Skip to content

KaTypeInformationProvider

@SubclassOptInRequired(markerClass = [KaSessionComponentImplementationDetail::class])
interface KaTypeInformationProvider : KaSessionComponent

Inheritors

Properties

builtinFunctionTypeFamilies

defaultInitializer

The default initializer for the given KaType, or null if the type is neither nullable, a primitive, nor a string.

expandedSymbol

The class symbol backing the given KaType, if available.

fullyExpandedType

The type that corresponds to the given KaType with fully expanded type aliases.

Type aliases are usually expanded immediately by the compiler, so most KaTypes should already present in their expanded forms. Nonetheless, it is possible to obtain unexpanded types from the Analysis API, and fullyExpandedType may be used to expand type aliases in such types.

Example

interface Base

typealias FirstAlias = @Anno1 Base
typealias SecondAlias = @Anno2 FirstAlias

fun foo(): @Anno3 SecondAlias = TODO()

The return type of foo() will be @Anno3 @Anno2 @Anno1 Base instead of @Anno3 SecondAlias

See also

functionTypeFamily

The function type family of the given KaType, or null if the type is not a function type.

For example, (Int) -> String belongs to the Function family, while suspend () -> Unit belongs to the SuspendFunction family.

See also

hasFlexibleNullability

Whether the KaType is a org.jetbrains.kotlin.analysis.api.types.KaFlexibleType / org.jetbrains.kotlin.analysis.api.types.KaDynamicType with flexible nullability or org.jetbrains.kotlin.analysis.api.types.KaErrorType with unknown nullability. Both safe and ordinary calls are valid on such types.

Note that a flexible / dynamic type has a flexible nullability when the lower bound is non-nullable and the upper bound is nullable. E.g. T! has T as the lower bound and T? as the upper bound, hence it has a flexible nullability.

isAnyType

abstract val KaType.isAnyType: Boolean

Whether the KaType is an Any type.

isArrayOrPrimitiveArray

Whether the KaType is an array or a primitive array type.

isBooleanType

abstract val KaType.isBooleanType: Boolean

Whether the KaType is a Boolean type.

isByteType

abstract val KaType.isByteType: Boolean

Whether the KaType is a Byte type.

isCharSequenceType

Whether the KaType is a CharSequence type.

isCharType

abstract val KaType.isCharType: Boolean

Whether the KaType is a Char type.

isDenotable

abstract val KaType.isDenotable: Boolean

Whether the KaType is denotable. A denotable type can be expressed in Kotlin code, as opposed to being only constructible via compiler type operations (such as type inference).

isDoubleType

abstract val KaType.isDoubleType: Boolean

Whether the KaType is a Double type.

isFloatType

abstract val KaType.isFloatType: Boolean

Whether the KaType is a Float type.

isFunctionalInterface

Whether the KaType is a functional interface type, such as Runnable. Such types are also known as SAM types.

isFunctionType

abstract val KaType.isFunctionType: Boolean

Whether the KaType is a kotlin.Function type.

isIntType

abstract val KaType.isIntType: Boolean

Whether the KaType is an Int type.

isKFunctionType

Whether the KaType is a kotlin.reflect.KFunction type.

isKSuspendFunctionType

Whether the KaType is a KSuspendFunction type.

isLongType

abstract val KaType.isLongType: Boolean

Whether the KaType is a Long type.

isMarkedNullable

Whether the KaType is explicitly marked as nullable, i.e., is represented as T?.

Note that this property just reflects the presence of nullability in the type signature, and sometimes isMarkedNullable being false doesn't imply that the given type cannot hold null or be assigned with it.

For example, isMarkedNullable doesn't expand type aliases to check the nullability of their underlying type:

typealias NonMarkedNullableAlias = String?

fun main() {
    val x: NonMarkedNullableAlias = null
}

The type of x is NonMarkedNullableAlias, which is not marked as nullable. However, it still represents a nullable type and can hold null and can be assigned with that.

To explicitly check whether a type can potentially hold null, use isNullable.

isNestedArray

abstract val KaType.isNestedArray: Boolean

Whether the KaType is an array or a primitive array type, and its element is also an array type.

isNothingType

abstract val KaType.isNothingType: Boolean

Whether the KaType is a Nothing type.

isNullable

abstract val KaType.isNullable: Boolean

Whether a public value of the KaType can potentially be null.

If a type can be null, it means that this type is not a subtype of Any. However, it does not mean one can assign null to a variable of this type. It may be unknown whether this type can accept null.

Example

A public value of type T : Any? can potentially be null. But one cannot assign null to such a variable because the instantiated type may not be nullable.

isPrimitive

abstract val KaType.isPrimitive: Boolean

Whether the KaType is a primitive type.

isShortType

abstract val KaType.isShortType: Boolean

Whether the KaType is a Short type.

isStringType

abstract val KaType.isStringType: Boolean

Whether the KaType is a String type.

isSuspendFunctionType

Whether the KaType is a suspend function type.

isUByteType

abstract val KaType.isUByteType: Boolean

Whether the KaType is a UByte type.

isUIntType

abstract val KaType.isUIntType: Boolean

Whether the KaType is a UInt type.

isULongType

abstract val KaType.isULongType: Boolean

Whether the KaType is a ULong type.

isUnitType

abstract val KaType.isUnitType: Boolean

Whether the KaType is a Unit type.

isUShortType

abstract val KaType.isUShortType: Boolean

Whether the KaType is a UShort type.

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.