aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt6
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt20
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt9
3 files changed, 31 insertions, 4 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 02da3f24..24ed0765 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -261,7 +261,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
if (it is JavaModifier.Empty) KotlinModifier.Open else it
}?.name?.let { keyword("$it ") }
p.modifiers()[sourceSet]?.toSignatureString()?.let { keyword(it) }
- p.setter?.let { keyword("var ") } ?: keyword("val ")
+ if (p.isMutable()) keyword("var ") else keyword("val ")
list(p.generics, prefix = "<", suffix = "> ",
separatorStyles = mainStyles + TokenStyle.Punctuation,
surroundingCharactersStyle = mainStyles + TokenStyle.Operator) {
@@ -279,6 +279,10 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
+ private fun DProperty.isMutable(): Boolean {
+ return this.extra[IsVar] != null || this.setter != null
+ }
+
private fun PageContentBuilder.DocumentableContentBuilder.highlightValue(expr: Expression) = when (expr) {
is IntegerConstant -> constant(expr.value.toString())
is FloatConstant -> constant(expr.value.toString() + "f")
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 38992ba0..c4a8253a 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -469,6 +469,8 @@ private class DokkaDescriptorVisitor(
return coroutineScope {
val generics = async { descriptor.typeParameters.parallelMap { it.toVariantTypeParameter() } }
+ val getter = getDescriptorGetter() ?: getImplicitAccessorGetter()
+ val setter = getDescriptorSetter() ?: getImplicitAccessorSetter()
DProperty(
dri = dri,
@@ -477,8 +479,8 @@ private class DokkaDescriptorVisitor(
visitReceiverParameterDescriptor(it, DRIWithPlatformInfo(dri, actual))
},
sources = actual,
- getter = getDescriptorGetter() ?: getImplicitAccessorGetter(),
- setter = getDescriptorSetter() ?: getImplicitAccessorSetter(),
+ getter = getter,
+ setter = setter,
visibility = descriptor.getVisibility(implicitAccessors).toSourceSetDependent(),
documentation = descriptor.resolveDescriptorData(),
modifier = descriptor.modifier().toSourceSetDependent(),
@@ -495,12 +497,26 @@ private class DokkaDescriptorVisitor(
.toAnnotations(),
descriptor.getDefaultValue()?.let { DefaultValue(it.toSourceSetDependent()) },
inheritedFrom?.let { InheritedMember(it.toSourceSetDependent()) },
+ takeIf { descriptor.isVar(getter, setter) }?.let { IsVar },
)
)
)
}
}
+ private fun PropertyDescriptor.isVar(getter: DFunction?, setter: DFunction?): Boolean {
+ return if (this is JavaPropertyDescriptor) {
+ // in Java, concepts of extensibility and mutability are mixed into a single `final` modifier
+ // in Kotlin, it's different - val/var controls mutability and open modifier controls extensibility
+ // so when inheriting Java properties, you can end up with a final var - non extensible mutable prop
+ val isMutable = this.isVar
+ // non-final java property should be var if it has no accessors at all or has a setter
+ (isMutable && getter == null && setter == null) || (getter != null && setter != null)
+ } else {
+ this.isVar
+ }
+ }
+
private fun PropertyDescriptor.getVisibility(implicitAccessors: DescriptorAccessorHolder?): Visibility {
val isNonPublicJavaProperty = this is JavaPropertyDescriptor && !this.visibility.isPublicAPI
val visibility =
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index bef86144..f64eb261 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -620,6 +620,12 @@ class DefaultPsiToDocumentableTranslator(
private fun parseField(psi: PsiField, getter: DFunction?, setter: DFunction?, inheritedFrom: DRI? = null): DProperty {
val dri = DRI.from(psi)
+
+ // non-final java field without accessors should be a var
+ // setter should be not null when inheriting kotlin vars
+ val isMutable = !psi.hasModifierProperty("final")
+ val isVar = (isMutable && getter == null && setter == null) || (getter != null && setter != null)
+
return DProperty(
dri = dri,
name = psi.name,
@@ -645,7 +651,8 @@ class DefaultPsiToDocumentableTranslator(
PropertyContainer.withAll(
inheritedFrom?.let { inheritedFrom -> InheritedMember(inheritedFrom.toSourceSetDependent()) },
it.toSourceSetDependent().toAdditionalModifiers(),
- annotations.toSourceSetDependent().toAnnotations()
+ annotations.toSourceSetDependent().toAnnotations(),
+ takeIf { isVar }?.let { IsVar }
)
}
)