diff options
6 files changed, 21 insertions, 18 deletions
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt index 58b686f3..b3ff4248 100644 --- a/core/src/main/kotlin/plugability/DefaultExtensions.kt +++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt @@ -10,15 +10,21 @@ import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationNodeMe import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator internal object DefaultExtensions { + + private val renderer: LazyEvaluated<HtmlRenderer> = LazyEvaluated.fromRecipe { HtmlRenderer(it.single(CoreExtensions.outputWriter), it) } + private val converter: LazyEvaluated<DocTagToContentConverter> = LazyEvaluated.fromRecipe {DocTagToContentConverter(it) } + private val providerFactory: LazyEvaluated<DefaultLocationProviderFactory> = LazyEvaluated.fromRecipe { DefaultLocationProviderFactory(it) } + + @Suppress("IMPLICIT_CAST_TO_ANY", "UNCHECKED_CAST") internal fun <T : Any, E : ExtensionPoint<T>> get(point: E, fullContext: DokkaContext): List<T> = when (point) { CoreExtensions.descriptorToDocumentationTranslator -> DefaultDescriptorToDocumentationTranslator CoreExtensions.documentationMerger -> DefaultDocumentationNodeMerger - CoreExtensions.commentsToContentConverter -> DocTagToContentConverter(fullContext) + CoreExtensions.commentsToContentConverter -> converter.get(fullContext) CoreExtensions.documentationToPageTranslator -> DefaultDocumentationToPageTranslator - CoreExtensions.renderer -> HtmlRenderer(fullContext.single(CoreExtensions.outputWriter), fullContext) - CoreExtensions.locationProviderFactory -> DefaultLocationProviderFactory + CoreExtensions.renderer -> renderer.get(fullContext) + CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext) CoreExtensions.outputWriter -> FileWriter(fullContext.configuration.outputDir, "") CoreExtensions.fileExtension -> ".html" else -> null diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index f2c99d95..0d110f85 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -11,15 +11,12 @@ import kotlin.reflect.KClass import kotlin.reflect.full.createInstance -interface DokkaExtensionHandler { +interface DokkaContext { + fun <T : DokkaPlugin> plugin(kclass: KClass<T>): T? + operator fun <T, E> get(point: E, askDefault: AskDefault = AskDefault.WhenEmpty): List<T> where T : Any, E : ExtensionPoint<T> -} - -interface DokkaContext : DokkaExtensionHandler { - fun <T : DokkaPlugin> plugin(kclass: KClass<T>): T? - val logger: DokkaLogger val configuration: DokkaConfiguration val platforms: Map<PlatformData, EnvironmentAndFacade> diff --git a/core/src/main/kotlin/plugability/LazyEvaluated.kt b/core/src/main/kotlin/plugability/LazyEvaluated.kt index 79ac0968..c0c271f4 100644 --- a/core/src/main/kotlin/plugability/LazyEvaluated.kt +++ b/core/src/main/kotlin/plugability/LazyEvaluated.kt @@ -3,7 +3,7 @@ package org.jetbrains.dokka.plugability internal class LazyEvaluated<T : Any> private constructor(private val recipe: ((DokkaContext) -> T)? = null, private var value: T? = null) { internal fun get(context: DokkaContext): T { - if(value != null) { + if(value == null) { value = recipe?.invoke(context) } return value ?: throw AssertionError("Incorrect initialized LazyEvaluated instance") diff --git a/core/src/main/kotlin/renderers/DefaultRenderer.kt b/core/src/main/kotlin/renderers/DefaultRenderer.kt index 5f982251..1152bcc5 100644 --- a/core/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/core/src/main/kotlin/renderers/DefaultRenderer.kt @@ -95,7 +95,7 @@ abstract class DefaultRenderer<T>( } override fun render(root: PageNode) { - locationProvider = context.single(CoreExtensions.locationProviderFactory).getLocationProvider(root, context) + locationProvider = context.single(CoreExtensions.locationProviderFactory).getLocationProvider(root as ModulePageNode) renderPackageList(root) buildSupportFiles() renderPages(root) diff --git a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt index 7eae26ca..d7089f96 100644 --- a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt +++ b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt @@ -10,9 +10,9 @@ import org.jetbrains.dokka.plugability.single open class DefaultLocationProvider( private val pageGraphRoot: ModulePageNode, - private val context: DokkaContext + private val dokkaContext: DokkaContext ) : LocationProvider { // TODO: cache - private val extension = context.single(CoreExtensions.fileExtension) + private val extension = dokkaContext.single(CoreExtensions.fileExtension) override fun resolve(node: PageNode, context: PageNode?): String = pathTo(node, context) + extension @@ -20,7 +20,7 @@ open class DefaultLocationProvider( findInPageGraph(dri, platforms)?.let { resolve(it, context) } ?: // Not found in PageGraph, that means it's an external link ExternalLocationProvider.getLocation(dri, - this@DefaultLocationProvider.context.configuration.passesConfigurations + this.dokkaContext.configuration.passesConfigurations .filter { passConfig -> platforms.toSet().contains(PlatformData(passConfig.moduleName, passConfig.analysisPlatform, passConfig.targets)) } // TODO: change targets to something better? diff --git a/core/src/main/kotlin/resolvers/LocationProviderFactory.kt b/core/src/main/kotlin/resolvers/LocationProviderFactory.kt index 1622045b..c657846a 100644 --- a/core/src/main/kotlin/resolvers/LocationProviderFactory.kt +++ b/core/src/main/kotlin/resolvers/LocationProviderFactory.kt @@ -1,13 +1,13 @@ package org.jetbrains.dokka.resolvers import org.jetbrains.dokka.pages.ModulePageNode -import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.plugability.DokkaContext interface LocationProviderFactory { - fun getLocationProvider(pageNode: PageNode, context: DokkaContext): LocationProvider + fun getLocationProvider(pageNode: ModulePageNode): LocationProvider } -object DefaultLocationProviderFactory : LocationProviderFactory { - override fun getLocationProvider(pageNode: PageNode, context: DokkaContext) = DefaultLocationProvider(pageNode as ModulePageNode, context) +class DefaultLocationProviderFactory(val context: DokkaContext) : LocationProviderFactory { + + override fun getLocationProvider(pageNode: ModulePageNode) = DefaultLocationProvider(pageNode, context) }
\ No newline at end of file |