aboutsummaryrefslogtreecommitdiff
path: root/src/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utilities')
-rw-r--r--src/Utilities/GuiceModule.kt6
-rw-r--r--src/Utilities/Path.kt11
-rw-r--r--src/Utilities/ServiceLocator.kt14
3 files changed, 19 insertions, 12 deletions
diff --git a/src/Utilities/GuiceModule.kt b/src/Utilities/GuiceModule.kt
index 4ce4863d..57bad468 100644
--- a/src/Utilities/GuiceModule.kt
+++ b/src/Utilities/GuiceModule.kt
@@ -45,14 +45,14 @@ class GuiceModule(val config: DokkaGenerator) : Module {
}
-private inline fun <reified T> Binder.registerCategory(category: String) {
+private inline fun <reified T: Any> Binder.registerCategory(category: String) {
ServiceLocator.allServices(category).forEach {
- @suppress("UNCHECKED_CAST")
+ @Suppress("UNCHECKED_CAST")
bind(javaClass<T>()).annotatedWith(Names.named(it.name)).to(javaClass<T>().classLoader.loadClass(it.className) as Class<T>)
}
}
-private inline fun <reified Base, reified T : Base> Binder.bindNameAnnotated(name: String) {
+private inline fun <reified Base : Any, reified T : Base> Binder.bindNameAnnotated(name: String) {
bind(javaClass<Base>()).annotatedWith(Names.named(name)).to(javaClass<T>())
}
diff --git a/src/Utilities/Path.kt b/src/Utilities/Path.kt
index fea22250..36277d9f 100644
--- a/src/Utilities/Path.kt
+++ b/src/Utilities/Path.kt
@@ -1,18 +1,19 @@
package org.jetbrains.dokka
-import java.io.*
+import java.io.File
+import java.io.IOException
fun File.getRelativePath(name: File): File {
val parent = parentFile ?: throw IOException("No common directory")
- val basePath = getCanonicalPath() + File.separator;
- val targetPath = name.getCanonicalPath();
+ val basePath = canonicalPath + File.separator;
+ val targetPath = name.canonicalPath;
if (targetPath.startsWith(basePath)) {
- return File(targetPath.substring(basePath.length()))
+ return File(targetPath.substring(basePath.length))
} else {
return File(".." + File.separator + parent.getRelativePath(name))
}
}
-fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(getPath() + "." + extension)
+fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(path + "." + extension)
diff --git a/src/Utilities/ServiceLocator.kt b/src/Utilities/ServiceLocator.kt
index b3610a53..bc04238f 100644
--- a/src/Utilities/ServiceLocator.kt
+++ b/src/Utilities/ServiceLocator.kt
@@ -2,7 +2,7 @@ package org.jetbrains.dokka.Utilities
import org.jetbrains.dokka.DokkaGenerator
import java.io.File
-import java.util.Properties
+import java.util.*
import java.util.jar.JarFile
import java.util.zip.ZipEntry
@@ -16,7 +16,7 @@ public object ServiceLocator {
val loadedClass = javaClass.classLoader.loadClass(descriptor.className)
val constructor = loadedClass.constructors
.filter { it.parameterTypes.isEmpty() || (it.parameterTypes.size() == 1 && conf.javaClass.isInstance(it.parameterTypes[0])) }
- .sortDescendingBy { it.parameterTypes.size() }
+ .sortedByDescending { it.parameterTypes.size() }
.firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor")
val implementationRawType: Any = if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor)
@@ -25,7 +25,7 @@ public object ServiceLocator {
throw ServiceLookupException("Class ${descriptor.className} is not a subtype of ${clazz.name}")
}
- @suppress("UNCHECKED_CAST")
+ @Suppress("UNCHECKED_CAST")
return implementationRawType as T
}
@@ -35,7 +35,7 @@ public object ServiceLocator {
throw ServiceLookupException("Class $className is not a subtype of ${clazz.name}")
}
- @suppress("UNCHECKED_CAST")
+ @Suppress("UNCHECKED_CAST")
val casted = loaded as Class<T>
casted
@@ -89,6 +89,12 @@ public inline fun <reified T : Any> ServiceLocator.lookupOrNull(category: String
null
}
+fun main(args: Array<String>) {
+ ServiceLocator.allServices("format").forEach {
+ println(it)
+ }
+}
+
private val ZipEntry.fileName: String
get() = name.substringAfterLast("/", name)