diff --git a/dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/resolvers/local/DokkaLocationProvider.kt b/dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/resolvers/local/DokkaLocationProvider.kt index 644764f32a..6c8bd901cb 100644 --- a/dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/resolvers/local/DokkaLocationProvider.kt +++ b/dokka-subprojects/plugin-base/src/main/kotlin/org/jetbrains/dokka/base/resolvers/local/DokkaLocationProvider.kt @@ -60,6 +60,7 @@ public open class DokkaLocationProvider( if (first) page else throw AssertionError("Multiple pages associated with key: ${key.dri}/${key.sourceSet}") } + @Deprecated("This is not used anymore and will be removed, since resolving references to anchors is removed to fix #3054") protected val anchorsIndex: Map = pageGraphRoot.withDescendants().filterIsInstance() .flatMap { page -> @@ -107,7 +108,6 @@ public open class DokkaLocationProvider( } return getLocalPageLink(dri, allSourceSets, context) - ?: getLocalAnchor(dri, allSourceSets, context) } private fun getLocalPageLink(dri: DRI, allSourceSets: Iterable>, context: PageNode?) = @@ -115,14 +115,6 @@ public open class DokkaLocationProvider( pagesIndex[DRIWithSourceSets(dri, displaySourceSet)] }.firstOrNull()?.let { page -> resolve(page, context) } - private fun getLocalAnchor(dri: DRI, allSourceSets: Iterable>, context: PageNode?) = - allSourceSets.mapNotNull { displaySourceSet -> - anchorsIndex[DRIWithSourceSets(dri, displaySourceSet)]?.let { (page, kind) -> - val dci = DCI(setOf(dri), kind) - resolve(page, context) + "#" + anchorForDCI(dci, displaySourceSet) - } - }.firstOrNull() - override fun pathToRoot(from: PageNode): String = pathTo(pageGraphRoot, from).removeSuffix(PAGE_WITH_CHILDREN_SUFFIX) diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt index f529a2b0c7..e0df2caabe 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -5,9 +5,11 @@ package linkableContent import org.jetbrains.dokka.SourceLinkDefinitionImpl +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.base.transformers.pages.DefaultSamplesTransformer import org.jetbrains.dokka.base.transformers.pages.sourcelinks.SourceLinksTransformer +import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.model.WithGenerics import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.Text @@ -418,4 +420,5 @@ class LinkableContentTest : BaseAbstractTest() { } } } + } diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt index aaf63e7eef..4f7732f114 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/locationProvider/DefaultExternalLocationProviderTest.kt @@ -5,16 +5,21 @@ package locationProvider import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.TypeConstructor +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.pages.ClasslikePageNode import org.jetbrains.dokka.plugability.DokkaContext +import utils.TestOutputWriterPlugin import java.net.URL import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertTrue class DefaultExternalLocationProviderTest : BaseAbstractTest() { private val testDataDir = @@ -75,4 +80,82 @@ class DefaultExternalLocationProviderTest : BaseAbstractTest() { assertEquals(null, locationProvider.resolve(dri)) } + + @Test + fun `should have a correct url to an external inherited member #2879`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + + + sourceSets { + sourceSet { + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + sourceRoots = listOf("src/") + classpath = listOfNotNull(jvmStdlibPath) + } + } + } + + testInline( + """ + /src/kotlin/main.kt + open interface C : Collection + interface A : C() + interface B : C() + """.trimIndent() + , + pluginOverrides = listOf(writerPlugin), + configuration = configuration + ) { + renderingStage = { rootPage, ctx -> + val location = DokkaLocationProvider(rootPage, ctx, ".html") + val classA = rootPage.dfs { it is ClasslikePageNode && it.name == "A" } + val classB = rootPage.dfs { it is ClasslikePageNode && it.name == "B" } + val classC = rootPage.dfs { it is ClasslikePageNode && it.name == "C" } + val sourceSet = (classA as ClasslikePageNode).content.sourceSets + val dri = DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList())) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classA)) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classB)) + assertEquals("https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/is-empty.html", location.resolve(dri, sourceSet, classC)) + } + } + } + + @Test + fun `should have external links for external inherited members`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + sourceRoots = listOf("src/") + classpath = listOfNotNull(jvmStdlibPath) + } + } + } + + testInline( + """ + /src/kotlin/main.kt + interface MyCharSequence: CharSequence + """.trimIndent() + , + pluginOverrides = listOf(writerPlugin), + configuration = configuration + ) { + renderingStage = { _, _ -> + "".chars() + val content = writerPlugin.writer.contents["root/[root]/-my-char-sequence/index.html"] ?: "" + assertTrue(content.contains("length")) + assertTrue(content.contains("get")) + assertTrue(content.contains("subSequence")) + // TODO #3542 + // these links are invalid + // chars() and codePoints() are absent in https://kotlinlang.org/ since they come from mapping Kotlin to Java + // see https://kotlinlang.org/docs/java-interop.html#mapped-types + assertTrue(content.contains("chars")) + assertTrue(content.contains("codePoints")) + } + } + } }