diff options
12 files changed, 91 insertions, 36 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt index 0f88b492..859e850e 100644 --- a/core/src/main/kotlin/CoreExtensions.kt +++ b/core/src/main/kotlin/CoreExtensions.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.pages.CommentsToContentConverter import org.jetbrains.dokka.plugability.ExtensionPoint import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.renderers.OutputWriter @@ -27,7 +26,6 @@ object CoreExtensions { val pageTransformer by coreExtension<PageNodeTransformer>() val renderer by coreExtension<Renderer>() - val commentsToContentConverter by coreExtension<CommentsToContentConverter>() val locationProviderFactory by coreExtension<LocationProviderFactory>() val outputWriter by coreExtension<OutputWriter>() diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 1ad93f4f..8897e68d 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -88,7 +88,7 @@ class DokkaGenerator( fun createPages( transformedDocumentation: Module, context: DokkaContext - ) = context.single(CoreExtensions.documentablesToPageTranslator).invoke(transformedDocumentation, context) + ) = context.single(CoreExtensions.documentablesToPageTranslator).invoke(transformedDocumentation) fun transformPages( pages: RootPageNode, diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt index 1a367d30..242eb6b8 100644 --- a/core/src/main/kotlin/plugability/DefaultExtensions.kt +++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt @@ -1,23 +1,20 @@ 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.OutputWriter import org.jetbrains.dokka.resolvers.DefaultLocationProviderFactory internal object DefaultExtensions { - private val converter: LazyEvaluated<DocTagToContentConverter> = LazyEvaluated.fromRecipe { DocTagToContentConverter(it) } private val providerFactory: LazyEvaluated<DefaultLocationProviderFactory> = LazyEvaluated.fromRecipe { DefaultLocationProviderFactory(it) } private val outputWriter: LazyEvaluated<OutputWriter> = LazyEvaluated.fromRecipe { FileWriter(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.commentsToContentConverter -> converter.get(fullContext) CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext) - CoreExtensions.outputWriter -> outputWriter.get(fullContext) + CoreExtensions.outputWriter -> outputWriter.get(fullContext) else -> null }.let { listOfNotNull( it ) as List<T> } }
\ No newline at end of file diff --git a/core/src/main/kotlin/plugability/DokkaPlugin.kt b/core/src/main/kotlin/plugability/DokkaPlugin.kt index c00b0af3..d8fb7892 100644 --- a/core/src/main/kotlin/plugability/DokkaPlugin.kt +++ b/core/src/main/kotlin/plugability/DokkaPlugin.kt @@ -13,8 +13,7 @@ abstract class DokkaPlugin { @PublishedApi internal var context: DokkaContext? = null - protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class) - ?: throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") + protected inline fun <reified T : DokkaPlugin> plugin(): T = context?.plugin(T::class) ?: throwIllegalQuery() protected fun <T : Any> extensionPoint() = object : ReadOnlyProperty<DokkaPlugin, ExtensionPoint<T>> { @@ -51,5 +50,10 @@ abstract class DokkaPlugin { } inline fun <reified P : DokkaPlugin, reified E : Any> P.query(extension: P.() -> ExtensionPoint<E>): List<E> = - context?.let { it[extension()] } - ?: throw IllegalStateException("Querying about plugins is only possible with dokka context initialised")
\ No newline at end of file + context?.let { it[extension()] } ?: throwIllegalQuery() + +inline fun <reified P : DokkaPlugin, reified E : Any> P.querySingle(extension: P.() -> ExtensionPoint<E>): E = + context?.single(extension()) ?: throwIllegalQuery() + +fun throwIllegalQuery(): Nothing = + throw IllegalStateException("Querying about plugins is only possible with dokka context initialised") diff --git a/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt b/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt index fa74d216..19698fa0 100644 --- a/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt +++ b/core/src/main/kotlin/transformers/documentation/DocumentablesToPageTranslator.kt @@ -5,5 +5,5 @@ import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.plugability.DokkaContext interface DocumentablesToPageTranslator { - operator fun invoke(module: Module, context: DokkaContext): ModulePageNode + operator fun invoke(module: Module): ModulePageNode }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index ed23d77e..9b6e9b1a 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -4,6 +4,8 @@ import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.transformers.descriptors.DefaultDescriptorToDocumentationTranslator import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentableMerger import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentablesToPageTranslator +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter +import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.base.transformers.pages.merger.FallbackPageMergerStrategy import org.jetbrains.dokka.base.transformers.pages.merger.PageMergerStrategy import org.jetbrains.dokka.base.transformers.pages.merger.PageNodeMerger @@ -12,8 +14,9 @@ import org.jetbrains.dokka.base.transformers.psi.DefaultPsiToDocumentationTransl import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.renderers.html.HtmlRenderer -class DokkaBase: DokkaPlugin() { +class DokkaBase : DokkaPlugin() { val pageMergerStrategy by extensionPoint<PageMergerStrategy>() + val commentsToContentConverter by extensionPoint<CommentsToContentConverter>() val descriptorToDocumentationTranslator by extending(isFallback = true) { CoreExtensions.descriptorToDocumentationTranslator providing ::DefaultDescriptorToDocumentationTranslator @@ -28,7 +31,13 @@ class DokkaBase: DokkaPlugin() { } val documentablesToPageTranslator by extending(isFallback = true) { - CoreExtensions.documentablesToPageTranslator with DefaultDocumentablesToPageTranslator + CoreExtensions.documentablesToPageTranslator providing { ctx -> + DefaultDocumentablesToPageTranslator(ctx.single(commentsToContentConverter), ctx.logger) + } + } + + val docTagToContentConverter by extending(isFallback = true) { + commentsToContentConverter with DocTagToContentConverter } val pageMerger by extending { diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt index 90f8e2d7..d28791ab 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt @@ -1,21 +1,26 @@ package org.jetbrains.dokka.base.transformers.documentables import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.model.Module import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.documentation.DocumentablesToPageTranslator +import org.jetbrains.dokka.utilities.DokkaLogger -object DefaultDocumentablesToPageTranslator : DocumentablesToPageTranslator { - override fun invoke(module: Module, context: DokkaContext): ModulePageNode = +class DefaultDocumentablesToPageTranslator( + private val commentsToContentConverter: CommentsToContentConverter, + private val logger: DokkaLogger +) : DocumentablesToPageTranslator { + override fun invoke(module: Module): ModulePageNode = DefaultPageBuilder { node, kind, operation -> DefaultPageContentBuilder.group( setOf(node.dri), node.platformData, kind, - context.single(CoreExtensions.commentsToContentConverter), - context.logger, + commentsToContentConverter, + logger, operation ) }.pageForModule(module) diff --git a/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt index 809b97a0..6ce883b1 100644 --- a/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.transformers.documentables +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.Function diff --git a/core/src/main/kotlin/pages/CommentsToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt index 78c7ff4c..4d2f14a5 100644 --- a/core/src/main/kotlin/pages/CommentsToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt @@ -1,6 +1,7 @@ -package org.jetbrains.dokka.pages +package org.jetbrains.dokka.base.transformers.pages.comments import org.jetbrains.dokka.model.doc.DocTag +import org.jetbrains.dokka.pages.* interface CommentsToContentConverter { fun buildContent( diff --git a/core/src/main/kotlin/pages/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt index 08a579a8..70792534 100644 --- a/core/src/main/kotlin/pages/DocTagToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt @@ -1,11 +1,10 @@ -package org.jetbrains.dokka.pages +package org.jetbrains.dokka.base.transformers.pages.comments import org.jetbrains.dokka.model.doc.* +import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext -class DocTagToContentConverter( - private val context: DokkaContext -) : CommentsToContentConverter { +object DocTagToContentConverter : CommentsToContentConverter { override fun buildContent( docTag: DocTag, dci: DCI, @@ -21,10 +20,28 @@ class DocTagToContentConverter( } fun buildHeader(level: Int) = - listOf(ContentHeader(buildChildren(docTag), level, dci, platforms, styles, extras)) + listOf( + ContentHeader( + buildChildren(docTag), + level, + dci, + platforms, + styles, + extras + ) + ) fun buildList(ordered: Boolean) = - listOf(ContentList(buildChildren(docTag), ordered, dci, platforms, styles, extras)) + listOf( + ContentList( + buildChildren(docTag), + ordered, + dci, + platforms, + styles, + extras + ) + ) return when (docTag) { is H1 -> buildHeader(1) @@ -53,7 +70,10 @@ class DocTagToContentConverter( ContentDRILink( buildChildren(docTag), docTag.dri, - DCI(setOf(docTag.dri), ContentKind.Symbol), + DCI( + setOf(docTag.dri), + ContentKind.Symbol + ), platforms, styles, extras @@ -81,16 +101,31 @@ class DocTagToContentConverter( ) is Img -> listOf( ContentEmbeddedResource( - address = docTag.params.get("href")!!, - altText = docTag.params.get("alt"), + address = docTag.params["href"]!!, + altText = docTag.params["alt"], dci = dci, platforms = platforms, style = styles, extras = extras ) ) - is HorizontalRule -> listOf(ContentText("", dci, platforms, setOf())) - is Text -> listOf(ContentText(docTag.body, dci, platforms, styles, extras)) + is HorizontalRule -> listOf( + ContentText( + "", + dci, + platforms, + setOf() + ) + ) + is Text -> listOf( + ContentText( + docTag.body, + dci, + platforms, + styles, + extras + ) + ) else -> buildChildren(docTag) } } diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt index 02e6ff82..87649a83 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPageContentBuilder.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.base.transformers.documentables.DefaultPageContentBuilder import org.jetbrains.dokka.base.transformers.documentables.PageContentBuilderFunction import org.jetbrains.dokka.base.transformers.documentables.type +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Function import org.jetbrains.dokka.model.JavaTypeWrapper diff --git a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt index f8a25aca..f9389ebd 100644 --- a/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt +++ b/plugins/kotlin-as-java/src/main/kotlin/KotlinAsJavaPlugin.kt @@ -2,12 +2,14 @@ package org.jetbrains.dokka.kotlinAsJava import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Module import org.jetbrains.dokka.pages.ModulePageNode -import org.jetbrains.dokka.plugability.DokkaContext -import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.plugability.* import org.jetbrains.dokka.transformers.documentation.DocumentablesToPageTranslator +import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.descriptors.DeclarationDescriptor class KotlinAsJavaPlugin : DokkaPlugin() { @@ -15,7 +17,7 @@ class KotlinAsJavaPlugin : DokkaPlugin() { CoreExtensions.descriptorToDocumentationTranslator providing ::KotlinAsJavaDescriptorToDocumentationTranslator } val kotlinAsJavaDocumentableToPageTranslator by extending { - CoreExtensions.documentablesToPageTranslator with KotlinAsJavaDocumentationToPageTranslator + CoreExtensions.documentablesToPageTranslator providing ::KotlinAsJavaDocumentationToPageTranslator } } @@ -26,14 +28,16 @@ object DescriptorCache { operator fun get(dri: DRI): DeclarationDescriptor? = cache[dri] } -object KotlinAsJavaDocumentationToPageTranslator : DocumentablesToPageTranslator { - override fun invoke(module: Module, context: DokkaContext): ModulePageNode = +class KotlinAsJavaDocumentationToPageTranslator( + private val context: DokkaContext +) : DocumentablesToPageTranslator { + override fun invoke(module: Module): ModulePageNode = KotlinAsJavaPageBuilder { node, kind, operation -> KotlinAsJavaPageContentBuilder.group( setOf(node.dri), node.platformData, kind, - context.single(CoreExtensions.commentsToContentConverter), + context.plugin<DokkaBase>().querySingle { commentsToContentConverter }, context.logger, operation ) |