aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-08-17 14:35:31 +0200
committerGitHub <noreply@github.com>2022-08-17 14:35:31 +0200
commitd755694746b877b0051b886e4ac05bd428bee429 (patch)
treea411c896ce741165faf4ee0f943b950f86c6d252 /plugins/base/src/main
parenta7c3113b2249a0fa1631dbc0e4bb85d75a12b25a (diff)
downloaddokka-d755694746b877b0051b886e4ac05bd428bee429.tar.gz
dokka-d755694746b877b0051b886e4ac05bd428bee429.tar.bz2
dokka-d755694746b877b0051b886e4ac05bd428bee429.zip
Display values of java constants (#2609)
Fixes #2524
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt17
1 files changed, 17 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index 03e0b9ef..a58e1b83 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -658,6 +658,7 @@ class DefaultPsiToDocumentableTranslator(
inheritedFrom?.let { inheritedFrom -> InheritedMember(inheritedFrom.toSourceSetDependent()) },
it.toSourceSetDependent().toAdditionalModifiers(),
annotations.toSourceSetDependent().toAnnotations(),
+ psi.getConstantExpression()?.let { DefaultValue(it.toSourceSetDependent()) },
takeIf { isVar }?.let { IsVar }
)
}
@@ -671,6 +672,22 @@ class DefaultPsiToDocumentableTranslator(
private fun Collection<PsiAnnotation>.toListOfAnnotations() =
filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.toAnnotation() }
+ private fun PsiField.getConstantExpression(): Expression? {
+ val constantValue = this.computeConstantValue() ?: return null
+ return when (constantValue) {
+ is Byte -> IntegerConstant(constantValue.toLong())
+ is Short -> IntegerConstant(constantValue.toLong())
+ is Int -> IntegerConstant(constantValue.toLong())
+ is Long -> IntegerConstant(constantValue)
+ is Char -> StringConstant(constantValue.toString())
+ is String -> StringConstant(constantValue)
+ is Double -> DoubleConstant(constantValue)
+ is Float -> FloatConstant(constantValue)
+ is Boolean -> BooleanConstant(constantValue)
+ else -> ComplexExpression(constantValue.toString())
+ }
+ }
+
private fun JvmAnnotationAttribute.toValue(): AnnotationParameterValue = when (this) {
is PsiNameValuePair -> value?.toValue() ?: attributeValue?.toValue() ?: StringValue("")
else -> StringValue(this.attributeName)