diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-08-14 14:59:04 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-19 13:34:10 +0200 |
commit | c4e4343bdb8df16e49d4da118fccc076abdc928a (patch) | |
tree | 19113d8630d6a24507184876e9d064ec833bc965 /plugins/base/src/main/kotlin/resolvers | |
parent | 28d6598bc749612f75a5c1a4210eb4b0f5aa1f6e (diff) | |
download | dokka-c4e4343bdb8df16e49d4da118fccc076abdc928a.tar.gz dokka-c4e4343bdb8df16e49d4da118fccc076abdc928a.tar.bz2 dokka-c4e4343bdb8df16e49d4da118fccc076abdc928a.zip |
Respect relocated declarations
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers')
8 files changed, 47 insertions, 15 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt index 18f52cce..b92b5330 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt @@ -10,8 +10,10 @@ open class DefaultExternalLocationProvider( val extension: String, val dokkaContext: DokkaContext ) : ExternalLocationProvider { - override fun resolve(dri: DRI): String? { // TODO: classes without packages? + override fun resolve(dri: DRI): String? { val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" + externalDocumentation.packageList.locations[dri.toString()]?.let { path -> return "$docURL$path" } + val classNamesChecked = dri.classNames ?: return "$docURL${dri.packageName ?: ""}/index$extension" val classLink = (listOfNotNull(dri.packageName) + classNamesChecked.split('.')) .joinToString("/", transform = ::identifierToFilename) diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt index bb9fb563..9f8f62da 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt @@ -10,7 +10,7 @@ class DefaultExternalLocationProviderFactory(val context: DokkaContext) : override fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? = when (doc.packageList.linkFormat) { RecognizedLinkFormat.KotlinWebsiteHtml, - RecognizedLinkFormat.DokkaOldHtml, + RecognizedLinkFormat.DokkaOldHtml -> Dokka010ExternalLocationProvider(doc, ".html", context) RecognizedLinkFormat.DokkaHtml -> DefaultExternalLocationProvider(doc, ".html", context) RecognizedLinkFormat.DokkaGFM, RecognizedLinkFormat.DokkaJekyll -> DefaultExternalLocationProvider(doc, ".md", context) diff --git a/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt new file mode 100644 index 00000000..33bc96d8 --- /dev/null +++ b/plugins/base/src/main/kotlin/resolvers/external/Dokka010ExternalLocationProvider.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka.base.resolvers.external + +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider.Companion.identifierToFilename +import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.plugability.DokkaContext + +open class Dokka010ExternalLocationProvider( + val externalDocumentation: ExternalDocumentation, + val extension: String, + val dokkaContext: DokkaContext +) : ExternalLocationProvider { + override fun resolve(dri: DRI): String? { + val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" + + val relocationId = + "${dri.packageName}.${dri.classNames}".let { if (dri.callable != null) it + "$" + dri.callable!!.toOldString() else it } + externalDocumentation.packageList.locations[relocationId]?.let { path -> return "$docURL$path" } + + val classNamesChecked = dri.classNames ?: return "$docURL${dri.packageName ?: ""}/index$extension" + val classLink = (listOfNotNull(dri.packageName) + classNamesChecked.split('.')) + .joinToString("/", transform = ::identifierToFilename) + + val callableChecked = dri.callable ?: return "$docURL$classLink/index$extension" + return "$docURL$classLink/" + identifierToFilename(callableChecked.name) + extension + } + + private fun Callable.toOldString() = name + params.joinToString(", ", "(", ")") + receiver?.let { "#$it" } +} diff --git a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt index 48cf554c..60aa540a 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt @@ -15,6 +15,8 @@ class JavadocExternalLocationProvider( override fun resolve(dri: DRI): String? { val docURL = externalDocumentation.documentationURL.toString().removeSuffix("/") + "/" + externalDocumentation.packageList.locations[dri.toString()]?.let { path -> return "$docURL$path" } + val packageLink = dri.packageName?.replace(".", "/") if (dri.classNames == null) { return "$docURL$packageLink/package-summary$extension".htmlEscape() diff --git a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt index 6fe39d35..27e0cd02 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt @@ -14,10 +14,10 @@ class JavadocExternalLocationProviderFactory(val context: DokkaContext) : when (doc.packageList.linkFormat) { RecognizedLinkFormat.Javadoc1 -> JavadocExternalLocationProvider(doc, "()", ", ", context) // Covers JDK 1 - 7 - RecognizedLinkFormat.Javadoc8, - RecognizedLinkFormat.DokkaJavadoc -> + RecognizedLinkFormat.Javadoc8 -> JavadocExternalLocationProvider(doc, "--", "-", context) // Covers JDK 8 - 9 - RecognizedLinkFormat.Javadoc10 -> + RecognizedLinkFormat.Javadoc10, + RecognizedLinkFormat.DokkaJavadoc -> JavadocExternalLocationProvider(doc, "()", ",", context) // Covers JDK 10 else -> null } diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index 45b39eec..c25aa543 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -1,13 +1,12 @@ package org.jetbrains.dokka.base.resolvers.local -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.model.DisplaySourceSet +import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query @@ -25,7 +24,7 @@ abstract class DefaultLocationProvider( .sourceSets .flatMap { sourceSet -> sourceSet.externalDocumentationLinks.map { - PackageList.load(it.packageListUrl, sourceSet.jdkVersion, dokkaContext) + PackageList.load(it.packageListUrl, sourceSet.jdkVersion, dokkaContext.configuration.offlineMode) ?.let { packageList -> ExternalDocumentation(it.url, packageList) } } } @@ -35,14 +34,13 @@ abstract class DefaultLocationProvider( val externalLocationProvider = (externalLocationProviderFactories.asSequence() .mapNotNull { it.getExternalLocationProvider(extDocInfo) }.firstOrNull() ?: run { dokkaContext.logger.error("No ExternalLocationProvider for '${extDocInfo.packageList.url}' found"); null }) - run { null } packageName to externalLocationProvider } } .toMap() .filterKeys(String::isNotBlank) - protected open fun getExternalLocation(dri: DRI, sourceSets: Set<DokkaSourceSet>): String? = + protected open fun getExternalLocation(dri: DRI, sourceSets: Set<DisplaySourceSet>): String? = packagesIndex[dri.packageName]?.resolve(dri) } diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt index d2e6d49b..ca2332db 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt @@ -1,8 +1,8 @@ package org.jetbrains.dokka.base.resolvers.local -import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -44,7 +44,7 @@ open class DokkaLocationProvider( override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = pathTo(node, context) + if (!skipExtension) extension else "" - override fun resolve(dri: DRI, sourceSets: Set<DokkaSourceSet>, context: PageNode?) = + override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) = pagesIndex[dri]?.let { resolve(it, context) } ?: anchorsIndex[dri]?.let { resolve(it, context) + "#$dri" } // Not found in PageGraph, that means it's an external link @@ -58,7 +58,7 @@ open class DokkaLocationProvider( protected open fun pathTo(node: PageNode, context: PageNode?): String { fun pathFor(page: PageNode) = pathsIndex[page] ?: throw AssertionError( - "${page::class.simpleName}(${page.name}) does not belong to current page graph so it is impossible to compute its path" + "${page::class.simpleName}(${page.name}) does not belong to the current page graph so it is impossible to compute its path" ) val contextNode = diff --git a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt index 819f5f09..e5f88556 100644 --- a/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt +++ b/plugins/base/src/main/kotlin/resolvers/shared/PackageList.kt @@ -11,8 +11,8 @@ data class PackageList( val url: URL ) { companion object { - fun load(url: URL, jdkVersion: Int, dokkaContext: DokkaContext): PackageList? { - if (dokkaContext.configuration.offlineMode && url.protocol.toLowerCase() != "file") + fun load(url: URL, jdkVersion: Int, offlineMode: Boolean = false): PackageList? { + if (offlineMode && url.protocol.toLowerCase() != "file") return null val packageListStream = url.readContent() |