Skip to content

UserDataProperty

class UserDataProperty<in R : UserDataHolder, T : Any>(val key: Key<T>)

A property delegate that reads and writes a value stored in a UserDataHolder under the given key.

It lets user data — the platform's mechanism for attaching arbitrary values to a UserDataHolder such as a PSI element — be accessed as an ordinary, type-safe (nullable) Kotlin property.

Example:

private val KEY = Key.create<Boolean>("MY_FLAG")
var PsiElement.myFlag: Boolean? by UserDataProperty(KEY)

Type Parameters

  • R: the type of user-data holder this property applies to

  • T: the type of the stored value

Constructors

UserDataProperty

constructor(key: Key<T>)

Type Parameters

  • R: the type of user-data holder this property applies to

  • T: the type of the stored value

Properties

key

val key: Key<T>

Functions

getValue

operator fun getValue(thisRef: R, desc: KProperty<*>): @Nullable T?

Reads the value stored under key on thisRef, or null if none is set.

setValue

operator fun setValue(
    thisRef: R, 
    desc: KProperty<*>, 
    value: T?
)

Stores value under key on thisRef (or removes it when value is null).