aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-08-24 15:06:36 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-25 13:12:48 +0200
commitcd3f48ec64e60221bd63720fa24cff8fd7afe6c7 (patch)
treee01483148b5d7ef5afa7c7090d82a8bdba7d7db0 /plugins/base/src
parent293d8788b5188cb29a8c792e7d54377b57963f3b (diff)
downloaddokka-cd3f48ec64e60221bd63720fa24cff8fd7afe6c7.tar.gz
dokka-cd3f48ec64e60221bd63720fa24cff8fd7afe6c7.tar.bz2
dokka-cd3f48ec64e60221bd63720fa24cff8fd7afe6c7.zip
Fix external links to Android and Androix documentations
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/external/javadoc/AndroidExternalLocationProvider.kt14
-rw-r--r--plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProvider.kt18
-rw-r--r--plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt27
-rw-r--r--plugins/base/src/test/kotlin/locationProvider/AndroidExternalLocationProviderTest.kt89
4 files changed, 132 insertions, 16 deletions
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)
+ )
+ }
+}