From 7b3bc6f97ee46981bd88852a50ee4a351bd4879d Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 16 Dec 2020 10:25:34 +0100 Subject: Resolve an issue with cross package linking in javadoc (#1659) --- .../dokka/javadoc/location/JavadocLocationTest.kt | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'plugins/javadoc/src/test/kotlin/org/jetbrains') diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationTest.kt index 26a6aaff..7abbeca8 100644 --- a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationTest.kt +++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLocationTest.kt @@ -40,6 +40,13 @@ class JavadocLocationTest : BaseAbstractTest() { | fun test2(s: String) {} | fun test3(a: A, t: T) {} |} + | + |/jvmSrc/another/javadoc/example/Referenced.kt + |package javadoc.example.another + |/** + | * Referencing element from another package: [javadoc.test.Test] + | */ + |class Referenced {} """.trimIndent(), config, cleanupOutput = false, @@ -52,7 +59,7 @@ class JavadocLocationTest : BaseAbstractTest() { locationTestInline { rootPageNode, dokkaContext -> val transformer = htmlTranslator(rootPageNode, dokkaContext) - val testClass = rootPageNode.firstChildOfType() + val testClass = rootPageNode.firstChildOfType { it.name == "javadoc.test" } .firstChildOfType() assertEquals( " implements Serializable, Cloneable", @@ -66,7 +73,7 @@ class JavadocLocationTest : BaseAbstractTest() { locationTestInline { rootPageNode, dokkaContext -> val transformer = htmlTranslator(rootPageNode, dokkaContext) - val testClassNode = rootPageNode.firstChildOfType() + val testClassNode = rootPageNode.firstChildOfType { it.name == "javadoc.test" } .firstChildOfType { it.name == "Test" } val testFunctionNode = testClassNode.methods.first { it.name == "test" } assertEquals( @@ -84,7 +91,7 @@ class JavadocLocationTest : BaseAbstractTest() { locationTestInline { rootPageNode, dokkaContext -> val transformer = htmlTranslator(rootPageNode, dokkaContext) - val testClassNode = rootPageNode.firstChildOfType() + val testClassNode = rootPageNode.firstChildOfType { it.name == "javadoc.test" } .firstChildOfType { it.name == "Test" } val testFunctionNode = testClassNode.methods.first { it.name == "test2" } assertEquals( @@ -102,7 +109,7 @@ class JavadocLocationTest : BaseAbstractTest() { locationTestInline { rootPageNode, dokkaContext -> val transformer = htmlTranslator(rootPageNode, dokkaContext) - val testClassNode = rootPageNode.firstChildOfType() + val testClassNode = rootPageNode.firstChildOfType { it.name == "javadoc.test" } .firstChildOfType { it.name == "Test" } val testFunctionNode = testClassNode.methods.first { it.name == "test3" } assertEquals( @@ -121,13 +128,29 @@ class JavadocLocationTest : BaseAbstractTest() { locationTestInline { rootPageNode, dokkaContext -> val locationProvider = dokkaContext.plugin().querySingle { locationProviderFactory } .getLocationProvider(rootPageNode) - val packageNode = rootPageNode.firstChildOfType() + val packageNode = rootPageNode.firstChildOfType() { it.name == "javadoc.test" } val packagePath = locationProvider.resolve(packageNode) assertEquals("javadoc/test/package-summary", packagePath) } } + @Test + fun `resolve link from another package`(){ + locationTestInline { rootPageNode, dokkaContext -> + val transformer = htmlTranslator(rootPageNode, dokkaContext) + val testClassNode = rootPageNode.firstChildOfType { it.name == "javadoc.example.another" } + .firstChildOfType { it.name == "Referenced" } + assertEquals( + """

Referencing element from another package: javadoc.test.Test

""", + transformer.htmlForContentNode( + testClassNode.description.single(), + testClassNode + ) + ) + } + } + private fun htmlTranslator(rootPageNode: RootPageNode, dokkaContext: DokkaContext): JavadocContentToHtmlTranslator { val locationProvider = dokkaContext.plugin().querySingle { locationProviderFactory } .getLocationProvider(rootPageNode) as JavadocLocationProvider -- cgit