From 4f5e54528427451de7741d8e5cdefaf550c2f36c Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Tue, 30 Jun 2020 13:44:08 +0200 Subject: JavadocParser: Remove unexpected whitespace from javadoc --- .../base/src/main/kotlin/translators/psi/JavadocParser.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt index 7119ba68..89226821 100644 --- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt @@ -122,13 +122,16 @@ class JavadocParser( private fun getSeeTagElementContent(tag: PsiDocTag): List = listOfNotNull(tag.referenceElement()?.toDocumentationLink()) - private fun PsiDocComment.getDescription(): Description? = - convertJavadocElements(descriptionElements.dropWhile { - it.text.trim().isEmpty() - }).takeIf { it.isNotEmpty() }?.let { list -> - Description(P(list)) + private fun PsiDocComment.getDescription(): Description? { + val nonEmptyDescriptionElements = descriptionElements.filter { it.text.trim().isNotEmpty() } + val convertedDescriptionElements = convertJavadocElements(nonEmptyDescriptionElements) + if (convertedDescriptionElements.isNotEmpty()) { + return Description(P(convertedDescriptionElements)) } + return null + } + private fun convertJavadocElements(elements: Iterable): List = elements.mapNotNull { when (it) { @@ -136,7 +139,7 @@ class JavadocParser( is PsiInlineDocTag -> listOfNotNull(convertInlineDocTag(it)) is PsiDocParamRef -> listOfNotNull(it.toDocumentationLink()) is PsiDocTagValue, - is LeafPsiElement -> Jsoup.parse(it.text).body().childNodes().mapNotNull { convertHtmlNode(it) } + is LeafPsiElement -> Jsoup.parse(it.text.trim()).body().childNodes().mapNotNull(::convertHtmlNode) else -> null } }.flatten() -- cgit