Skip to content

Commit

Permalink
Do not render default value for var properties (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev authored and atyrin committed Nov 1, 2022
1 parent 18ebe88 commit 2d454b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,15 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
link(p.name, p.dri, styles = mainStyles + p.stylesIfDeprecated(sourceSet))
operator(": ")
signatureForProjection(p.type)
defaultValueAssign(p, sourceSet)

if (p.isNotMutable()) {
defaultValueAssign(p, sourceSet)
}
}
}

private fun DProperty.isNotMutable(): Boolean = !isMutable()

private fun DProperty.isMutable(): Boolean {
return this.extra[IsVar] != null || this.setter != null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,35 @@ class ContentForSignaturesTest : BaseAbstractTest() {
pagesTransformationStage = { module ->
val page = module.children.single { it.name == "test" } as PackagePageNode
page.content.assertNode {
propertySignature(emptyMap(), "protected", "", setOf("lateinit"), "var", "property", "Int", "6")
propertySignature(emptyMap(), "protected", "", setOf("lateinit"), "var", "property", "Int", null)
}
}
}
}

@Test
fun `should not display default value for mutable property`() {
testInline(
"""
|/src/main/kotlin/test/source.kt
|package test
|
|var property: Int = 6
""".trimIndent(), testConfiguration
) {
pagesTransformationStage = { module ->
val page = module.children.single { it.name == "test" } as PackagePageNode
page.content.assertNode {
propertySignature(
annotations = emptyMap(),
visibility = "",
modifier = "",
keywords = setOf(),
preposition = "var",
name = "property",
type = "Int",
value = null
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/base/src/test/kotlin/utils/contentUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fun ContentMatcherBuilder<*>.propertySignature(
}
}
}
if (type != null) {
if (value != null) {
+(" = $value")
}
}
Expand Down

0 comments on commit 2d454b9

Please sign in to comment.