aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorVadim Mishenev <vad-mishenev@yandex.ru>2022-04-28 15:20:43 +0300
committerGitHub <noreply@github.com>2022-04-28 15:20:43 +0300
commit4451b8e546584da389da60f73b56ce25d6ac2eaa (patch)
treefe9c2b8772bad7d8970c85c3144bad0803ca00f6 /plugins/base/src/main
parent2e88c6f70feff1edb9f386110a071df897f3b319 (diff)
downloaddokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.tar.gz
dokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.tar.bz2
dokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.zip
Make a default value dependent on source set (#2449)
* Make a default value dependent on source set * Get a default value from an expect source set * Fix default value for expect properties * Deprecate `DefaultValue.value` * Add test * Refactor * Reformat
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt61
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt4
2 files changed, 36 insertions, 29 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 612f9ace..42ae1c27 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -13,7 +13,10 @@ import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.Nullable
import org.jetbrains.dokka.model.TypeConstructor
import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.pages.ContentKind
+import org.jetbrains.dokka.pages.ContentNode
+import org.jetbrains.dokka.pages.TextStyle
+import org.jetbrains.dokka.pages.TokenStyle
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
@@ -117,6 +120,19 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
} ?: regularSignature(c, sourceSetData)
}
+ private fun <T : Documentable> PageContentBuilder.DocumentableContentBuilder.defaultValueAssign(
+ d: WithExtraProperties<T>,
+ sourceSet: DokkaSourceSet
+ ) {
+ // a default value of parameter can be got from expect source set
+ // but expect properties cannot have a default value
+ d.extra[DefaultValue]?.expression?.let {
+ it[sourceSet] ?: if (d is DParameter) it[d.expectPresentInSet] else null
+ }?.let { expr ->
+ operator(" = ")
+ highlightValue(expr)
+ }
+ }
private fun regularSignature(c: DClasslike, sourceSet: DokkaSourceSet) =
contentBuilder.contentFor(
@@ -197,10 +213,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text(param.name.orEmpty())
operator(": ")
signatureForProjection(param.type)
- param.extra[DefaultValue]?.let {
- operator(" = ")
- highlightValue(it.value)
- }
+ defaultValueAssign(param, sourceSet)
}
punctuation(")")
}
@@ -228,20 +241,20 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
(this.sources[sourceSet] as? DescriptorDocumentableSource)?.descriptor?.findPsi() is KtParameter
private fun propertySignature(p: DProperty) =
- p.sourceSets.map {
+ p.sourceSets.map { sourceSet ->
contentBuilder.contentFor(
p,
ContentKind.Symbol,
- setOf(TextStyle.Monospace) + p.stylesIfDeprecated(it),
- sourceSets = setOf(it)
+ setOf(TextStyle.Monospace) + p.stylesIfDeprecated(sourceSet),
+ sourceSets = setOf(sourceSet)
) {
annotationsBlock(p)
- p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
- if (p.isExpectActual) keyword(if (it == p.expectPresentInSet) "expect " else "actual ")
- p.modifier[it].takeIf { it !in ignoredModifiers }?.let {
+ p.visibility[sourceSet].takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ if (p.isExpectActual) keyword(if (sourceSet == p.expectPresentInSet) "expect " else "actual ")
+ p.modifier[sourceSet].takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
}?.name?.let { keyword("$it ") }
- p.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
+ p.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
p.setter?.let { keyword("var ") } ?: keyword("val ")
list(p.generics, prefix = "<", suffix = "> ",
separatorStyles = mainStyles + TokenStyle.Punctuation,
@@ -256,10 +269,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
link(p.name, p.dri)
operator(": ")
signatureForProjection(p.type)
- p.extra[DefaultValue]?.run {
- operator(" = ")
- highlightValue(value)
- }
+ defaultValueAssign(p, sourceSet)
}
}
@@ -274,20 +284,20 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun functionSignature(f: DFunction) =
- f.sourceSets.map {
+ f.sourceSets.map { sourceSet ->
contentBuilder.contentFor(
f,
ContentKind.Symbol,
- setOf(TextStyle.Monospace) + f.stylesIfDeprecated(it),
- sourceSets = setOf(it)
+ setOf(TextStyle.Monospace) + f.stylesIfDeprecated(sourceSet),
+ sourceSets = setOf(sourceSet)
) {
annotationsBlock(f)
- f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
- if (f.isExpectActual) keyword(if (it == f.expectPresentInSet) "expect " else "actual ")
- f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let {
+ f.visibility[sourceSet]?.takeIf { it !in ignoredVisibilities }?.name?.let { keyword("$it ") }
+ if (f.isExpectActual) keyword(if (sourceSet == f.expectPresentInSet) "expect " else "actual ")
+ f.modifier[sourceSet]?.takeIf { it !in ignoredModifiers }?.let {
if (it is JavaModifier.Empty) KotlinModifier.Open else it
}?.name?.let { keyword("$it ") }
- f.modifiers()[it]?.toSignatureString()?.let { keyword(it) }
+ f.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
keyword("fun ")
val usedGenerics = if (f.isConstructor) f.generics.filter { f uses it } else f.generics
list(usedGenerics, prefix = "<", suffix = "> ",
@@ -312,10 +322,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text(param.name!!)
operator(": ")
signatureForProjection(param.type)
- param.extra[DefaultValue]?.run {
- operator(" = ")
- highlightValue(value)
- }
+ defaultValueAssign(param, sourceSet)
}
}
punctuation(")")
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 6bc8774d..91848963 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -467,7 +467,7 @@ private class DokkaDescriptorVisitor(
.toAdditionalExtras()).toSet().toSourceSetDependent().toAdditionalModifiers(),
(descriptor.getAnnotationsWithBackingField() + descriptor.fileLevelAnnotations()).toSourceSetDependent()
.toAnnotations(),
- descriptor.getDefaultValue()?.let { DefaultValue(it) },
+ descriptor.getDefaultValue()?.let { DefaultValue(it.toSourceSetDependent()) },
InheritedMember(inheritedFrom.toSourceSetDependent()),
)
)
@@ -712,7 +712,7 @@ private class DokkaDescriptorVisitor(
extra = PropertyContainer.withAll(listOfNotNull(
descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
descriptor.getAnnotations().toSourceSetDependent().toAnnotations(),
- descriptor.getDefaultValue()?.let { DefaultValue(it) }
+ descriptor.getDefaultValue()?.let { DefaultValue(it.toSourceSetDependent()) }
))
)