diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-20 18:56:43 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-02-20 18:56:43 +0100 |
commit | ff0e6be0369f2778d33fd7aa4821548745172b80 (patch) | |
tree | 4bb185e80561ecad52360ee3713be2dbf6a26fe5 | |
parent | f26fccd1ed4cdb399c41f87541099d8cc9f85417 (diff) | |
download | dokka-ff0e6be0369f2778d33fd7aa4821548745172b80.tar.gz dokka-ff0e6be0369f2778d33fd7aa4821548745172b80.tar.bz2 dokka-ff0e6be0369f2778d33fd7aa4821548745172b80.zip |
process @link and @linkplain tags in javadoc
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 27 | ||||
-rw-r--r-- | test/data/format/javaLinkTag.html | 26 | ||||
-rw-r--r-- | test/data/format/javaLinkTag.java | 8 | ||||
-rw-r--r-- | test/src/format/HtmlFormatTest.kt | 6 | ||||
-rw-r--r-- | test/src/model/JavaTest.kt | 2 |
5 files changed, 66 insertions, 3 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index e1b91470..ddc526ac 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -4,6 +4,7 @@ import com.intellij.psi.* import com.intellij.psi.javadoc.PsiDocComment import com.intellij.psi.javadoc.PsiDocTag import com.intellij.psi.javadoc.PsiDocTagValue +import com.intellij.psi.javadoc.PsiInlineDocTag import org.jetbrains.dokka.DocumentationNode.Kind public class JavaDocumentationBuilder(private val options: DocumentationOptions, @@ -18,9 +19,15 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, fun parseDocumentation(docComment: PsiDocComment?): Content { if (docComment == null) return Content.Empty val result = Content() + val para = ContentParagraph() + result.append(para) docComment.getDescriptionElements().dropWhile { it.getText().trim().isEmpty() }.forEach { - val text = if (result.isEmpty()) it.getText().trimLeading() else it.getText() - result.append(ContentText(text)) + if (it is PsiInlineDocTag) { + para.append(convertInlineDocTag(it)) + } else { + val text = if (para.isEmpty()) it.getText().trimLeading() else it.getText() + para.append(ContentText(text)) + } } docComment.getTags().forEach { tag -> val subjectName = tag.getSubjectName() @@ -34,6 +41,22 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, return result } + private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.getName()) { + "link", "linkplain" -> resolveLink(tag.getValueElement()) ?: ContentText(tag.getText()) + else -> ContentText(tag.getText()) + } + + private fun resolveLink(valueElement: PsiDocTagValue?): ContentNode? { + val target = valueElement?.getReference()?.resolve() + if (target != null) { + val signature = getSignature(target) + if (signature != null) { + return ContentNodeLazyLink(valueElement!!.getText(), {() -> signatureToNode[signature]}) + } + } + return null + } + fun PsiDocTag.getSubjectName(): String? { if (getName() == "param" || getName() == "throws" || getName() == "exception") { return getValueElement()?.getText() diff --git a/test/data/format/javaLinkTag.html b/test/data/format/javaLinkTag.html new file mode 100644 index 00000000..65d33283 --- /dev/null +++ b/test/data/format/javaLinkTag.html @@ -0,0 +1,26 @@ +<HTML> +<HEAD> +<title>test / test.Foo</title> +</HEAD> +<BODY> +<a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-foo/index">Foo</a><br/> +<br/> +<h1>Foo</h1> +<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span><span class="symbol"> : </span><span class="identifier">Any</span></code><br/> +<p>Call <a href="test/test/-foo/bar"></a> to do the job. + </p> +<br/> +<br/> +<h3>Functions</h3> +<table> +<tbody> +<tr> +<td> +<a href="test/test/-foo/bar">bar</a></td> +<td> +<code><span class="keyword">public</span> <span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">bar</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code></td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/data/format/javaLinkTag.java b/test/data/format/javaLinkTag.java new file mode 100644 index 00000000..06452f16 --- /dev/null +++ b/test/data/format/javaLinkTag.java @@ -0,0 +1,8 @@ +package test; + +/** + * Call {@link #bar()} to do the job. + */ +class Foo { + public void bar() +} diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index f6e0a2f3..030b72f8 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -99,4 +99,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "C"}.members.filter { it.name == "Bar"} ) } } + + Test fun javaLinkTag() { + verifyOutput("test/data/format/javaLinkTag.java", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } } diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt index 1c2df0d6..f3c7c610 100644 --- a/test/src/model/JavaTest.kt +++ b/test/src/model/JavaTest.kt @@ -12,7 +12,7 @@ public class JavaTest { with(cls.members.single()) { assertEquals("fn", name) assertEquals(DocumentationNode.Kind.Function, kind) - assertEquals("Summary for Function", content.summary.toTestString()) + assertEquals("Summary for Function", content.summary.toTestString().trimTrailing()) assertEquals(3, content.sections.size()) with(content.sections[0]) { assertEquals("Parameters", tag) |