Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preserving spaces in Javadoc comments #1923

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class DefaultPsiToDocumentableTranslator(
name.orEmpty(),
fields.filterIsInstance<PsiEnumConstant>().map { entry ->
DEnumEntry(
dri.withClass("${entry.name}"),
dri.withClass(entry.name),
entry.name,
javadocParser.parseDocumentation(entry).toSourceSetDependent(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -253,7 +253,7 @@ class JavadocParser(
val lastHtmlTag = text.trim().substringAfterLast("<")
val endsWithAnUnclosedTag = lastHtmlTag.endsWith(">") && !lastHtmlTag.startsWith("</")

return (nextSibling as? PsiWhiteSpace)?.text == "\n " &&
return (nextSibling as? PsiWhiteSpace)?.text?.startsWith("\n ") == true &&
(getNextSiblingIgnoringWhitespace() as? PsiDocToken)?.tokenType != JavaDocTokenTypes.INSTANCE.commentEnd() &&
nextNotEmptySibling?.isLeadingAsterisk() == true &&
furtherNotEmptySibling?.tokenType == JavaDocTokenTypes.INSTANCE.commentData() &&
Expand Down
50 changes: 50 additions & 0 deletions plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package parsers

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DModule
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import utils.text

class JavadocParserTest : BaseAbstractTest() {

private fun performJavadocTest(testOperation: (DModule) -> 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())
}
}
}