Skip to content

KaAnnotation

KaAnnotation is an application of an annotation to a declaration, type, or as an argument of another annotation.

The annotation application may be unresolved, for example due to a type error. In such a case, properties like classId and constructorSymbol might be null. However, the annotation application's arguments are available independently of its resolvability.

Examples

// `@Deprecated` applied to a function declaration `foo1`.
@Deprecated("Should not be used")
fun foo1() {}

// `@A` applied to a type `Int`.
fun foo2(x: List<@A Int>) {}

// `B()` applied as an argument of another annotation `@A`.
@A(B())
fun foo3() {}

Properties

arguments

The list of annotation arguments passed to the annotation constructor in the form of KaNamedAnnotationValues.

classId

abstract val classId: ClassId?

The fully qualified annotation ClassId, or null if the annotation application is unresolved.

constructorSymbol

The KaConstructorSymbol of the annotation's constructor, or null if the annotation application is unresolved.

psi

abstract val psi: KtCallElement?

The KtCallElement which represents the application of the annotation to a declaration/type in PSI.

psi is present only for declarations from sources. For declarations from other places (libraries, stdlib), it is 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.

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.