diff options
7 files changed, 135 insertions, 19 deletions
diff --git a/core/src/main/kotlin/defaultExternalLinks.kt b/core/src/main/kotlin/defaultExternalLinks.kt index 01eefb39..b36de388 100644 --- a/core/src/main/kotlin/defaultExternalLinks.kt +++ b/core/src/main/kotlin/defaultExternalLinks.kt @@ -20,7 +20,7 @@ fun ExternalDocumentationLink.Companion.kotlinStdlib(): ExternalDocumentationLin fun ExternalDocumentationLink.Companion.androidSdk(): ExternalDocumentationLinkImpl = - ExternalDocumentationLink("https://developer.android.com/reference/") + ExternalDocumentationLink("https://developer.android.com/reference/kotlin/") fun ExternalDocumentationLink.Companion.androidX(): ExternalDocumentationLinkImpl = ExternalDocumentationLink( diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt index c13fcf14..6246cade 100644 --- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt +++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/Android0GradleIntegrationTest.kt @@ -71,7 +71,7 @@ class Android0GradleIntegrationTest(override val versions: BuildVersions) : Abst assertTrue( htmlOutputDir.allHtmlFiles().any { file -> - "https://developer.android.com/reference/android/content/Context.html" in file.readText() + "https://developer.android.com/reference/kotlin/android/content/Context.html" in file.readText() }, "Expected link to developer.android.com" ) diff --git a/plugins/base/src/main/kotlin/resolvers/external/javadoc/AndroidExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/javadoc/AndroidExternalLocationProvider.kt new file mode 100644 index 00000000..0d4d8766 --- /dev/null +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/AndroidExternalLocationProvider.kt @@ -0,0 +1,14 @@ +package org.jetbrains.dokka.base.resolvers.external.javadoc + +import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.plugability.DokkaContext + +open class AndroidExternalLocationProvider( + externalDocumentation: ExternalDocumentation, + dokkaContext: DokkaContext +) : JavadocExternalLocationProvider(externalDocumentation, "", "", dokkaContext) { + + override fun anchorPart(callable: Callable) = callable.name.toLowerCase() + +} 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 60aa540a..d4f44a94 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt @@ -2,11 +2,12 @@ package org.jetbrains.dokka.base.resolvers.external.javadoc import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider 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 import org.jetbrains.dokka.utilities.htmlEscape -class JavadocExternalLocationProvider( +open class JavadocExternalLocationProvider( externalDocumentation: ExternalDocumentation, val brackets: String, val separator: String, @@ -21,13 +22,16 @@ class JavadocExternalLocationProvider( if (dri.classNames == null) { return "$docURL$packageLink/package-summary$extension".htmlEscape() } - val classLink = if (packageLink == null) "${dri.classNames}$extension" else "$packageLink/${dri.classNames}$extension" + val classLink = + if (packageLink == null) "${dri.classNames}$extension" else "$packageLink/${dri.classNames}$extension" val callableChecked = dri.callable ?: return "$docURL$classLink".htmlEscape() - return ("$docURL$classLink#" + - callableChecked.name + - "${brackets.first()}" + - callableChecked.params.joinToString(separator) + - "${brackets.last()}").htmlEscape() + return ("$docURL$classLink#" + anchorPart(callableChecked)).htmlEscape() } + + protected open fun anchorPart(callable: Callable) = callable.name + + "${brackets.first()}" + + callable.params.joinToString(separator) + + "${brackets.last()}" + } 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 27e0cd02..102d118a 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt @@ -1,5 +1,8 @@ package org.jetbrains.dokka.base.resolvers.external.javadoc +import org.jetbrains.dokka.DokkaConfiguration +import org.jetbrains.dokka.androidSdk +import org.jetbrains.dokka.androidX import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProviderFactory import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProviderFactoryWithCache @@ -11,15 +14,21 @@ class JavadocExternalLocationProviderFactory(val context: DokkaContext) : ExternalLocationProviderFactory by ExternalLocationProviderFactoryWithCache( object : ExternalLocationProviderFactory { override fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? = - when (doc.packageList.linkFormat) { - RecognizedLinkFormat.Javadoc1 -> - JavadocExternalLocationProvider(doc, "()", ", ", context) // Covers JDK 1 - 7 - RecognizedLinkFormat.Javadoc8 -> - JavadocExternalLocationProvider(doc, "--", "-", context) // Covers JDK 8 - 9 - RecognizedLinkFormat.Javadoc10, - RecognizedLinkFormat.DokkaJavadoc -> - JavadocExternalLocationProvider(doc, "()", ",", context) // Covers JDK 10 - else -> null + when (doc.packageList.url) { + DokkaConfiguration.ExternalDocumentationLink.androidX().packageListUrl, + DokkaConfiguration.ExternalDocumentationLink.androidSdk().packageListUrl -> + AndroidExternalLocationProvider(doc, context) + else -> + when (doc.packageList.linkFormat) { + RecognizedLinkFormat.Javadoc1 -> + JavadocExternalLocationProvider(doc, "()", ", ", context) // Covers JDK 1 - 7 + RecognizedLinkFormat.Javadoc8 -> + JavadocExternalLocationProvider(doc, "--", "-", context) // Covers JDK 8 - 9 + RecognizedLinkFormat.Javadoc10, + RecognizedLinkFormat.DokkaJavadoc -> + JavadocExternalLocationProvider(doc, "()", ",", context) // Covers JDK 10 + else -> null + } } } ) diff --git a/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt new file mode 100644 index 00000000..ea2c434f --- /dev/null +++ b/plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt @@ -0,0 +1,89 @@ +package locationProvider + +import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.external.javadoc.AndroidExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation +import org.jetbrains.dokka.base.resolvers.shared.PackageList +import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat +import org.jetbrains.dokka.links.Callable +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.net.URL + +class AndroidExternalLocationProviderTest : AbstractCoreTest() { + private val android = ExternalDocumentation( + URL("https://developer.android.com/reference/kotlin"), + PackageList( + RecognizedLinkFormat.DokkaHtml, + setOf("android.content", "android.net"), + emptyMap(), + URL("file://not-used") + ) + ) + private val androidx = ExternalDocumentation( + URL("https://developer.android.com/reference/kotlin"), + PackageList( + RecognizedLinkFormat.DokkaHtml, + setOf("androidx.appcompat.app"), + emptyMap(), + URL("file://not-used") + ) + ) + private val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + classpath += jvmStdlibPath!! + } + } + } + + private fun getTestLocationProvider( + externalDocumentation: ExternalDocumentation, + context: DokkaContext? = null + ): DefaultExternalLocationProvider { + val dokkaContext = context ?: DokkaContext.create(configuration, logger, emptyList()) + return AndroidExternalLocationProvider(externalDocumentation, dokkaContext) + } + + @Test + fun `#1230 anchor to a method from AndroidX`() { + val locationProvider = getTestLocationProvider(androidx) + val dri = DRI( + "androidx.appcompat.app", + "AppCompatActivity", + Callable("findViewById", null, listOf(TypeConstructor("kotlin.Int", emptyList()))) + ) + + assertEquals( + "${androidx.documentationURL}/androidx/appcompat/app/AppCompatActivity.html#findviewbyid", + locationProvider.resolve(dri) + ) + } + + @Test + fun `anchor to a method from Android`() { + val locationProvider = getTestLocationProvider(android) + val dri = DRI( + "android.content", + "ContextWrapper", + Callable( + "checkCallingUriPermission", + null, + listOf( + TypeConstructor("android.net.Uri", emptyList()), + TypeConstructor("kotlin.Int", emptyList()) + ) + ) + ) + + assertEquals( + "${android.documentationURL}/android/content/ContextWrapper.html#checkcallinguripermission", + locationProvider.resolve(dri) + ) + } +} diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt index e48eb0a4..c1053069 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt @@ -411,7 +411,7 @@ class GradleDokkaSourceSetBuilderTest { project.plugins.apply("com.android.library") assertEquals(1, sourceSet.build().externalDocumentationLinks.count { - "https://developer.android.com/reference/package-list" in it.packageListUrl.toURI().toString() + "https://developer.android.com/reference/kotlin/package-list" in it.packageListUrl.toURI().toString() }, "Expected android sdk in external documentation links") assertEquals(1, sourceSet.build().externalDocumentationLinks.count { |