From 75f572b271c5959bd6fab0b51cef792fa403ea83 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak <32793002+BarkingBad@users.noreply.github.com> Date: Thu, 8 Oct 2020 20:25:06 +0200 Subject: Fix multiline links in javadoc and wrong linebreaking of
 bodies
 (#1518)

* Fix multiline links in javadoc

* Fix wrong linebreaking of 
 bodies

* Use included static values for external links

Co-authored-by: Marcin Aman 
---
 .../javadoc/AbstractJavadocTemplateMapTest.kt      |  7 +-
 .../dokka/javadoc/location/JavadocLinkingTest.kt   | 74 ++++++++++++++++++++++
 .../dokka/javadoc/location/JavadocLocationTest.kt  | 10 +--
 3 files changed, 80 insertions(+), 11 deletions(-)
 create mode 100644 plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLinkingTest.kt

(limited to 'plugins/javadoc/src/test/kotlin/org/jetbrains')

diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/AbstractJavadocTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/AbstractJavadocTemplateMapTest.kt
index 09feebe9..ec5c215e 100644
--- a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/AbstractJavadocTemplateMapTest.kt
+++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/AbstractJavadocTemplateMapTest.kt
@@ -1,7 +1,6 @@
 package org.jetbrains.dokka.javadoc
 
-import org.jetbrains.dokka.DokkaConfigurationImpl
-import org.jetbrains.dokka.ExternalDocumentationLink
+import org.jetbrains.dokka.*
 import org.jetbrains.dokka.javadoc.pages.JavadocPageNode
 import org.jetbrains.dokka.javadoc.renderer.JavadocContentToTemplateMapTranslator
 import org.jetbrains.dokka.javadoc.JavadocPlugin
@@ -19,8 +18,8 @@ internal abstract class AbstractJavadocTemplateMapTest : AbstractCoreTest() {
                 sourceRoots = listOf("src")
                 analysisPlatform = "jvm"
                 externalDocumentationLinks = listOf(
-                    ExternalDocumentationLink("https://docs.oracle.com/javase/8/docs/api/"),
-                    ExternalDocumentationLink("https://kotlinlang.org/api/latest/jvm/stdlib/")
+                    DokkaConfiguration.ExternalDocumentationLink.jdk(8),
+                    DokkaConfiguration.ExternalDocumentationLink.kotlinStdlib()
                 )
             }
         }
diff --git a/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLinkingTest.kt b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLinkingTest.kt
new file mode 100644
index 00000000..95dc6a2e
--- /dev/null
+++ b/plugins/javadoc/src/test/kotlin/org/jetbrains/dokka/javadoc/location/JavadocLinkingTest.kt
@@ -0,0 +1,74 @@
+package org.jetbrains.dokka.javadoc.location
+
+import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.jdk
+import org.jetbrains.dokka.kotlinStdlib
+import org.jetbrains.dokka.model.doc.DocumentationLink
+import org.jetbrains.dokka.model.doc.Text
+import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+import org.jetbrains.dokka.utilities.cast
+import org.junit.jupiter.api.Test
+import utils.TestOutputWriterPlugin
+import kotlin.test.assertEquals
+
+class JavadocLinkingTest : AbstractCoreTest() {
+
+    @Test
+    fun lineBrokenLink() {
+        val config = dokkaConfiguration {
+            sourceSets {
+                sourceSet {
+                    sourceRoots = listOf("jvmSrc/")
+                    externalDocumentationLinks = listOf(
+                        DokkaConfiguration.ExternalDocumentationLink.jdk(8),
+                        DokkaConfiguration.ExternalDocumentationLink.kotlinStdlib(),
+                    )
+                    analysisPlatform = "jvm"
+                }
+            }
+        }
+        testInline(
+            """
+            |/jvmSrc/javadoc/test/SomeClass.kt
+            |
+            |package example
+            |
+            |class SomeClass {
+            |    fun someFun(x: Int): Int = 1
+            |}
+            |
+            |/jvmSrc/javadoc/test/SomeJavaDocExample.java
+            |
+            |package example;
+            |
+            |/**
+            | * Here comes some comment
+            | *
+            | * {@link example.SomeClass#someFun(int) someName(ads,
+            | * dsa)}
+            | *
+            | * longer comment
+            | */
+            |public class SomeJavaDocExample {
+            |    public void someFunc(int integer, Object object) {
+            |    }
+            |}
+        """.trimMargin(),
+            config,
+            pluginOverrides = listOf(TestOutputWriterPlugin())
+        ) {
+            documentablesMergingStage = {
+                it.packages.single()
+                    .classlikes.single { classlike -> classlike.name == "SomeJavaDocExample" }
+                    .documentation.values.single()
+                    .children.single()
+                    .children.single()
+                    .children.single {
+                        it is DocumentationLink
+                    }.children.filterIsInstance().single { it.body.contains("someName") }.cast().body.run {
+                        assertEquals("someName(ads, dsa)", this)
+                    }
+            }
+        }
+    }
+}
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 87de4228..c8ae59e3 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
@@ -1,11 +1,9 @@
 package org.jetbrains.dokka.javadoc.location
 
+import org.jetbrains.dokka.*
 import org.jetbrains.dokka.javadoc.pages.JavadocClasslikePageNode
 import org.jetbrains.dokka.javadoc.pages.JavadocPackagePageNode
 import org.jetbrains.dokka.javadoc.renderer.JavadocContentToHtmlTranslator
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.ExternalDocumentationLink
-import org.jetbrains.dokka.ExternalDocumentationLinkImpl
 import org.jetbrains.dokka.javadoc.JavadocPlugin
 import org.jetbrains.dokka.model.firstChildOfType
 import org.jetbrains.dokka.pages.RootPageNode
@@ -19,16 +17,14 @@ import org.junit.jupiter.api.Assertions.assertEquals
 class JavadocLocationTest : AbstractCoreTest() {
 
     private fun locationTestInline(testHandler: (RootPageNode, DokkaContext) -> Unit) {
-        fun externalLink(link: String) = ExternalDocumentationLink(link)
-
         val config = dokkaConfiguration {
             format = "javadoc"
             sourceSets {
                 sourceSet {
                     sourceRoots = listOf("jvmSrc/")
                     externalDocumentationLinks = listOf(
-                        externalLink("https://docs.oracle.com/javase/8/docs/api/"),
-                        externalLink("https://kotlinlang.org/api/latest/jvm/stdlib/")
+                        DokkaConfiguration.ExternalDocumentationLink.jdk(8),
+                        DokkaConfiguration.ExternalDocumentationLink.kotlinStdlib()
                     )
                     analysisPlatform = "jvm"
                 }
-- 
cgit