aboutsummaryrefslogtreecommitdiff
path: root/src/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utilities')
-rw-r--r--src/Utilities/DokkaModule.kt (renamed from src/Utilities/GuiceModule.kt)36
-rw-r--r--src/Utilities/ServiceLocator.kt27
2 files changed, 25 insertions, 38 deletions
diff --git a/src/Utilities/GuiceModule.kt b/src/Utilities/DokkaModule.kt
index e852ae19..3b2d26f1 100644
--- a/src/Utilities/GuiceModule.kt
+++ b/src/Utilities/DokkaModule.kt
@@ -4,15 +4,16 @@ import com.google.inject.Binder
import com.google.inject.Module
import com.google.inject.Provider
import com.google.inject.name.Names
-import com.google.inject.util.Providers
import org.jetbrains.dokka.*
import org.jetbrains.dokka.Formats.FormatDescriptor
+import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import java.io.File
-class GuiceModule(val config: DokkaGenerator) : Module {
+class DokkaModule(val environment: AnalysisEnvironment,
+ val options: DocumentationOptions,
+ val logger: DokkaLogger) : Module {
override fun configure(binder: Binder) {
- binder.bind(DokkaGenerator::class.java).toInstance(config)
- binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(config.outputDir))
+ binder.bind(File::class.java).annotatedWith(Names.named("outputDir")).toInstance(File(options.outputDir))
binder.bindNameAnnotated<LocationService, SingleFolderLocationService>("singleFolder")
binder.bindNameAnnotated<FileLocationService, SingleFolderLocationService>("singleFolder")
@@ -33,23 +34,28 @@ class GuiceModule(val config: DokkaGenerator) : Module {
binder.registerCategory<FormatService>("format")
binder.registerCategory<Generator>("generator")
- val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", config.outputFormat, config)
+ val descriptor = ServiceLocator.lookup<FormatDescriptor>("format", options.outputFormat)
descriptor.outlineServiceClass?.let { clazz ->
- binder.bind(OutlineFormatService::class.java).to(clazz)
+ binder.bind(OutlineFormatService::class.java).to(clazz.java)
}
descriptor.formatServiceClass?.let { clazz ->
- binder.bind(FormatService::class.java).to(clazz)
- }
- if (descriptor.packageDocumentationBuilderServiceClass != null) {
- binder.bind(PackageDocumentationBuilder::class.java).to(descriptor.packageDocumentationBuilderServiceClass)
- } else {
- binder.bind(PackageDocumentationBuilder::class.java).toProvider(Providers.of(null))
+ binder.bind(FormatService::class.java).to(clazz.java)
}
+ binder.bind<PackageDocumentationBuilder>().to(descriptor.packageDocumentationBuilderClass.java)
+ binder.bind<JavaDocumentationBuilder>().to(descriptor.javaDocumentationBuilderClass.java)
- binder.bind(Generator::class.java).to(descriptor.generatorServiceClass)
- }
+ binder.bind<Generator>().to(descriptor.generatorServiceClass.java)
+
+ val coreEnvironment = environment.createCoreEnvironment()
+ binder.bind<KotlinCoreEnvironment>().toInstance(coreEnvironment)
+ val dokkaResolutionFacade = environment.createResolutionFacade(coreEnvironment)
+ binder.bind<DokkaResolutionFacade>().toInstance(dokkaResolutionFacade)
+
+ binder.bind<DocumentationOptions>().toInstance(options)
+ binder.bind<DokkaLogger>().toInstance(logger)
+ }
}
private inline fun <reified T: Any> Binder.registerCategory(category: String) {
@@ -63,3 +69,5 @@ private inline fun <reified Base : Any, reified T : Base> Binder.bindNameAnnotat
bind(Base::class.java).annotatedWith(Names.named(name)).to(T::class.java)
}
+
+inline fun <reified T: Any> Binder.bind() = bind(T::class.java)
diff --git a/src/Utilities/ServiceLocator.kt b/src/Utilities/ServiceLocator.kt
index 57d2f47b..92aa9ba4 100644
--- a/src/Utilities/ServiceLocator.kt
+++ b/src/Utilities/ServiceLocator.kt
@@ -1,6 +1,5 @@
package org.jetbrains.dokka.Utilities
-import org.jetbrains.dokka.DokkaGenerator
import java.io.File
import java.util.*
import java.util.jar.JarFile
@@ -11,12 +10,11 @@ data class ServiceDescriptor(val name: String, val category: String, val descrip
class ServiceLookupException(message: String) : Exception(message)
public object ServiceLocator {
- public fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String, conf: DokkaGenerator): T {
+ public fun <T : Any> lookup(clazz: Class<T>, category: String, implementationName: String): T {
val descriptor = lookupDescriptor(category, implementationName)
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])) }
- .sortedByDescending { it.parameterTypes.size }
+ .filter { it.parameterTypes.isEmpty() }
.firstOrNull() ?: throw ServiceLookupException("Class ${descriptor.className} has no corresponding constructor")
val implementationRawType: Any = if (constructor.parameterTypes.isEmpty()) constructor.newInstance() else constructor.newInstance(constructor)
@@ -29,19 +27,6 @@ public object ServiceLocator {
return implementationRawType as T
}
- public fun <T> lookupClass(clazz: Class<T>, category: String, implementationName: String): Class<T> = lookupDescriptor(category, implementationName).className.let { className ->
- javaClass.classLoader.loadClass(className).let { loaded ->
- if (!clazz.isAssignableFrom(loaded)) {
- throw ServiceLookupException("Class $className is not a subtype of ${clazz.name}")
- }
-
- @Suppress("UNCHECKED_CAST")
- val casted = loaded as Class<T>
-
- casted
- }
- }
-
private fun lookupDescriptor(category: String, implementationName: String): ServiceDescriptor {
val properties = javaClass.classLoader.getResourceAsStream("dokka/$category/$implementationName.properties")?.use { stream ->
Properties().let { properties ->
@@ -81,13 +66,7 @@ public object ServiceLocator {
} ?: emptyList()
}
-public inline fun <reified T : Any> ServiceLocator.lookup(category: String, implementationName: String, conf: DokkaGenerator): T = lookup(T::class.java, category, implementationName, conf)
-public inline fun <reified T : Any> ServiceLocator.lookupClass(category: String, implementationName: String): Class<T> = lookupClass(T::class.java, category, implementationName)
-public inline fun <reified T : Any> ServiceLocator.lookupOrNull(category: String, implementationName: String, conf: DokkaGenerator): T? = try {
- lookup(T::class.java, category, implementationName, conf)
-} catch (any: Throwable) {
- null
-}
+public inline fun <reified T : Any> ServiceLocator.lookup(category: String, implementationName: String): T = lookup(T::class.java, category, implementationName)
private val ZipEntry.fileName: String
get() = name.substringAfterLast("/", name)