From 852a6ce6c0f43c9b2044320dcceb4c6cc0a3b302 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 11 Aug 2020 21:47:26 +0200 Subject: Refactor location providers --- .../javadoc/location/JavadocLocationProvider.kt | 34 ++++++++++++---------- .../location/JavadocLocationProviderFactory.kt | 1 - .../renderer/JavadocContentToHtmlTranslator.kt | 7 ++--- .../dokka/javadoc/renderer/SearchScriptsCreator.kt | 6 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) (limited to 'plugins/javadoc') diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProvider.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProvider.kt index 9b0d8b04..3359b32f 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProvider.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProvider.kt @@ -1,7 +1,8 @@ package org.jetbrains.dokka.javadoc.location +import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.base.resolvers.local.DefaultLocationProvider import org.jetbrains.dokka.javadoc.pages.* -import org.jetbrains.dokka.base.resolvers.local.BaseLocationProvider import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.Nullable import org.jetbrains.dokka.links.parent @@ -14,7 +15,7 @@ import org.jetbrains.dokka.plugability.DokkaContext import java.util.* class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext) : - BaseLocationProvider(dokkaContext) { + DefaultLocationProvider(pageRoot, dokkaContext, ".html") { private val pathIndex = IdentityHashMap>().apply { fun registerPath(page: PageNode, prefix: List = emptyList()) { @@ -64,8 +65,8 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext private fun JavadocClasslikePageNode.findAnchorableByDRI(dri: DRI): AnchorableJavadocNode? = (constructors + methods + entries + properties).firstOrNull { it.dri == dri } - override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?): String { - return nodeIndex[dri]?.let { resolve(it, context) } + override fun resolve(dri: DRI, sourceSets: Set, context: PageNode?) = + nodeIndex[dri]?.let { resolve(it, context) } ?: nodeIndex[dri.parent]?.takeIf { it is JavadocClasslikePageNode }?.let { val anchor = when (val anchorElement = (it as? JavadocClasslikePageNode)?.findAnchorableByDRI(dri)) { is JavadocFunctionNode -> anchorElement.getAnchor() @@ -79,17 +80,18 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext private fun JavadocFunctionNode.getAnchor(): String = - "$name(${parameters.joinToString(",") { - when (val bound = - if (it.typeBound is org.jetbrains.dokka.model.Nullable) it.typeBound.inner else it.typeBound) { - is TypeConstructor -> bound.dri.classNames.orEmpty() - is TypeParameter -> bound.name - is PrimitiveJavaType -> bound.name - is UnresolvedBound -> bound.name - is JavaObject -> "Object" - else -> bound.toString() - } - })" + "$name(" + + parameters.joinToString(",") { + when (val bound = + if (it.typeBound is org.jetbrains.dokka.model.Nullable) it.typeBound.inner else it.typeBound) { + is TypeConstructor -> bound.dri.classNames.orEmpty() + is TypeParameter -> bound.name + is PrimitiveJavaType -> bound.name + is UnresolvedBound -> bound.name + is JavaObject -> "Object" + else -> bound.toString() + } + } + ")" fun anchorForFunctionNode(node: JavadocFunctionNode) = node.getAnchor() @@ -122,7 +124,7 @@ class JavadocLocationProvider(pageRoot: RootPageNode, dokkaContext: DokkaContext } }?.relativeTo(pathIndex[contextRoot].orEmpty())?.let { if (skipExtension) "$it.html" else it }.orEmpty() - override fun resolveRoot(node: PageNode): String { + override fun pathToRoot(from: PageNode): String { TODO("Not yet implemented") } diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProviderFactory.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProviderFactory.kt index 7dd8abe1..1c4420f3 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProviderFactory.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationProviderFactory.kt @@ -5,7 +5,6 @@ import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext class JavadocLocationProviderFactory(private val context: DokkaContext) : LocationProviderFactory { - override fun getLocationProvider(pageNode: RootPageNode) = JavadocLocationProvider(pageNode, context) } \ No newline at end of file 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 1e9a3d65..b5fdde33 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 @@ -69,10 +69,9 @@ internal class JavadocContentToHtmlTranslator( ).joinToString(separator = " ") { htmlForContentNode(it, relative) } private fun buildLinkFromNode(node: ContentDRILink, relative: PageNode?) = - buildLink( - locationProvider.resolve(node.address, node.sourceSets, relative), - htmlForContentNodes(node.children, relative) - ) + locationProvider.resolve(node.address, node.sourceSets, relative)?.let { + buildLink(it, htmlForContentNodes(node.children, relative)) + } ?: htmlForContentNodes(node.children, relative) private fun buildLinkFromNode(node: ContentResolvedLink, relative: PageNode?) = buildLink(node.address, htmlForContentNodes(node.children, relative)) 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 736a1f93..e25a29fd 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 @@ -57,7 +57,7 @@ class SearchScriptsCreator(private val locationProvider: JavadocLocationProvider val modules = SearchData(moduleRecords = input.map { SearchRecord( l = it.name, - url = locationProvider.resolve(it).formatToEndWithHtml() + url = locationProvider.resolve(it)?.formatToEndWithHtml() ) }) val processablePackages = input.flatMap { it.children.filterIsInstance() } @@ -68,7 +68,7 @@ class SearchScriptsCreator(private val locationProvider: JavadocLocationProvider val packages = input.map { SearchRecord( l = it.name, - url = locationProvider.resolve(it).formatToEndWithHtml() + url = locationProvider.resolve(it)?.formatToEndWithHtml() ) } + SearchRecord.allPackages val types = input.flatMap { @@ -86,7 +86,7 @@ class SearchScriptsCreator(private val locationProvider: JavadocLocationProvider SearchRecord( p = it.first.name, l = it.second.name, - url = locationProvider.resolve(it.second).formatToEndWithHtml() + url = locationProvider.resolve(it.second)?.formatToEndWithHtml() ) } + allTypes val updated = accumulator.copy(typeRecords = types) -- cgit