Analysis API: introduce annotation value for KClass
This commit is contained in:
+17
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.api.annotations
|
||||
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,22 @@ public class KtAnnotationApplicationValue(
|
||||
}
|
||||
|
||||
|
||||
public sealed class KtKClassAnnotationValue : KtAnnotationValue()
|
||||
|
||||
public class KtNonLocalKClassAnnotationValue(
|
||||
public val classId: ClassId,
|
||||
override val sourcePsi: KtElement?,
|
||||
) : KtKClassAnnotationValue()
|
||||
|
||||
public class KtLocalKClassAnnotationValue(
|
||||
public val ktClass: KtClassOrObject,
|
||||
override val sourcePsi: KtElement?,
|
||||
) : KtKClassAnnotationValue()
|
||||
|
||||
public class KtErrorClassAnnotationValue(
|
||||
override val sourcePsi: KtElement?,
|
||||
) : KtKClassAnnotationValue()
|
||||
|
||||
public class KtEnumEntryAnnotationValue(
|
||||
public val callableId: CallableId?,
|
||||
override val sourcePsi: KtElement?,
|
||||
|
||||
+15
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.annotations
|
||||
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
|
||||
public object KtAnnotationValueRenderer {
|
||||
public fun render(value: KtAnnotationValue): String = buildString {
|
||||
renderConstantValue(value)
|
||||
@@ -25,11 +27,23 @@ public object KtAnnotationValueRenderer {
|
||||
renderConstantAnnotationValue(value)
|
||||
}
|
||||
KtUnsupportedAnnotationValue -> {
|
||||
append("KtUnsupportedConstantValue")
|
||||
append("error(\"non-annotation value\")")
|
||||
}
|
||||
is KtKClassAnnotationValue -> {
|
||||
renderKClassAnnotationValue(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.renderKClassAnnotationValue(value: KtKClassAnnotationValue) {
|
||||
when (value) {
|
||||
is KtErrorClassAnnotationValue -> append("UNRESOLVED_CLASS")
|
||||
is KtLocalKClassAnnotationValue -> append(value.ktClass.nameAsName?.render())
|
||||
is KtNonLocalKClassAnnotationValue -> append(value.classId.asSingleFqName().render())
|
||||
}
|
||||
append("::class")
|
||||
}
|
||||
|
||||
private fun StringBuilder.renderConstantAnnotationValue(value: KtConstantAnnotationValue) {
|
||||
append(KtConstantValueRenderer.render(value.constantValue))
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtClass Foo
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtNamedFunction foo
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtProperty foo
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtTypeAlias Foo
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtPropertyAccessor null
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtParameter bar
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtProperty foo
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
KtDeclaration: KtPropertyAccessor null
|
||||
annotations: [
|
||||
A(a = 1, c = KtUnsupportedConstantValue)
|
||||
A(a = 1, c = kotlin.Int::class)
|
||||
psi: KtAnnotationEntry
|
||||
]
|
||||
|
||||
analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/propertyInit_UInt.txt
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
expression: 42u
|
||||
constant: 42
|
||||
constantValueKind: Long
|
||||
constantValueKind: UInt
|
||||
|
||||
Reference in New Issue
Block a user