From 6af51fdd6ee41cee6b5a7fd5714b80ad4b077a42 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 27 Feb 2015 17:14:21 +0100 Subject: fix link resolution with other variants of the javadoc PSI structure --- src/Java/JavaDocumentationBuilder.kt | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Java') diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 055d64d3..bb2fb639 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -104,9 +104,13 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, } private fun MutableContent.convertSeeTag(tag: PsiDocTag) { + val linkElement = tag.linkElement() + if (linkElement == null) { + return + } val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) - val linkSignature = resolveLink(tag.getValueElement()) - val text = ContentText(tag.getValueElement()!!.getText()) + val linkSignature = resolveLink(linkElement) + val text = ContentText(linkElement.getText()) if (linkSignature != null) { val linkNode = ContentNodeLazyLink(tag.getValueElement()!!.getText(), {() -> refGraph.lookup(linkSignature)}) linkNode.append(text) @@ -118,14 +122,16 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, private fun convertInlineDocTag(tag: PsiInlineDocTag) = when (tag.getName()) { "link", "linkplain" -> { - val valueElement = tag.getValueElement() + val valueElement = tag.linkElement() val linkSignature = resolveLink(valueElement) if (linkSignature != null) { val link = "${valueElement!!.getText().htmlEscape()}" if (tag.getName() == "link") "$link" else link } - else { - valueElement!!.getText() + else if (valueElement != null) { + valueElement.getText() + } else { + "" } } "code", "literal" -> { @@ -137,7 +143,10 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, else -> tag.getText() } - private fun resolveLink(valueElement: PsiDocTagValue?): String? { + private fun PsiDocTag.linkElement(): PsiElement? = + getValueElement() ?: getDataElements().firstOrNull { it !is PsiWhiteSpace } + + private fun resolveLink(valueElement: PsiElement?): String? { val target = valueElement?.getReference()?.resolve() if (target != null) { return getSignature(target) -- cgit