KaTypeProvider¶
@SubclassOptInRequired(markerClass = [KaSessionComponentImplementationDetail::class])
interface KaTypeProvider : KaSessionComponent
Inheritors¶
Properties¶
allSupertypes¶
abstract fun KaType.allSupertypes(shouldApproximate: Boolean): Sequence<KaType>
Returns all supertypes of the given KaType. The resulting sequence is ordered by a breadth-first traversal of the class hierarchy, without duplicates.
Parameters
- shouldApproximate: Whether to approximate
non-denotabletypes. SeedirectSupertypesfor more information.
open val KaType.allSupertypes: Sequence<KaType>
arrayElementType¶
abstract val KaType.arrayElementType: KaType?
augmentedByWarningLevelAnnotations¶
abstract val KaType.augmentedByWarningLevelAnnotations: KaType
A KaType derived from the given type by enforcing warning-level nullability annotations. If the derived type doesn't differ from the original type, the original type is used.
In general, Java type enhancement allows the Kotlin compiler to infer a more specific nullability for a Java type based on its nullability annotations. Normally, only strict nullability annotations have an impact on a resolved type's nullability. These annotations are already taken into account in KaType.
However, there are also warning-level nullability annotations, such as Android's RecentlyNullable and RecentlyNonNull. These annotations have weaker constraints and don't affect a resolved type's nullability. augmentedByWarningLevelAnnotations is a KaType with weak annotations treated as strict ones.
See the list of default report levels for different nullability annotations in NULLABILITY_ANNOTATION_SETTINGS
Examples
-
For
@androidx.annotation.RecentlyNullable X!augmentedByWarningLevelAnnotationsisX?. -
For
@androidx.annotation.RecentlyNonNull X!augmentedByWarningLevelAnnotationsisX.
builtinTypes¶
abstract val builtinTypes: KaBuiltinTypes
KaType instances for built-in types.
commonSupertype¶
abstract val Iterable<KaType>.commonSupertype: KaType
The common supertype of the given KaTypes.
Throws
IllegalArgumentException-
If the collection of types is empty.
open val Array<KaType>.commonSupertype: KaType
The common supertype of the given KaTypes.
Throws
IllegalArgumentException-
If the array of types is empty.
defaultType¶
abstract val KaClassifierSymbol.defaultType: KaType
defaultTypeWithStarProjections¶
abstract val KaClassifierSymbol.defaultTypeWithStarProjections: KaType
The representation of this in terms of KaType.
Type parameters are substituted with KaStarTypeProjection, e.g. List<*> for the List class.
See also
directSupertypes¶
abstract fun KaType.directSupertypes(shouldApproximate: Boolean): Sequence<KaType>
Returns the direct supertypes of the given KaType.
For flexible types, direct supertypes of both the upper and lower bounds are returned. If that's not desirable, use directSupertypes on KaFlexibleType.upperBound or KaFlexibleType.lowerBound.
Example
Given MutableList<String>, directSupertypes returns List<String> and MutableCollection<String>
Parameters
- shouldApproximate: Whether to approximate
non-denotabletypes. For example, the supertype ofList<out String>isCollection<CAPTURED out String>. With approximation set totrue,Collection<out String>is returned instead.
open val KaType.directSupertypes: Sequence<KaType>
The direct supertypes of the given KaType.
For flexible types, direct supertypes of both the upper and lower bounds are included. If that's not desirable, use directSupertypes on KaFlexibleType.upperBound or KaFlexibleType.lowerBound.
Denotable types are not approximated.
Example
Given MutableList<String>, directSupertypes contains List<String> and MutableCollection<String>
receiverType¶
abstract val KtDoubleColonExpression.receiverType: KaType?
Resolves the given KtDoubleColonExpression to the KaType of its receiver.
The result may be null if the resolution fails or the resolved callable reference is not a reflection type.
Example
Here, receiverType for foo::bar is Foo (the type of foo).
token¶
abstract val token: KaLifetimeToken
The KaLifetimeToken which determines the lifetime of the lifetime owner.
type¶
abstract val KtTypeReference.type: KaType
Resolves the given KtTypeReference to its corresponding KaType.
This may raise an exception if the resolution ends up with an unexpected result.
varargArrayType¶
abstract val KaValueParameterSymbol.varargArrayType: KaType?
The array type that represents the list of arguments passed to this parameter if this is a vararg parameter.
If this is not a vararg parameter, varargArrayType is null. If this is an invalid (e.g., in case of multiple vararg parameters) or useless (in anonymous functions) vararg parameter, varargArrayType still contains a type for it.
Functions¶
approximateToDenotableSubtype¶
abstract fun KaType.approximateToDenotableSubtype(): KaType?
approximateToDenotableSubtypeOrSelf¶
open fun KaType.approximateToDenotableSubtypeOrSelf(): KaType
approximateToDenotableSupertype¶
abstract fun KaType.approximateToDenotableSupertype(allowLocalDenotableTypes: Boolean): KaType?
Approximates KaType to a denotable supertype.
The function returns null if the type is already denotable and does not need approximation. Otherwise, for a type T, returns a denotable type S such that T <: S, with all type arguments of S also being denotable.
Parameters
- allowLocalDenotableTypes: Whether locally declared types should be approximated to local supertypes instead of non-local ones. Local type approximation is sensible when the resulting
KaTypeis analyzed in the same local context.
abstract fun KaType.approximateToDenotableSupertype(position: KtElement): KaType?
Approximates KaType to a denotable supertype based on the given position.
This position is used when approximating local types. If the given type is local, then the function returns the first supertype, which is visible from the given position. Note that position is required to be within KaAnalysisScopeProvider.analysisScope, otherwise, an exception is thrown.
The function returns null if the type is already denotable and does not need approximation. Otherwise, for a type T, returns a denotable type S such that T <: S, with all type arguments of S also being denotable.
Example:
In the example above we are trying to approximate the type of object: A() {} expression, which is a local type <anonymous>: A. When this type is approximated using <position_2> the function returns A, as this type is visible from this position. However, when approximating from <position_1>, the function returns Any, as A is not visible from this position, so the only option left is Any.
approximateToDenotableSupertypeOrSelf¶
open fun KaType.approximateToDenotableSupertypeOrSelf(allowLocalDenotableTypes: Boolean): KaType
open fun KaType.approximateToDenotableSupertypeOrSelf(position: KtElement): KaType
assertIsValidAndAccessible¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
hasCommonSubtypeWith¶
abstract fun KaType.hasCommonSubtypeWith(that: KaType): Boolean
isValid¶
fun KaLifetimeOwner.isValid(): Boolean
Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.
lowerBoundIfFlexible¶
open fun KaType.lowerBoundIfFlexible(): KaType
Returns the KaFlexibleType's lower bound, or the type itself if it is not flexible.
upperBoundIfFlexible¶
open fun KaType.upperBoundIfFlexible(): KaType
Returns the KaFlexibleType's upper bound, or the type itself if it is not flexible.
withNullability¶
abstract fun KaType.withNullability(isMarkedNullable: Boolean): KaType
Creates a new KaType based on the given type with the updated nullability specified by isMarkedNullable.
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.