diff --git a/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt b/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt index ad29f5f034..7fa95ddcfc 100644 --- a/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt +++ b/dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/kdoc/KdocMarkdownParser.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag -import org.jetbrains.kotlin.psi.psiUtil.allChildren +import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType internal fun parseFromKDocTag( kDocTag: KDocTag?, @@ -34,7 +34,11 @@ internal fun parseFromKDocTag( listOf(kDocTag) + if (kDocTag.canHaveParent() && parseWithChildren) getAllKDocTags(findParent(kDocTag)) else emptyList() DocumentationNode( allTags.map { tag -> - val links = tag.allChildren.filterIsInstance().associate { it.getLinkText() to externalDri(it) } + val links = mutableMapOf() + tag.forEachDescendantOfType{ + links[it.getLinkText()] = externalDri(it) + } + val externalDRIProvider = { linkText: String -> links[linkText] } when (tag.knownTag) { diff --git a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt index 97e027b8c0..6d157d27af 100644 --- a/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt +++ b/dokka-subprojects/plugin-base/src/test/kotlin/markdown/LinkTest.kt @@ -7,6 +7,7 @@ package markdown import org.jetbrains.dokka.analysis.kotlin.markdown.MARKDOWN_ELEMENT_FILE_NAME import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.links.* +import org.jetbrains.dokka.model.DClass import org.jetbrains.dokka.model.WithGenerics import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.model.doc.* @@ -238,4 +239,57 @@ class LinkTest : BaseAbstractTest() { } } } + + @Test + fun `link should lead to class rather than constructor`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Testing.kt + |package example + | + |/** + |* @constructor reference in constructor [AllKDocTagsClass] + | */ + |class AllKDocTagsClass(paramInt: Int, paramStr: String = "100"){} + | + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val functionDocs = (module.packages.flatMap { it.classlikes }.first() as DClass).constructors.first().documentation.values.first() + val expected = Description( + root = CustomDocTag( + children = listOf( + P( + children = listOf( + Text("reference in constructor "), + DocumentationLink( + dri = DRI( + packageName = "example", + classNames = "AllKDocTagsClass", + target = PointingToDeclaration + ), + children = listOf( + Text("AllKDocTagsClass") + ), + params = mapOf("href" to "[AllKDocTagsClass]") + ) + ) + ) + ), + name = "MARKDOWN_FILE" + ) + ) + assertEquals(expected, functionDocs.children.first()) + } + } + } }