From 8cb6efc97f8fa321381c95cc5f85a3ce7bc13c3f Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Fri, 19 Jun 2020 14:08:49 +0200 Subject: Remove SourceSetDataCache, rename PassConfiguration to DokkaSourceSet and use it instead of SourceSetData --- .../main/kotlin/javadoc/JavadocLocationProvider.kt | 35 +++++++++++----------- .../src/main/kotlin/javadoc/JavadocPageCreator.kt | 19 ++++++------ .../main/kotlin/javadoc/KorteJavadocRenderer.kt | 10 +++---- .../kotlin/javadoc/pages/JavadocContentNodes.kt | 22 +++++++------- .../main/kotlin/javadoc/pages/JavadocPageNodes.kt | 2 +- 5 files changed, 45 insertions(+), 43 deletions(-) (limited to 'plugins/javadoc/src/main/kotlin') diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt index a92320dd..f8ecf868 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocLocationProvider.kt @@ -1,11 +1,11 @@ package javadoc import javadoc.pages.* +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.pages.ContentPage import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.pages.RootPageNode @@ -22,8 +22,8 @@ class JavadocLocationProvider(pageRoot: RootPageNode, private val context: Dokka externalLocationProviderFactories.asSequence().map { it.getExternalLocationProvider("javadoc10") } .filterNotNull().take(1).firstOrNull() private val externalDocumentationLinks by lazy { - context.configuration.passesConfigurations - .filter { passConfig -> passConfig.analysisPlatform == Platform.jvm } + context.configuration.sourceSets + .filter { sourceSet -> sourceSet.analysisPlatform == Platform.jvm } .flatMap { it.externalDocumentationLinks } .distinct() } @@ -65,7 +65,7 @@ class JavadocLocationProvider(pageRoot: RootPageNode, private val context: Dokka private operator fun IdentityHashMap>.get(dri: DRI) = this[nodeIndex[dri]] - override fun resolve(dri: DRI, sourceSets: List, context: PageNode?): String = + override fun resolve(dri: DRI, sourceSets: List, context: PageNode?): String = context?.let { resolve(it, skipExtension = false) } ?: nodeIndex[dri]?.let { resolve(it, skipExtension = true) } ?: with(externalLocationProvider!!) { @@ -79,19 +79,20 @@ class JavadocLocationProvider(pageRoot: RootPageNode, private val context: Dokka throw IllegalStateException("Path for ${node::class.java.canonicalName}:${node.name} not found") } - fun resolve(link: LinkJavadocListEntry, dir: String = "", skipExtension: Boolean = true) = pathIndex[link.dri.first()]?.let { - when (link.kind) { - JavadocContentKind.Class -> it - JavadocContentKind.OverviewSummary -> it.dropLast(1) + "index" - JavadocContentKind.PackageSummary -> it.dropLast(1) + "package-summary" - JavadocContentKind.AllClasses -> it.dropLast(1) + "allclasses" - JavadocContentKind.OverviewTree -> it.dropLast(1) + "overview-tree" - JavadocContentKind.PackageTree -> it.dropLast(1) + "package-tree" - else -> it - } - }?.joinToString("/")?.let {if (skipExtension) "$it.html" else it}?.let { - Paths.get(dir).relativize(Paths.get(it)).toString() - } ?: run {""} //TODO just a glue to compile it on HMPP + fun resolve(link: LinkJavadocListEntry, dir: String = "", skipExtension: Boolean = true) = + pathIndex[link.dri.first()]?.let { + when (link.kind) { + JavadocContentKind.Class -> it + JavadocContentKind.OverviewSummary -> it.dropLast(1) + "index" + JavadocContentKind.PackageSummary -> it.dropLast(1) + "package-summary" + JavadocContentKind.AllClasses -> it.dropLast(1) + "allclasses" + JavadocContentKind.OverviewTree -> it.dropLast(1) + "overview-tree" + JavadocContentKind.PackageTree -> it.dropLast(1) + "package-tree" + else -> it + } + }?.joinToString("/")?.let { if (skipExtension) "$it.html" else it }?.let { + Paths.get(dir).relativize(Paths.get(it)).toString() + } ?: run { "" } //TODO just a glue to compile it on HMPP override fun resolveRoot(node: PageNode): String { TODO("Not yet implemented") diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 53292225..6cf34ed1 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -1,6 +1,7 @@ package javadoc import javadoc.pages.* +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.signatures.function @@ -40,7 +41,7 @@ open class JavadocPageCreator( ) fun pageForClasslike(c: DClasslike): JavadocClasslikePageNode? = - c.sourceSets.firstOrNull { it.platform == Platform.jvm }?.let { jvm -> + c.sourceSets.firstOrNull { it.analysisPlatform == Platform.jvm }?.let { jvm -> JavadocClasslikePageNode( name = c.name.orEmpty(), content = contentForClasslike(c), @@ -72,11 +73,11 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(m.dri), JavadocContentKind.OverviewSummary, - m.sourceSets.filter { it.platform == Platform.jvm }.toSet() + m.sourceSets.filter { it.analysisPlatform == Platform.jvm }.toSet() ) { title(m.name, "0.0.1", dri = setOf(m.dri), kind = ContentKind.Main) list("Packages", "Package", setOf(m.dri), ContentKind.Packages, m.packages.sortedBy { it.name }.map { p -> - val description = p.documentation.entries.find { (k, _) -> k.platform == Platform.jvm }?.value?.let { + val description = p.documentation.entries.find { (k, _) -> k.analysisPlatform == Platform.jvm }?.value?.let { it.children.firstIsInstanceOrNull()?.let { description -> DocTagToContentConverter.buildContent( description.root, @@ -96,7 +97,7 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(p.dri), JavadocContentKind.PackageSummary, - p.sourceSets.filter { it.platform == Platform.jvm }.toSet() + p.sourceSets.filter { it.analysisPlatform == Platform.jvm }.toSet() ) { title(p.name, "0.0.1", dri = setOf(p.dri), kind = ContentKind.Packages) list("Packages", "Package", setOf(p.dri), ContentKind.Packages, p.classlikes.sortedBy { it.name }.map { c -> @@ -111,7 +112,7 @@ open class JavadocPageCreator( JavadocContentGroup( setOf(c.dri), JavadocContentKind.Class, - c.sourceSets.filter { it.platform == Platform.jvm }.toSet() + c.sourceSets.filter { it.analysisPlatform == Platform.jvm }.toSet() ) { title( c.name.orEmpty(), @@ -146,7 +147,7 @@ open class JavadocPageCreator( is UnresolvedBound -> p.name } - private fun DFunction.toJavadocFunction(sourceSetData: SourceSetData) = JavadocFunctionNode( + private fun DFunction.toJavadocFunction(sourceSetData: DokkaSourceSet) = JavadocFunctionNode( name = name, signature = signatureProvider.signature(this).jvmSignature(), brief = TextNode(description(sourceSetData), setOf(sourceSetData)), @@ -161,12 +162,12 @@ open class JavadocPageCreator( ) fun List.jvmSignature(): ContentNode = - first { it.sourceSets.any { it.platform == Platform.jvm } } + first { it.sourceSets.any { it.analysisPlatform == Platform.jvm } } - private fun Documentable.description(sourceSetData: SourceSetData): String = + private fun Documentable.description(sourceSetData: DokkaSourceSet): String = findNodeInDocumentation(sourceSetData) - private inline fun Documentable.findNodeInDocumentation(sourceSetData: SourceSetData): String = + private inline fun Documentable.findNodeInDocumentation(sourceSetData: DokkaSourceSet): String = documentation[sourceSetData]?.children?.firstIsInstanceOrNull()?.root?.children?.firstIsInstanceOrNull()?.body.orEmpty() } diff --git a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt index 370ee68b..23a7c9ed 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt @@ -12,7 +12,7 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.ImplementedInterfaces import org.jetbrains.dokka.model.InheritedFunction -import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.renderers.Renderer @@ -269,13 +269,13 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ) + renderJavadocContentNode(node.content) private fun renderImplementedInterfaces(node: JavadocClasslikePageNode) = - node.extras[ImplementedInterfaces]?.interfaces?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.map { it.displayable() } // TODO: REMOVE HARDCODED JVM DEPENDENCY + node.extras[ImplementedInterfaces]?.interfaces?.entries?.firstOrNull { it.key.analysisPlatform == Platform.jvm }?.value?.map { it.displayable() } // TODO: REMOVE HARDCODED JVM DEPENDENCY .orEmpty() private fun renderClasslikeMethods(nodes: List): TemplateMap { val (inherited, own) = nodes.partition { val extra = it.extras[InheritedFunction] - extra?.inheritedFrom?.keys?.first { it.platform == Platform.jvm }?.let { jvm -> + extra?.inheritedFrom?.keys?.first { it.analysisPlatform == Platform.jvm }?.let { jvm -> extra.isInherited(jvm) } ?: false } @@ -294,7 +294,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon private fun renderInheritedMethod(node: JavadocFunctionNode): TemplateMap { val inheritedFrom = node.extras[InheritedFunction]?.inheritedFrom return mapOf( - "inheritedFrom" to inheritedFrom?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.displayable() // TODO: REMOVE HARDCODED JVM DEPENDENCY + "inheritedFrom" to inheritedFrom?.entries?.firstOrNull { it.key.analysisPlatform == Platform.jvm }?.value?.displayable() // TODO: REMOVE HARDCODED JVM DEPENDENCY .orEmpty(), "name" to node.name ) @@ -370,7 +370,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ) } - private fun resolveLink(address: DRI, sourceSets: Set) = + private fun resolveLink(address: DRI, sourceSets: Set) = locationProvider.resolve(address, sourceSets.toList()).let { val afterFormattingToHtml = formatToEndWithHtml(it) if (currentLocation != null) afterFormattingToHtml.relativizePath(currentLocation) diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt index 6587e290..286223fa 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt @@ -1,7 +1,7 @@ package javadoc.pages import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.SourceSetData +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.* @@ -12,7 +12,7 @@ enum class JavadocContentKind : Kind { abstract class JavadocContentNode( dri: Set, kind: Kind, - override val sourceSets: Set + override val sourceSets: Set ) : ContentNode { override val dci: DCI = DCI(dri, kind) override val style: Set