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

Do not render default value for var properties #2717

Merged
merged 1 commit into from Oct 20, 2022
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
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
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
Expand Up @@ -176,7 +176,7 @@ fun ContentMatcherBuilder<*>.propertySignature(
}
}
}
if (type != null) {
if (value != null) {
+(" = $value")
}
}
Expand Down