From 9b8280a227848c53045cabc5a86cd013d720c63c Mon Sep 17 00:00:00 2001 From: Vladimir Kryachko Date: Thu, 16 Jul 2020 11:28:30 -0400 Subject: Fix external link rendering. The issue manifested by rendering "empty" links to not-imported fully-qualified symbols, for example `{@link com.example.Foo#bar()}` as opposed to `{@link Foo#bar()}` where the file also contains `import com.example.Foo;`. The resulting rendering would be ` `( note the space instead of the symbol name. Bug: 161729379 Change-Id: Idc90a7c94c1babff1656a0d2e71194dc7016ec70 --- core/src/main/kotlin/Java/JavadocParser.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt index 27cca9177..f446a998d 100644 --- a/core/src/main/kotlin/Java/JavadocParser.kt +++ b/core/src/main/kotlin/Java/JavadocParser.kt @@ -439,7 +439,13 @@ class JavadocParser( val externalLink = resolveExternalLink(valueElement) val linkSignature by lazy { resolveInternalLink(valueElement) } if (externalLink != null || linkSignature != null) { - val labelText = tag.dataElements.firstOrNull { it is PsiDocToken }?.text ?: valueElement!!.text + + // sometimes `dataElements` contains multiple `PsiDocToken` elements and some have whitespace in them + // this is best effort to find the first non-empty one before falling back to using the symbol name. + val labelText = tag.dataElements.firstOrNull { + it is PsiDocToken && it.text?.trim()?.isNotEmpty() ?: false + }?.text ?: valueElement!!.text + val linkTarget = if (externalLink != null) "href=\"$externalLink\"" else "docref=\"$linkSignature\"" val link = "$labelText" if (tag.name == "link") "$link" else link -- cgit v1.2.3