Skip to content

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:

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

Represents an array of annotation values, such as arrayOf(1, 2) or [1, 2].

ClassLiteralValue

A class literal annotation value, such as String::class or Array<String>::class.

ConstantValue

A constant annotation value, such as 1 or "foo".

EnumEntryValue

An enum entry annotation value, such as Color.RED.

NestedAnnotationValue

Represents a nested annotation value, such as ReplaceWith("bar()") in @Deprecated("Use 'bar()' instead", ReplaceWith("bar()")).

UnsupportedValue

Represents an unsupported expression used as an annotation value.

Properties

sourcePsi

abstract val sourcePsi: KtElement?

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

isValid

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.