KaType
Represents a Kotlin type. It serves as the base interface for various specific type.
Hierarchy
Inherits from KaAnnotated.
Members
val abbreviation: KaUsualClassType?The abbreviated type for the given expanded type, or
nullif this type has not been expanded, or the abbreviated type cannot be resolved.An abbreviated type is an expanded type alias application. For example, if we have a type alias
typealias MyString = Stringand its applicationMyString,Stringwould be the type alias expansion andMyStringits abbreviated type.val nullability: KaTypeNullabilityThe type nullability:
NULLABLE,NON_NULLABLE,UNKNOWN(for flexible types).
Subtypes
The KaType interface has several subtypes that represent different kinds of types in Kotlin:
KaClassType: Represents a Kotlin class type, encompassing classes, interfaces, objects, and enum classes.
KaUsualClassType: Represents a class type that is not a function type.
KaFunctionType: Represents Kotlin function types, including regular functions, suspend functions, and those with receivers.
KaTypeParameterType: Represents a type parameter type, such as
Tin the declarationclass Box<T>(val element: T).KaDefinitelyNotNullType: Represents a type that is known to be non-nullable at a particular point in the program.
KaCapturedType: Represents a type that is captured during type inference, often occurring when working with generics and variance.
KaFlexibleType: Represents a type with flexibility in its bounds, commonly used for platform types or types with uncertain nullability.
KaIntersectionType: Represents a type formed by the intersection of multiple types.
KaDynamicType: Represents the dynamic type in Kotlin, used for interoperability with dynamically-typed languages or platforms.
KaErrorType: Represents an unresolved type of some kind.
Transformation utilities
val Iterable<KaType>.commonSupertype: KaTypeThe common super type of the given collection of [KaType]. The collection must not be empty.
fun KaType.withNullability(newNullability: KaTypeNullability): KaTypeReturns the given type with the modified nullability.
Nullability utilities
val KaType.canBeNull: Booleantrueif a public value of the given type can potentially benull.This means this type is not a subtype of [Any]. However, it does not mean one can assign
nullto a variable of this type because it may be unknown if this type can acceptnull.val KaType.isMarkedNullable: Booleantrueif the given type is explicitly marked as nullable. This means it is safe to assignnullto a variable with this type.val KaType.hasFlexibleNullability: Booleantrueif the given type is a flexible (platform) type, can both safe and ordinary calls are valid on it.fun KaType.upperBoundIfFlexible(): KaTypeReturns the upper bound if the given type is a flexible type, and the given type itself otherwise.
fun KaType.lowerBoundIfFlexible(): KaTypeReturns the lower bound if the given type is a flexible type, and the given type itself otherwise.
Type relation utilities
fun KaType.semanticallyEquals(other: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): BooleanCheck semantic type equality. Returns
trueif the given type can be used instead ofother.fun KaType.isSubtypeOf(supertype: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): BooleanCheck if the given type is a subtype of the
supertype.fun KaType.isClassType(classId: ClassId): Booleantrueif the given type is a class type with the givenClassId, or its nullable version.fun KaType.hasCommonSubtypeWith(that: KaType): BooleanCheck whether the given type is compatible with the other type. Compatibility means the types can have a common subtype.
val KaType.directSupertypes: Sequence<KaType>Direct super types of the given type. For example, for
MutableList<String>it will beList<String>andMutableCollection<String>.val KaType.allSupertypes: Sequence<KaType>All supertypes of the given type.
val KaType.isArrayOrPrimitiveArray: Booleantrueif the given type is an array or a primitive array type.val KaType.isNestedArray: Booleantrueif the given type is an array or a primitive array type, and if its element is also an array type.val KaType.isPrimitive: Booleantrueif the given [KaType] is one of these types:Byte,Short,Int,Long,Float,Double,Char,Boolean, or a nullable version of them.val KaType.isAnyType
val KaType.isNothingType
val KaType.isUnitType
val KaType.isByteType
val KaType.isUByteType
val KaType.isShortType
val KaType.isUShortType
val KaType.isIntType
val KaType.isUIntType
val KaType.isLongType
val KaType.isULongType
val KaType.isFloatType
val KaType.isDoubleType
val KaType.isCharType
val KaType.isBooleanType
val KaType.isCharSequenceType
val KaType.isStringTypetrueif the given type is the specified Kotlin type or its nullable version.val KaType.isFunctionalInterface: Booleantrueif the given type is a functional interface type (SAM type), e.g.,Runnable.val KaType.isFunctionType: Booleantrueif this type is akotlin.Functiontype.val KaType.isKFunctionType: Booleantrueif this type is akotlin.reflect.KFunctiontype.val KaType.isSuspendFunctionType: Booleantrueif this type is akotlin.coroutines.SuspendFunctiontype.val KaType.isKSuspendFunctionType: Booleantrueif this type is akotlin.reflect.KSuspendFunctiontype.val KaType.functionTypeKind: FunctionTypeKind?The
FunctionTypeKindof the given type, ornullif the type is not a function type.Experimental API.
Scope utilities
val KaType.scope: KaTypeScope?Return a
KaTypeScopefor a given type. The type scope includes all members which are declared and callable on a given type.Comparing to a
KaScope, in theKaTypeScopeall use-site type parameters are substituted.Experimental API.
val KaType.syntheticJavaPropertiesScope: KaTypeScope?A
KaTypeScopewith synthetic Java properties created for a given type.
Other utilities
val builtinTypes: KaBuiltinTypesAn instance providing access to all built-in Kotlin types, including number types,
Any,Nothing,Stringand others.val KaType.arrayElementType: KaType?The array element type for a primitive type array or
Array,nullotherwise.val KaType.expandedSymbol: KaClassSymbol?The class symbol backing the given type, or
nullif the type has no expansion.val KaType.fullyExpandedType: KaTypeThe type with type aliases recursively expanded.
val KaType.isDenotable: Booleantrueif this type is denotable. In other words, it can be written in Kotlin by a developer. Flexible type is an example of a non-denotable type.val KaType.enhancedType: KaType?The warning-level enhanced type for the given type, or
nullif it is absent.Experimental API.
val KaType.enhancedTypeOrSelf: KaType?The warning-level enhanced type for the given type, or the given type itself if it is absent.
Experimental API.
fun KaType.render(renderer: KaTypeRenderer = KaTypeRendererForSource.WITH_QUALIFIED_NAMES, position: Variance): StringRender the given type to a
String. The particular rendering strategy is defined by therenderer.Experimental API.