diff options
Diffstat (limited to 'core/src/main/kotlin/Java/JavadocParser.kt')
-rw-r--r-- | core/src/main/kotlin/Java/JavadocParser.kt | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt index 04de29087..21cc2bbdf 100644 --- a/core/src/main/kotlin/Java/JavadocParser.kt +++ b/core/src/main/kotlin/Java/JavadocParser.kt @@ -1,12 +1,11 @@ package org.jetbrains.dokka import com.intellij.psi.* -import com.intellij.psi.impl.source.javadoc.CorePsiDocTagValueImpl +import com.intellij.psi.impl.source.javadoc.PsiDocTagValueImpl import com.intellij.psi.impl.source.tree.JavaDocElementType import com.intellij.psi.javadoc.* import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.IncorrectOperationException -import com.intellij.util.containers.isNullOrEmpty import org.jetbrains.dokka.Model.CodeNode import org.jetbrains.kotlin.utils.join import org.jetbrains.kotlin.utils.keysToMap @@ -172,7 +171,7 @@ class JavadocParser( fun PsiDocTag.getApiLevel(): String? { if (dataElements.isNotEmpty()) { val data = dataElements - if (data[0] is CorePsiDocTagValueImpl) { + if (data[0] is PsiDocTagValueImpl) { val docTagValue = data[0] if (docTagValue.firstChild != null) { val apiLevel = docTagValue.firstChild @@ -420,11 +419,12 @@ class JavadocParser( linkNode } linkSignature != null -> { + @Suppress("USELESS_CAST") + val signature: String = linkSignature as String val linkNode = ContentNodeLazyLink( - (tag.valueElement ?: linkElement).text, - { -> refGraph.lookupOrWarn(linkSignature, logger) } - ) + (tag.valueElement ?: linkElement).text + ) { refGraph.lookupOrWarn(signature, logger) } linkNode.append(text) linkNode } @@ -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 = "<a $linkTarget>$labelText</a>" if (tag.name == "link") "<code>$link</code>" else link @@ -560,7 +566,7 @@ class JavadocParser( val superMethods = current.findSuperMethods() for (method in superMethods) { val docs = method.docComment?.descriptionElements?.dropWhile { it.text.trim().isEmpty() } - if (!docs.isNullOrEmpty()) { + if (docs?.isNotEmpty() == true) { return method } } @@ -648,7 +654,7 @@ class JavadocParser( appendContentBetweenIncludes(path, betweenTag) } } catch (e: java.lang.Exception) { - logger.error("No file found when processing Java @sample. Path to sample: $path") + logger.error("No file found when processing Java @sample. Path to sample: $path\n") } } |