From d89be4ba91b8c5cb5e9e34063873004992ee884f Mon Sep 17 00:00:00 2001 From: Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> Date: Mon, 17 May 2021 20:45:00 +0200 Subject: Fix preserving spaces in Javadoc comments (#1923) Fixes #1895 --- .../psi/DefaultPsiToDocumentableTranslator.kt | 2 +- .../translators/psi/parsers/JavadocParser.kt | 6 +-- .../src/test/kotlin/parsers/JavadocParserTest.kt | 50 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt (limited to 'plugins') diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index cd2bbfc6..f728c8a7 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -264,7 +264,7 @@ class DefaultPsiToDocumentableTranslator( name.orEmpty(), fields.filterIsInstance().map { entry -> DEnumEntry( - dri.withClass("${entry.name}"), + dri.withClass(entry.name), entry.name, javadocParser.parseDocumentation(entry).toSourceSetDependent(), null, diff --git a/plugins/base/src/main/kotlin/translators/psi/parsers/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/parsers/JavadocParser.kt index a02bceac..dc93568f 100644 --- a/plugins/base/src/main/kotlin/translators/psi/parsers/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/parsers/JavadocParser.kt @@ -213,9 +213,9 @@ class JavadocParser( javadoc doesn't care about it. */ text.let { - if ((prevSibling as? PsiDocToken)?.isLeadingAsterisk() == true && text != " " && state.previousElement !is PsiInlineDocTag) it?.trimStart() else it + if ((prevSibling as? PsiDocToken)?.isLeadingAsterisk() == true && text.isNotBlank() && state.previousElement !is PsiInlineDocTag) it?.trimStart() else it }?.let { - if ((nextSibling as? PsiDocToken)?.isLeadingAsterisk() == true && text != " ") it.trimEnd() else it + if ((nextSibling as? PsiDocToken)?.isLeadingAsterisk() == true && text.isNotBlank()) it.trimEnd() else it }?.let { if (shouldHaveSpaceAtTheEnd()) "$it " else it } @@ -253,7 +253,7 @@ class JavadocParser( val lastHtmlTag = text.trim().substringAfterLast("<") val endsWithAnUnclosedTag = lastHtmlTag.endsWith(">") && !lastHtmlTag.startsWith(" Unit) { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/java") + } + } + } + + testInline( + """ + |/src/main/java/sample/Date2.java + | + |package docs + |/** + | * class level docs + | */ + |public enum AnEnumType { + | /** + | * content being refreshed, which can be a result of + | * invalidation, refresh that may contain content updates, or the initial load. + | */ + | REFRESH + |} + """.trimIndent(), + configuration + ) { + documentablesMergingStage = testOperation + } + } + + @Test + fun `correctly parsed list`() { + performJavadocTest { module -> + val docs = (module.packages.single().classlikes.single() as DEnum).entries.single().documentation.values.single().children.single().root.text() + assertEquals("content being refreshed, which can be a result of invalidation, refresh that may contain content updates, or the initial load.", docs.trimEnd()) + } + } +} -- cgit