KaAnnotationValue¶
sealed interface KaAnnotationValue : KaLifetimeOwner
KaAnnotationValue represents the value of an annotation argument.
Annotation values must be compile-time constants. They are restricted in their allowed types, which are:
-
Integers,
Boolean, andString(ConstantValue) -
Enum types (
EnumEntryValue) -
Other annotation types (
NestedAnnotationValue) -
Arrays of aforementioned types (
ArrayValue)
Examples¶
@Foo1(5, true, "foo") // Constant values
@Foo2(Color.RED) // Enum entries
@Foo3(String::class) // `KClass` values
@Foo4(Foo2(Color.RED)) // Nested annotation values
@Foo5([Color.RED, Color.GREEN, Color.BLUE]) // Arrays
Inheritors¶
Types¶
ArrayValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface ArrayValue : KaAnnotationValue
Represents an array of annotation values, such as arrayOf(1, 2) or [1, 2].
ClassLiteralValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface ClassLiteralValue : KaAnnotationValue
A class literal annotation value, such as String::class or Array<String>::class.
ConstantValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface ConstantValue : KaAnnotationValue
A constant annotation value, such as 1 or "foo".
EnumEntryValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface EnumEntryValue : KaAnnotationValue
An enum entry annotation value, such as Color.RED.
NestedAnnotationValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface NestedAnnotationValue : KaAnnotationValue
Represents a nested annotation value, such as ReplaceWith("bar()") in @Deprecated("Use 'bar()' instead", ReplaceWith("bar()")).
UnsupportedValue¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface UnsupportedValue : KaAnnotationValue
Represents an unsupported expression used as an annotation value.
Properties¶
sourcePsi¶
The KtElement underlying the annotation value. This is only defined for annotations in source files. For libraries, it is always null.
token¶
abstract val token: KaLifetimeToken
The KaLifetimeToken which determines the lifetime of the lifetime owner.
Functions¶
assertIsValidAndAccessible¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
isValid¶
fun KaLifetimeOwner.isValid(): Boolean
Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.
renderAsSourceCode¶
Renders the annotation value as valid Kotlin source code.
withValidityAssertion¶
inline fun <R> KaLifetimeOwner.withValidityAssertion(action: () -> R): R
Executes action only if the KaLifetimeOwner is still valid and accessible. Otherwise, throws a validity exception based on the concrete violation.