Skip to content

KaConstantValue

sealed interface KaConstantValue

Represents a compile-time constant value. It can be used as a const val initializer or as an annotation argument.

KaConstantValue can also represent evaluated values. For example, the constant expression 1 + 2 can be represented as an IntValue with a value 3.

Inheritors

Types

BooleanValue

Represents a Boolean value.

ByteValue

Represents a Byte value.

CharValue

Represents a Char value.

DoubleValue

Represents a Double value.

ErrorValue

Represents either a non-constant value, or a constant evaluation error (such as a division by zero).

FloatValue

Represents a Float value.

IntValue

Represents an Int value.

LongValue

Represents a Long value.

NullValue

Represents a null value of some class type.

ShortValue

Represents a Short value.

StringValue

Represents a String value.

UByteValue

Represents a UByte value.

UIntValue

Represents a UInt value.

ULongValue

Represents a ULong value.

UShortValue

Represents a UShort value.

Properties

sourcePsi

abstract val sourcePsi: KtElement?

A source element from which the value was created. The PSI might be null for constants from non-source files.

value

abstract val value: Any?

The value of the constant. The type of value matches its represented class, e.g. BooleanValue.value is a Boolean.

For NullValue and ErrorValue, value contains a special value.

Functions

render

abstract fun render(): String

Renders the value as a representable constant value String, such as 1, 2f, 3u null, "text".