diff options
Diffstat (limited to 'core/src/main/kotlin/plugability')
-rw-r--r-- | core/src/main/kotlin/plugability/DefaultExtensions.kt | 18 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/DokkaContext.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/LazyEvaluated.kt | 16 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/extensions.kt | 18 |
4 files changed, 46 insertions, 23 deletions
diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt index 86ca5ca8..58b686f3 100644 --- a/core/src/main/kotlin/plugability/DefaultExtensions.kt +++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt @@ -2,23 +2,25 @@ package org.jetbrains.dokka.plugability import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.pages.DocTagToContentConverter +import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.HtmlRenderer -import org.jetbrains.dokka.resolvers.DefaultLocationProvider +import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory import org.jetbrains.dokka.transformers.descriptors.DefaultDescriptorToDocumentationTranslator import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationNodeMerger import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator -object DefaultExtensions : DokkaExtensionHandler { +internal object DefaultExtensions { @Suppress("IMPLICIT_CAST_TO_ANY", "UNCHECKED_CAST") - override fun <T : Any, E : ExtensionPoint<T>> get(point: E, askDefault: AskDefault): List<T> = + internal fun <T : Any, E : ExtensionPoint<T>> get(point: E, fullContext: DokkaContext): List<T> = when (point) { - CoreExtensions.descriptorToDocumentationTranslator -> DefaultDescriptorToDocumentationTranslator + CoreExtensions.descriptorToDocumentationTranslator -> DefaultDescriptorToDocumentationTranslator CoreExtensions.documentationMerger -> DefaultDocumentationNodeMerger - CoreExtensions.commentsToContentConverterFactory -> ::DocTagToContentConverter + CoreExtensions.commentsToContentConverter -> DocTagToContentConverter(fullContext) CoreExtensions.documentationToPageTranslator -> DefaultDocumentationToPageTranslator - CoreExtensions.rendererFactory -> ::HtmlRenderer - CoreExtensions.locationProviderFactory -> ::DefaultLocationProvider + CoreExtensions.renderer -> HtmlRenderer(fullContext.single(CoreExtensions.outputWriter), fullContext) + CoreExtensions.locationProviderFactory -> DefaultLocationProviderFactory + CoreExtensions.outputWriter -> FileWriter(fullContext.configuration.outputDir, "") CoreExtensions.fileExtension -> ".html" else -> null - }.let { listOfNotNull(it) as List<T> } + }.let { listOfNotNull( it ) as List<T> } }
\ No newline at end of file diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index 8709b74f..f2c99d95 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.plugability +import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.dokka.EnvironmentAndFacade import org.jetbrains.dokka.pages.PlatformData @@ -20,17 +21,17 @@ interface DokkaContext : DokkaExtensionHandler { fun <T : DokkaPlugin> plugin(kclass: KClass<T>): T? val logger: DokkaLogger - + val configuration: DokkaConfiguration val platforms: Map<PlatformData, EnvironmentAndFacade> companion object { fun create( - pluginsClasspath: Iterable<File>, + configuration: DokkaConfiguration, logger: DokkaLogger, platforms: Map<PlatformData, EnvironmentAndFacade> ): DokkaContext = - DokkaContextConfigurationImpl(logger, DefaultExtensions, platforms).apply { - pluginsClasspath.map { it.relativeTo(File(".").absoluteFile).toURI().toURL() } + DokkaContextConfigurationImpl(logger, configuration, platforms).apply { + configuration.pluginsClasspath.map { it.relativeTo(File(".").absoluteFile).toURI().toURL() } .toTypedArray() .let { URLClassLoader(it, this.javaClass.classLoader) } .also { checkClasspath(it) } @@ -60,7 +61,7 @@ interface DokkaContextConfiguration { private class DokkaContextConfigurationImpl( override val logger: DokkaLogger, - private val defaultHandler: DokkaExtensionHandler?, + override val configuration: DokkaConfiguration, override val platforms: Map<PlatformData, EnvironmentAndFacade> ) : DokkaContext, DokkaContextConfiguration { private val plugins = mutableMapOf<KClass<*>, DokkaPlugin>() @@ -105,12 +106,12 @@ private class DokkaContextConfigurationImpl( override operator fun <T, E> get(point: E, askDefault: AskDefault) where T : Any, E : ExtensionPoint<T> = when (askDefault) { AskDefault.Never -> actions(point).orEmpty() - AskDefault.Always -> actions(point).orEmpty() + defaultHandler?.get(point, askDefault).orEmpty() + AskDefault.Always -> actions(point).orEmpty() + DefaultExtensions.get(point, this) AskDefault.WhenEmpty -> - actions(point)?.takeIf { it.isNotEmpty() } ?: defaultHandler?.get(point, askDefault).orEmpty() + actions(point)?.takeIf { it.isNotEmpty() } ?: DefaultExtensions?.get(point, this) } as List<T> - private fun <E : ExtensionPoint<*>> actions(point: E) = extensions[point]?.map { it.action } + private fun <E : ExtensionPoint<*>> actions(point: E) = extensions[point]?.map { it.action.get(this) } @Suppress("UNCHECKED_CAST") override fun <T : DokkaPlugin> plugin(kclass: KClass<T>) = (plugins[kclass] ?: pluginStubFor(kclass)) as T diff --git a/core/src/main/kotlin/plugability/LazyEvaluated.kt b/core/src/main/kotlin/plugability/LazyEvaluated.kt new file mode 100644 index 00000000..79ac0968 --- /dev/null +++ b/core/src/main/kotlin/plugability/LazyEvaluated.kt @@ -0,0 +1,16 @@ +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) { + value = recipe?.invoke(context) + } + return value ?: throw AssertionError("Incorrect initialized LazyEvaluated instance") + } + + companion object { + fun <T : Any> fromInstance(value: T) = LazyEvaluated(value = value) + fun <T : Any> fromRecipe(recipe: (DokkaContext) -> T) = LazyEvaluated(recipe = recipe) + } +}
\ No newline at end of file diff --git a/core/src/main/kotlin/plugability/extensions.kt b/core/src/main/kotlin/plugability/extensions.kt index 8d1a7ba0..42bf3900 100644 --- a/core/src/main/kotlin/plugability/extensions.kt +++ b/core/src/main/kotlin/plugability/extensions.kt @@ -11,7 +11,7 @@ abstract class Extension<T : Any> internal constructor( internal val extensionPoint: ExtensionPoint<T>, internal val pluginClass: String, internal val extensionName: String, - val action: T, + internal val action: LazyEvaluated<T>, internal val ordering: (OrderDsl.() -> Unit)? = null ) { override fun toString() = "Extension: $pluginClass/$extensionName" @@ -23,11 +23,11 @@ abstract class Extension<T : Any> internal constructor( override fun hashCode() = listOf(pluginClass, extensionName).hashCode() } -class ExtensionOrdered<T : Any>( +class ExtensionOrdered<T : Any> internal constructor( extensionPoint: ExtensionPoint<T>, pluginClass: String, extensionName: String, - action: T, + action: LazyEvaluated<T>, ordering: (OrderDsl.() -> Unit) ) : Extension<T>( extensionPoint, @@ -37,11 +37,11 @@ class ExtensionOrdered<T : Any>( ordering ) -class ExtensionUnordered<T : Any>( +class ExtensionUnordered<T : Any> internal constructor( extensionPoint: ExtensionPoint<T>, pluginClass: String, extensionName: String, - action: T + action: LazyEvaluated<T> ) : Extension<T>( extensionPoint, pluginClass, @@ -57,8 +57,12 @@ annotation class ExtensionsDsl @ExtensionsDsl class ExtendingDSL(private val pluginClass: String, private val extensionName: String) { - infix fun <T: Any> ExtensionPoint<T>.with(action: T) = - ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, action) + + infix fun <T : Any> ExtensionPoint<T>.with(action: T) = + ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromInstance(action)) + + infix fun <T : Any> ExtensionPoint<T>.providing(action: (DokkaContext) -> T) = + ExtensionUnordered(this, this@ExtendingDSL.pluginClass, extensionName, LazyEvaluated.fromRecipe(action)) infix fun <T: Any> ExtensionUnordered<T>.order(block: OrderDsl.() -> Unit) = ExtensionOrdered(extensionPoint, pluginClass, extensionName, action, block) |