From 0da70311b0535bbda18540d957570a46d19484f5 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 30 Jul 2020 17:06:47 +0200 Subject: Javadoc package-list --- .../org/jetbrains/dokka/javadoc/JavadocPlugin.kt | 41 +++++++++++++++++++--- .../dokka/javadoc/pages/JavadocPageNodes.kt | 33 ++++++++--------- .../dokka/javadoc/pages/htmlPreprocessors.kt | 2 -- .../renderer/JavadocContentToHtmlTranslator.kt | 4 +-- .../JavadocContentToTemplateMapTranslator.kt | 2 ++ .../dokka/javadoc/renderer/KorteJavadocRenderer.kt | 24 +++++++------ .../dokka/javadoc/renderer/SearchScriptsCreator.kt | 8 ++--- 7 files changed, 71 insertions(+), 43 deletions(-) (limited to 'plugins/javadoc/src/main/kotlin/org/jetbrains/dokka') diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt index 0c322a82..cf45ef75 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/JavadocPlugin.kt @@ -1,21 +1,27 @@ package org.jetbrains.dokka.javadoc -import org.jetbrains.dokka.javadoc.JavadocDocumentableToPageTranslator import org.jetbrains.dokka.javadoc.location.JavadocLocationProviderFactory import org.jetbrains.dokka.javadoc.renderer.KorteJavadocRenderer import org.jetbrains.dokka.javadoc.signatures.JavadocSignatureProvider import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.renderers.PackageListCreator +import org.jetbrains.dokka.base.renderers.RootCreator +import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat +import org.jetbrains.dokka.javadoc.pages.AllClassesPageInstaller +import org.jetbrains.dokka.javadoc.pages.ResourcesInstaller +import org.jetbrains.dokka.javadoc.pages.TreeViewInstaller import org.jetbrains.dokka.kotlinAsJava.KotlinAsJavaPlugin import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.transformers.pages.PageTransformer class JavadocPlugin : DokkaPlugin() { val dokkaBasePlugin by lazy { plugin() } val kotinAsJavaPlugin by lazy { plugin() } - - val locationProviderFactory by extensionPoint() + val locationProviderFactory by lazy { dokkaBasePlugin.locationProviderFactory } + val javadocPreprocessors by extensionPoint() val dokkaJavadocPlugin by extending { (CoreExtensions.renderer @@ -34,9 +40,9 @@ class JavadocPlugin : DokkaPlugin() { } val javadocLocationProviderFactory by extending { - locationProviderFactory providing { context -> + dokkaBasePlugin.locationProviderFactory providing { context -> JavadocLocationProviderFactory(context) - } + } override dokkaBasePlugin.locationProvider } val javadocSignatureProvider by extending { @@ -49,5 +55,30 @@ class JavadocPlugin : DokkaPlugin() { ) } override kotinAsJavaPlugin.javaSignatureProvider } + + val rootCreator by extending { + javadocPreprocessors with RootCreator + } + + val packageListCreator by extending { + javadocPreprocessors providing { + PackageListCreator( + it, + RecognizedLinkFormat.DokkaJavadoc + ) + } order { after(rootCreator) } + } + + val resourcesInstaller by extending { + javadocPreprocessors with ResourcesInstaller order { after(rootCreator) } + } + + val treeViewInstaller by extending { + javadocPreprocessors with TreeViewInstaller order { after(rootCreator) } + } + + val allClassessPageInstaller by extending { + javadocPreprocessors with AllClassesPageInstaller order { before(rootCreator) } + } } diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt index 7bc6d6d8..24719ebf 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt @@ -32,37 +32,32 @@ interface WithBrief { } class JavadocModulePageNode( - override val name: String, - override val content: JavadocContentNode, - override val children: List, + name: String, + content: JavadocContentNode, + children: List, override val dri: Set ) : - RootPageNode(), + ModulePageNode(name, content, null, children, emptyList()), JavadocPageNode { - override val documentable: Documentable? = null - override val embeddedResources: List = emptyList() - override fun modified(name: String, children: List): RootPageNode = - JavadocModulePageNode(name, content, children, dri) - override fun modified( name: String, content: ContentNode, dri: Set, embeddedResources: List, children: List - ): ContentPage = JavadocModulePageNode(name, content as JavadocContentNode, children, dri) + ): ModulePageNode = JavadocModulePageNode(name, content as JavadocContentNode, children, dri) } class JavadocPackagePageNode( - override val name: String, - override val content: JavadocContentNode, - override val dri: Set, + name: String, + content: JavadocContentNode, + dri: Set, - override val documentable: Documentable? = null, - override val children: List = emptyList(), - override val embeddedResources: List = listOf() -) : JavadocPageNode, WithIndexables, IndexableJavadocNode { + documentable: Documentable? = null, + children: List = emptyList(), + embeddedResources: List = listOf() +) : JavadocPageNode, WithIndexables, IndexableJavadocNode, PackagePageNode(name, content, dri, documentable, children, embeddedResources) { override fun getAllIndexables(): List = children.filterIsInstance().flatMap { @@ -73,7 +68,7 @@ class JavadocPackagePageNode( override fun modified( name: String, children: List - ): PageNode = JavadocPackagePageNode( + ): PackagePageNode = JavadocPackagePageNode( name, content, dri, @@ -88,7 +83,7 @@ class JavadocPackagePageNode( dri: Set, embeddedResources: List, children: List - ): ContentPage = + ): PackagePageNode = JavadocPackagePageNode( name, content as JavadocContentNode, diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt index a2c3cf22..c54d484a 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/htmlPreprocessors.kt @@ -5,8 +5,6 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.transformers.pages.PageTransformer import kotlin.collections.HashMap -val preprocessors = listOf(ResourcesInstaller, TreeViewInstaller, AllClassesPageInstaller, IndexGenerator) - object ResourcesInstaller : PageTransformer { override fun invoke(input: RootPageNode): RootPageNode = input.modified( children = input.children + diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt index b5fdde33..413b6387 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka.javadoc.renderer -import org.jetbrains.dokka.javadoc.location.JavadocLocationProvider +import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.javadoc.pages.JavadocSignatureContentNode import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -8,7 +8,7 @@ import org.jetbrains.dokka.utilities.formatToEndWithHtml import org.jetbrains.dokka.utilities.htmlEscape internal class JavadocContentToHtmlTranslator( - private val locationProvider: JavadocLocationProvider, + private val locationProvider: LocationProvider, private val context: DokkaContext ) { diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index ab12f50c..554bdb8a 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -167,6 +167,8 @@ internal class JavadocContentToTemplateMapTranslator( else -> emptyMap() } + fun templateMapForJavadocContentNode(node: ContentNode): TemplateMap = (node as? JavadocContentNode)?.let { templateMapForJavadocContentNode(it) } ?: emptyMap() + private fun templateMapForParameterNode(node: JavadocParameterNode): TemplateMap = mapOf( "description" to htmlForContentNodes(node.description, contextNode), diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt index 20115ac8..cdd045a4 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/KorteJavadocRenderer.kt @@ -10,11 +10,13 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.base.renderers.OutputWriter +import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.javadoc.JavadocPlugin import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -25,6 +27,7 @@ typealias TemplateMap = Map class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: DokkaContext, resourceDir: String) : Renderer { private lateinit var locationProvider: JavadocLocationProvider + private val registeredPreprocessors = context.plugin().query { javadocPreprocessors } private val contentToHtmlTranslator by lazy { JavadocContentToHtmlTranslator(locationProvider, context) @@ -34,10 +37,10 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: JavadocContentToTemplateMapTranslator(locationProvider, context) } - override fun render(root: RootPageNode) = root.let { preprocessors.fold(root) { r, t -> t.invoke(r) } }.let { newRoot -> - locationProvider = context.plugin().querySingle { locationProviderFactory }.getLocationProvider(newRoot) + override fun render(root: RootPageNode) = root.let { registeredPreprocessors.fold(root) { r, t -> t.invoke(r) } }.let { newRoot -> + locationProvider = context.plugin().querySingle { locationProviderFactory }.getLocationProvider(newRoot) as JavadocLocationProvider runBlocking(Dispatchers.IO) { - renderModulePageNode(newRoot as JavadocModulePageNode) + renderPage(newRoot) SearchScriptsCreator(locationProvider).invoke(newRoot).forEach { renderSpecificPage(it, "") } } } @@ -52,11 +55,11 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: else -> "" } - private fun CoroutineScope.renderNode(node: PageNode, path: String = "") { - if (node is JavadocPageNode) { - renderJavadocPageNode(node) - } else if (node is RendererSpecificPage) { - renderSpecificPage(node, path) + private fun CoroutineScope.renderPage(node: PageNode, path: String = "") { + when(node){ + is JavadocModulePageNode -> renderModulePageNode(node) + is JavadocPageNode -> renderJavadocPageNode(node) + is RendererSpecificPage -> renderSpecificPage(node, path) } } @@ -67,14 +70,14 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) - node.children.forEach { renderNode(it, link) } + node.children.forEach { renderPage(it, link) } } private fun CoroutineScope.renderJavadocPageNode(node: JavadocPageNode) { val link = locationProvider.resolve(node, skipExtension = true) val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) - node.children.forEach { renderNode(it, link.toNormalized()) } + node.children.forEach { renderPage(it, link.toNormalized()) } } private fun CoroutineScope.renderSpecificPage(node: RendererSpecificPage, path: String) = launch { @@ -87,6 +90,7 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: ) RenderingStrategy.DoNothing -> Unit } + node.children.forEach { renderPage(it, locationProvider.resolve(node, skipExtension = true).toNormalized()) } } private fun Pair.pairToTag() = diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt index 589aeb51..0c2d8e07 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/SearchScriptsCreator.kt @@ -1,12 +1,10 @@ package org.jetbrains.dokka.javadoc.renderer -import org.jetbrains.dokka.javadoc.location.JavadocLocationProvider import org.jetbrains.dokka.javadoc.pages.* import org.jetbrains.dokka.javadoc.renderer.SearchRecord.Companion.allTypes -import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.DokkaException import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.base.resolvers.local.resolveOrThrow +import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.Documentable @@ -14,12 +12,12 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.utilities.formatToEndWithHtml import java.lang.StringBuilder -class SearchScriptsCreator(private val locationProvider: JavadocLocationProvider) { +class SearchScriptsCreator(private val locationProvider: LocationProvider) { fun invoke(input: RootPageNode): List { val data = when (input) { is JavadocModulePageNode -> processModules(listOf(input)) - else -> SearchData() + else -> processModules(input.children.filterIsInstance()) } val serializer = SearchRecordJsonSerializer() -- cgit