aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/translators
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-08-03 15:07:57 +0200
committerGitHub <noreply@github.com>2022-08-03 15:07:57 +0200
commit256740ae75f30be7bd4f326b380f8ef2efd5d53c (patch)
tree953b061ca787e17f5274c227e4f65b8f97cc3efc /plugins/base/src/main/kotlin/translators
parent3994c42f2f2366d2e551e62412518a210581cb3a (diff)
downloaddokka-256740ae75f30be7bd4f326b380f8ef2efd5d53c.tar.gz
dokka-256740ae75f30be7bd4f326b380f8ef2efd5d53c.tar.bz2
dokka-256740ae75f30be7bd4f326b380f8ef2efd5d53c.zip
Fix parsing of static imports in java annotation params (#2593)
Fixes #2580
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt20
1 files changed, 17 insertions, 3 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index 3c1a2cc7..03e0b9ef 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.base.translators.psi
import com.intellij.lang.jvm.JvmModifier
import com.intellij.lang.jvm.annotation.JvmAnnotationAttribute
import com.intellij.lang.jvm.annotation.JvmAnnotationAttributeValue
+import com.intellij.lang.jvm.annotation.JvmAnnotationConstantValue
import com.intellij.lang.jvm.annotation.JvmAnnotationEnumFieldValue
import com.intellij.lang.jvm.types.JvmReferenceType
import com.intellij.openapi.vfs.VirtualFileManager
@@ -682,9 +683,22 @@ class DefaultPsiToDocumentableTranslator(
* This is a workaround for static imports from JDK like RetentionPolicy
* For some reason they are not represented in the same way than using normal import
*/
- private fun JvmAnnotationAttributeValue.toValue(): AnnotationParameterValue? = when (this) {
- is JvmAnnotationEnumFieldValue -> (field as? PsiElement)?.let { EnumValue(fieldName ?: "", DRI.from(it)) }
- else -> null
+ private fun JvmAnnotationAttributeValue.toValue(): AnnotationParameterValue? {
+ return when (this) {
+ is JvmAnnotationEnumFieldValue -> (field as? PsiElement)?.let { EnumValue(fieldName ?: "", DRI.from(it)) }
+ // static import of a constant is resolved to constant value instead of a field/link
+ is JvmAnnotationConstantValue -> this.constantValue?.toAnnotationLiteralValue()
+ else -> null
+ }
+ }
+
+ private fun Any.toAnnotationLiteralValue() = when (this) {
+ is Int -> IntValue(this)
+ is Long -> LongValue(this)
+ is Boolean -> BooleanValue(this)
+ is Float -> FloatValue(this)
+ is Double -> DoubleValue(this)
+ else -> StringValue(this.toString())
}
private fun PsiAnnotationMemberValue.toValue(): AnnotationParameterValue? = when (this) {