Skip to content

Commit

Permalink
Fix empty parentheses for no-arg enum entry
Browse files Browse the repository at this point in the history
Fixes #2355
  • Loading branch information
IgnatBeresnev committed Apr 26, 2022
1 parent a43f710 commit 898351e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
18 changes: 10 additions & 8 deletions plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
Expand Up @@ -79,14 +79,16 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
annotationsBlock(e)
link(e.name, e.dri, styles = emptySet())
e.extra[ConstructorValues]?.let { constructorValues ->
constructorValues.values[it]?.let { values ->
punctuation("(")
list(
elements = values,
separator = ", ",
separatorStyles = mainStyles + TokenStyle.Punctuation,
) { highlightValue(it) }
punctuation(")")
constructorValues.values[it]
?.takeIf { values -> values.isNotEmpty() }
?.let { values ->
punctuation("(")
list(
elements = values,
separator = ", ",
separatorStyles = mainStyles + TokenStyle.Punctuation,
) { highlightValue(it) }
punctuation(")")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion plugins/base/src/test/kotlin/enums/EnumsTest.kt
Expand Up @@ -400,7 +400,6 @@ class EnumsTest : BaseAbstractTest() {
group {
group {
link { +"E1" }
+"()"
}
}
group {
Expand Down
39 changes: 39 additions & 0 deletions plugins/base/src/test/kotlin/signatures/SignatureTest.kt
Expand Up @@ -857,4 +857,43 @@ class SignatureTest : BaseAbstractTest() {
}
}
}

@Test
fun `should have no empty parentheses for no-arg enum entry`() {
val writerPlugin = TestOutputWriterPlugin()

testInline(
"""
|/src/main/kotlin/common/EnumClass.kt
|package example
|
|enum class EnumClass(param: String = "Default") {
| EMPTY,
| WITH_ARG("arg")
|}
""".trimMargin(),
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
val enumEntrySignatures = writerPlugin.writer.renderedContent("root/example/-enum-class/index.html")
.select("div.table[data-togglable=Entries]")
.single()
.signature()
.select("div.block")

// TODO [beresnev] change ordering after https://github.com/Kotlin/dokka/pull/2469

enumEntrySignatures[1].match(
A("EMPTY"),
ignoreSpanWithTokenStyle = true
)

enumEntrySignatures[0].match(
A("WITH_ARG"), "(\"arg\")",
ignoreSpanWithTokenStyle = true
)
}
}
}
}

0 comments on commit 898351e

Please sign in to comment.