From e848994d3b350c681501fc32d4c7b3053fdb3840 Mon Sep 17 00:00:00 2001 From: "Vadim.Mishenev" Date: Tue, 12 Mar 2024 19:49:45 +0200 Subject: [PATCH 1/3] Add a test --- .../linkableContent/LinkableContentTest.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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..2129c482d6 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,41 @@ class LinkableContentTest : BaseAbstractTest() { } } } + + @Test + fun `should have a correct url to an external inherited member #2879`() { + val writerPlugin = TestOutputWriterPlugin() + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + 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 = org.jetbrains.dokka.links.DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList())) + assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classA)) + assertEquals("index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classB)) + assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classC)) + } + } + } } From 31da6517bf52f30aa71e06108000135d7c08b085 Mon Sep 17 00:00:00 2001 From: "Vadim.Mishenev" Date: Tue, 19 Mar 2024 18:35:10 +0200 Subject: [PATCH 2/3] Remove resolve DRI to anchor links --- .../base/resolvers/local/DokkaLocationProvider.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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) From d937a1e58e63adb032666bcfe7597e2c8e1c3572 Mon Sep 17 00:00:00 2001 From: "Vadim.Mishenev" Date: Tue, 19 Mar 2024 18:35:31 +0200 Subject: [PATCH 3/3] Add tests --- .../linkableContent/LinkableContentTest.kt | 36 -------- .../DefaultExternalLocationProviderTest.kt | 83 +++++++++++++++++++ 2 files changed, 83 insertions(+), 36 deletions(-) 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 2129c482d6..e0df2caabe 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -421,40 +421,4 @@ class LinkableContentTest : BaseAbstractTest() { } } - @Test - fun `should have a correct url to an external inherited member #2879`() { - val writerPlugin = TestOutputWriterPlugin() - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - 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 = org.jetbrains.dokka.links.DRI("kotlin.collections", "Collection", Callable(name="isEmpty", receiver=null, params=emptyList())) - assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classA)) - assertEquals("index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classB)) - assertEquals("../-b/index.html#-719293276%2FFunctions%2F-1617659094", location.resolve(dri, sourceSet, classC)) - } - } - } } 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")) + } + } + } }