KaSession¶
@SubclassOptInRequired(markerClass = [KaImplementationDetail::class])
interface KaSession : KaLifetimeOwner, KaResolver, KaSymbolRelationProvider, KaDiagnosticProvider, KaScopeProvider, KaCompletionCandidateChecker, KaExpressionTypeProvider, KaTypeProvider, KaTypeInformationProvider, KaSymbolProvider, KaJavaInteroperabilityComponent, KaSymbolInformationProvider, KaTypeRelationChecker, KaExpressionInformationProvider, KaEvaluator, KaReferenceShortener, KaRenderer, KaVisibilityChecker, KaTypeCreator, KaTypeCreatorProvider, KaAnalysisScopeProvider, KaSignatureSubstitutor, KaResolveExtensionInfoProvider, KaCompilerPluginGeneratedDeclarationsProvider, KaCompilerFacility, KaSubstitutorProvider, KaDataFlowProvider, KaSourceProvider, KaKDocProvider
KaSession, also called an analysis session, is the entry point to all frontend-related work. It has the following contracts:
-
It should not be accessed outside a read action.
-
It should only be accessed in restricted analysis mode (see
KotlinRestrictedAnalysisServicein the platform interface) when restricted analysis is allowed by the Analysis API platform. -
It should not be accessed from the event dispatch thread (EDT) or a write action unless explicitly allowed (
allowAnalysisOnEdt,allowAnalysisFromWriteAction). -
It should not be leaked outside the
analyzecall it was created in. To ensure that an analysis session isn't leaked, there are additional conventions, explained further below. -
All
lifetime ownerss retrieved from an analysis session should not be leaked outside theanalyzecall that spawned the analysis session.
To pass a lifetime owner from one analyze call to another, use a pointer:
-
KaSymbolProviderforKaSymbols usingKaSymbol.createPointer. -
KaTypePointerforKaTypes usingKaType.createPointer.
To create a KaSession, please use analyze or one of its siblings.
Conventions to avoid leakage¶
It is crucial to avoid leaking the analysis session outside the read action it was created in, as the analysis session itself and all lifetime owners retrieved from it will become invalid. An analysis session also shouldn't be leaked from the analyze call it was created in.
It is forbidden to store an analysis session in a variable, parameter, or property. From the analyze block which provides the analysis session, the analysis session should be passed to functions via an context parameter. For example:
PsiElement as input¶
Some API components accept PsiElements as input. For example, KaSymbolProvider.symbol takes a KtDeclaration and returns a KaDeclarationSymbol for it.
In this case, the symbol may be created only for elements which are a part of the current KaSession. And it means that KaAnalysisScopeProvider.canBeAnalysed is true for such elements.
If this condition is not met, an exception will be thrown to prevent undefined behavior.
Nested analysis¶
While analyze calls can be nested, it is currently not recommended to use lifetime owners from the outer analysis context in the inner analysis context. This section illustrates the reasons behind this recommendation.
As there is one analysis session per use-site module, in the best case, the analyzed element will be from the same module. Then the nested analyze call will simply perform the analysis in the same analysis session context. As such, it would be possible to use a symbol from the outer analysis context in the inner analyze call. But if it's the same use-site module, it's better to pass the analysis session down the call chain directly, instead of calling analyze again. In addition, relying on two elements having the same use-site module is an open invitation for bugs.
In more problematic cases, nested analysis may lead to various issues. First of all, a KaLifetimeOwner can usually only be accessed in the session where it was created. Nesting analyze and starting analysis from a different use-site module will effectively change the current KaSession context. Any calls to symbols created in other sessions will result in an exception (unless the Analysis API platform defines different accessibility rules, such as the Standalone Analysis API).
Furthermore, even if such an access exception wasn't thrown, it is conceptually problematic to access a symbol in a different use-site context. Symbols are always viewed from a specific use-site context. It is unclear whether the symbol would even exist in the other use-site context. And even if the symbol is accessible, analyzing it may lead to different results due to differences in the use site's dependencies. For example, the supertypes of a class symbol may resolve to different declaration symbols.
In summary, using lifetime owners from an outer context in a nested analyze block will likely lead to an access exception given the accessibility rules of lifetime owners. And even if this wasn't the case, there's a conceptual problem with using a lifetime owner in the wrong session, as lifetime owners such as symbols are always viewed from a specific use-site context.
Example¶
Properties¶
allOverriddenSymbols¶
abstract val KaCallableSymbol.allOverriddenSymbols: Sequence<KaCallableSymbol>
All explicitly declared (non-fake) callable symbols overridden by this callable symbol.
allSupertypes¶
open val KaType.allSupertypes: Sequence<KaType>
All supertypes of the given KaType. The resulting sequence is ordered by a breadth-first traversal of the class hierarchy, without duplicates.
analysisScope¶
abstract val analysisScope: GlobalSearchScope
A GlobalSearchScope which spans the files that can be analyzed by the current KaSession.
applicableAnnotationTargets¶
abstract val KaClassSymbol.applicableAnnotationTargets: Set<KaAnnotationTarget>?
A set of applicable targets for an annotation class symbol, or null if the symbol is not an annotation class.
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.
builtinFunctionTypeFamilies¶
abstract val builtinFunctionTypeFamilies: KaBuiltinFunctionTypeFamilies
Provides access to the built-in function type families.
builtinTypes¶
abstract val builtinTypes: KaBuiltinTypes
KaType instances for built-in types.
callableSymbol¶
abstract val PsiMember.callableSymbol: KaCallableSymbol?
A KaCallableSymbol for the given PsiMember method or field, or null for local declarations and Kotlin light classes.
canBeOperator¶
abstract val KaNamedFunctionSymbol.canBeOperator: Boolean
Whether the function symbol meets all the requirements to be declared as an operator function.
classSymbol¶
abstract val KtClassOrObject.classSymbol: KaClassSymbol?
A KaClassSymbol for the given KtClassOrObject, or null for KtEnumEntry declarations.
combinedDeclaredMemberScope¶
abstract val KaDeclarationContainerSymbol.combinedDeclaredMemberScope: KaScope
A KaScope containing all members explicitly declared in the given KaDeclarationContainerSymbol.
combinedMemberScope¶
A KaScope containing all members from memberScope and staticMemberScope.
commonSupertype¶
open val Array<KaType>.commonSupertype: KaType
The common supertype of the given KaTypes.
abstract val Iterable<KaType>.commonSupertype: KaType
The common supertype of the given KaTypes.
compilerPluginGeneratedDeclarations¶
Declarations generated by compiler plugins for this module, not including the generated declarations for dependencies of this module.
containingDeclaration¶
abstract val KaSymbol.containingDeclaration: KaDeclarationSymbol?
The KaDeclarationSymbol which contains this symbol, or null if there is no containing declaration:
containingFile¶
abstract val KaSymbol.containingFile: KaFileSymbol?
The KaFileSymbol which contains this symbol, or null if this symbol is already a KaFileSymbol, since it has no containing file. Also null for Java and library declarations.
containingFileAnnotations¶
abstract val KaDeclarationSymbol.containingFileAnnotations: KaAnnotationList?
File-level annotations (@file:SomeAnnotation) of the source file this top-level KaDeclarationSymbol was defined in, or null for a nested declaration.
containingJvmClassName¶
abstract val KaCallableSymbol.containingJvmClassName: String?
The containing JVM class name for the given KaCallableSymbol.
containingModule¶
abstract val KaSymbol.containingModule: KaModule
The KaModule which contains this symbol.
containingSymbol¶
abstract val KaSymbol.containingSymbol: KaSymbol?
The KaSymbol which contains this symbol, or null if there is no containing declaration:
contextSensitiveResolutionStatus¶
The context-sensitive resolution status of the KtSimpleNameExpression: whether the name is already resolved through context-sensitive resolution, and whether a redundant explicit qualifier or import could be removed in favor of it.
declarationScope¶
abstract val KaTypeScope.declarationScope: KaScope
declaredMemberScope¶
abstract val KaDeclarationContainerSymbol.declaredMemberScope: KaScope
A KaScope containing the non-static callables (functions, properties, and constructors) and inner classes explicitly declared in the given KaDeclarationContainerSymbol.
defaultAnnotationTargets¶
abstract val KaSymbol.defaultAnnotationTargets: Set<KaAnnotationTarget>?
A set of annotation targets matching for the given symbol, or null if the symbol cannot be annotated. Annotations with one of targets from the returned set can be placed on the KaSymbol without an explicit use-site target.
defaultInitializer¶
abstract val KaType.defaultInitializer: String?
The default initializer for the given KaType, or null if the type is neither nullable, a primitive, nor a string.
defaultType¶
abstract val KaClassifierSymbol.defaultType: KaType
defaultTypeWithStarProjections¶
abstract val KaClassifierSymbol.defaultTypeWithStarProjections: KaType
delegatedMemberScope¶
abstract val KaDeclarationContainerSymbol.delegatedMemberScope: KaScope
A KaScope containing synthetic callables (functions and properties) created by interface delegation.
deprecation¶
abstract val KaSymbol.deprecation: KaDeprecation?
The deprecation status of the given symbol, or null if the symbol is not deprecated.
directlyOverriddenSymbols¶
abstract val KaCallableSymbol.directlyOverriddenSymbols: Sequence<KaCallableSymbol>
Explicitly declared (non-fake) callable symbols that are directly overridden by this callable symbol.
directSupertypes¶
open val KaType.directSupertypes: Sequence<KaType>
The direct supertypes of the given KaType.
expandedSymbol¶
abstract val KaType.expandedSymbol: KaClassSymbol?
The class symbol backing the given KaType, if available.
expectedType¶
abstract val PsiElement.expectedType: KaType?
The expected KaType for the given PsiElement if it is an expression, or null if the element does not have an expected type. The expected type represents the type that is expected for an expression at a specific location in the code.
expressionType¶
abstract val KtExpression.expressionType: KaType?
The type of the given KtExpression, or null if it does not have a type.
fakeOverrideOriginal¶
abstract val KaCallableSymbol.fakeOverrideOriginal: KaCallableSymbol
The original declared symbol for this callable symbol, after unwrapping fake override KaCallableSymbols if needed.
fileScope¶
abstract val KaFileSymbol.fileScope: KaScope
A KaScope containing the top-level declarations (such as classes, functions and properties) in the given KaFileSymbol.
fullyExpandedType¶
abstract val KaType.fullyExpandedType: KaType
The type that corresponds to the given KaType with fully expanded type aliases.
functionalInterface¶
abstract val KaSamConstructorSymbol.functionalInterface: KaClassLikeSymbol
The KaClassLikeSymbol of the corresponding functional (SAM) interface.
functionalInterfaceFunction¶
abstract val KaClassLikeSymbol.functionalInterfaceFunction: KaNamedFunctionSymbol?
The single abstract function of a functional interface, or null if this class is not a functional interface.
The single abstract function of the functional interface that this SAM constructor creates.
functionType¶
abstract val KtFunction.functionType: KaType
The function type of the given KtFunction.
functionTypeFamily¶
abstract val KaType.functionTypeFamily: KaFunctionTypeFamily?
The function type family of the given KaType, or null if the type is not a function type.
hasFlexibleNullability¶
abstract val KaType.hasFlexibleNullability: Boolean
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.
implicitReceiverSmartCasts¶
The list of implicit receiver smart casts which have refined the expression's implicit receivers to a more specific type. These smart casts are required for the expression to be evaluated. The list does not include smart casts for explicit receivers.
importableFqName¶
abstract val KaSymbol.importableFqName: FqName?
A FqName which can be used to import the given symbol, or null if the symbol cannot be imported.
importingScopeContext¶
abstract val KtFile.importingScopeContext: KaScopeContext
A KaScopeContext formed from all imports in the KtFile.
intersectionOverriddenSymbols¶
abstract val KaCallableSymbol.intersectionOverriddenSymbols: List<KaCallableSymbol>
All callable symbols overridden by this callable symbol if it is an intersection override, or an empty list otherwise.
isAnyType¶
isArrayOrPrimitiveArray¶
abstract val KaType.isArrayOrPrimitiveArray: Boolean
Whether the KaType is an array or a primitive array type.
isBooleanType¶
abstract val KaType.isBooleanType: Boolean
isByteType¶
abstract val KaType.isByteType: Boolean
isCharSequenceType¶
abstract val KaType.isCharSequenceType: Boolean
Whether the KaType is a CharSequence type.
isCharType¶
abstract val KaType.isCharType: Boolean
isDefinitelyNotNull¶
abstract val KtExpression.isDefinitelyNotNull: Boolean
Whether this expression is definitely not null.
isDefinitelyNull¶
abstract val KtExpression.isDefinitelyNull: Boolean
Whether this expression is definitely null, based on the declared nullability and smart cast types derived from data-flow analysis facts.
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).
isDeprecated¶
abstract val KaSymbol.isDeprecated: Boolean
Whether the symbol is deprecated at any level.
isDoubleType¶
abstract val KaType.isDoubleType: Boolean
isFloatType¶
abstract val KaType.isFloatType: Boolean
isFromResolveExtension¶
abstract val KtElement.isFromResolveExtension: Boolean
Whether the given KtElement is provided by a KaResolveExtension.
isFunctionalInterface¶
abstract val KaType.isFunctionalInterface: Boolean
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.
isImplicitReferenceToCompanion¶
abstract val KtSimpleNameExpression.isImplicitReferenceToCompanion: Boolean
Checks if the KtSimpleNameExpression is an implicit reference to a companion object via the containing class.
isInline¶
abstract val KaKotlinPropertySymbol.isInline: Boolean
Whether the property is an inline property. A property is considered inline when both of its accessors are inline or when it has the inline keyword. The inline keyword on a property is syntactic sugar for marking both accessors as inline.
isIntType¶
isKFunctionType¶
abstract val KaType.isKFunctionType: Boolean
Whether the KaType is a kotlin.reflect.KFunction type.
isKSuspendFunctionType¶
abstract val KaType.isKSuspendFunctionType: Boolean
Whether the KaType is a KSuspendFunction type.
isLongType¶
abstract val KaType.isLongType: Boolean
isMarkedNullable¶
abstract val KaType.isMarkedNullable: Boolean
Whether the KaType is explicitly marked as nullable, i.e., is represented as T?.
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
isNullable¶
abstract val KaType.isNullable: Boolean
Whether a public value of the KaType can potentially be null.
isPrimitive¶
abstract val KaType.isPrimitive: Boolean
Whether the KaType is a primitive type.
isPrimitiveBacked¶
abstract val KaType.isPrimitiveBacked: Boolean
Whether the given KaType is backed by a single JVM primitive type.
isResolveExtensionFile¶
abstract val VirtualFile.isResolveExtensionFile: Boolean
Whether the given VirtualFile is provided by a KaResolveExtension.
isShortType¶
abstract val KaType.isShortType: Boolean
isStableForSmartCasting¶
abstract val KtExpression.isStableForSmartCasting: Boolean
Whether this expression can be used as a stable smart-cast sink at the current program point.
isStringType¶
abstract val KaType.isStringType: Boolean
isSuspendFunctionType¶
abstract val KaType.isSuspendFunctionType: Boolean
Whether the KaType is a suspend function type.
isUByteType¶
abstract val KaType.isUByteType: Boolean
isUIntType¶
abstract val KaType.isUIntType: Boolean
isULongType¶
abstract val KaType.isULongType: Boolean
isUnitType¶
abstract val KaType.isUnitType: Boolean
isUsedAsExpression¶
abstract val KtExpression.isUsedAsExpression: Boolean
Whether the value of the given KtExpression is used. In other words, true if the value of the expression is not safe to discard.
isUsedAsResultOfLambda¶
abstract val KtExpression.isUsedAsResultOfLambda: Boolean
Whether the value of the given KtExpression is used as the resulting expression of some lambda block.
isUShortType¶
abstract val KaType.isUShortType: Boolean
klibSourceFileName¶
abstract val KaDeclarationSymbol.klibSourceFileName: String?
The source file name for the given KtDeclaration located in a Kotlin library (klib), or null if the declaration is not located in a klib, or when the source file name is not available.
memberScope¶
abstract val KaDeclarationContainerSymbol.memberScope: KaScope
A KaScope containing non-static callable members (functions, properties, and constructors) and all classifier members (classes and objects) of the given KaDeclarationContainerSymbol. The scope includes members inherited from the symbol's supertypes, in addition to members which are declared explicitly inside the symbol's body.
namedClassSymbol¶
abstract val PsiClass.namedClassSymbol: KaNamedClassSymbol?
A KaNamedClassSymbol for the given PsiClass, or null for anonymous classes, local classes, type parameters (which are also PsiClasses), and Kotlin light classes.
abstract val KtClassOrObject.namedClassSymbol: KaNamedClassSymbol?
A KaNamedClassSymbol for the given named KtClassOrObject, or null for KtEnumEntry declarations and object literals.
originalConstructorIfTypeAliased¶
The original KaConstructorSymbol for a type-aliased constructor, or null otherwise.
packageScope¶
abstract val KaPackageSymbol.packageScope: KaScope
A KaScope containing all members of the package represented by the given KaPackageSymbol, not including members of subpackages.
receiverType¶
abstract val KtDoubleColonExpression.receiverType: KaType?
Resolves the given KtDoubleColonExpression to the KaType of its receiver.
resolveExtensionNavigationElements¶
abstract val KtElement.resolveExtensionNavigationElements: Collection<PsiElement>
A list of PsiElements which are used as navigation targets in place of this KtElement provided by a KaResolveExtension.
resolveExtensionScopeWithTopLevelDeclarations¶
abstract val resolveExtensionScopeWithTopLevelDeclarations: KaScope
The KaScope containing top-level callable declarations generated by KaResolveExtensions.
returnType¶
abstract val KtDeclarationWithReturnType.returnType: KaType
The return type of the given KtDeclarationWithReturnType.
returnValueStatus¶
abstract val KaNamedFunctionSymbol.returnValueStatus: KaReturnValueStatus
The return value status of the function (should it be used, or can it be ignored). See the KEEP for details.
rootPackageSymbol¶
abstract val rootPackageSymbol: KaPackageSymbol
A KaPackageSymbol for the root package, which is the special package with an empty fully-qualified name.
samConstructor¶
abstract val KaClassLikeSymbol.samConstructor: KaSamConstructorSymbol?
The associated KaSamConstructorSymbol if this KaClassLikeSymbol is a functional interface type (SAM).
scope¶
abstract val KaType.scope: KaTypeScope?
A KaTypeScope for the given KaType, or null if the type is erroneous. The scope includes all members which are callable on a given type. It also includes synthetic Java properties.
sealedClassInheritors¶
abstract val KaNamedClassSymbol.sealedClassInheritors: List<KaNamedClassSymbol>
The inheritors of the given sealed class.
smartCastInfo¶
abstract val KtExpression.smartCastInfo: KaSmartCastInfo?
Smart cast information for the given KtExpression, or null if smart casts are not applied to it.
staticDeclaredMemberScope¶
abstract val KaDeclarationContainerSymbol.staticDeclaredMemberScope: KaScope
A KaScope containing the static callables (functions and properties) and all classifiers (classes and objects) explicitly declared in the given KaDeclarationContainerSymbol.
staticMemberScope¶
abstract val KaDeclarationContainerSymbol.staticMemberScope: KaScope
A KaScope containing the static members of the given KaDeclarationContainerSymbol.
symbol¶
abstract val KtBackingField.symbol: KaBackingFieldSymbol
A KaBackingFieldSymbol for the given KtBackingField.
abstract val KtClassInitializer.symbol: KaClassInitializerSymbol
A KaClassInitializerSymbol for the given KtClassInitializer.
abstract val KtConstructor<*>.symbol: KaConstructorSymbol
A KaConstructorSymbol for the given KtConstructor.
abstract val KtContextReceiver.symbol: KaContextParameterSymbol
Represents KtContextReceiver as a KaContextParameterSymbol.
abstract val KtDeclaration.symbol: KaDeclarationSymbol
A KaDeclarationSymbol for the given KtDeclaration.
abstract val KtDestructuringDeclaration.symbol: KaDestructuringDeclarationSymbol
A KaDestructuringDeclarationSymbol for the given KtDestructuringDeclaration.
abstract val KtDestructuringDeclarationEntry.symbol: KaVariableSymbol
A KaVariableSymbol that corresponds to the local variable introduced by the given KtDestructuringDeclarationEntry.
abstract val KtEnumEntry.symbol: KaEnumEntrySymbol
A KaEnumEntrySymbol for the given KtEnumEntry.
abstract val KtFile.symbol: KaFileSymbol
A KaFileSymbol for a KtFile.
abstract val KtFunctionLiteral.symbol: KaAnonymousFunctionSymbol
A KaAnonymousFunctionSymbol for the given KtFunctionLiteral.
abstract val KtNamedFunction.symbol: KaFunctionSymbol
A KaFunctionSymbol for the given KtNamedFunction.
abstract val KtObjectDeclaration.symbol: KaClassSymbol
A KaClassSymbol for the given KtObjectDeclaration.
abstract val KtObjectLiteralExpression.symbol: KaAnonymousObjectSymbol
A KaAnonymousObjectSymbol for the given KtObjectLiteralExpression.
abstract val KtParameter.symbol: KaVariableSymbol
A KaVariableSymbol for the given KtParameter.
abstract val KtProperty.symbol: KaVariableSymbol
A KaVariableSymbol for the given KtProperty.
abstract val KtPropertyAccessor.symbol: KaPropertyAccessorSymbol
A KaPropertyAccessorSymbol for the given KtPropertyAccessor.
abstract val KtScript.symbol: KaScriptSymbol
A KaScriptSymbol for a KtScript.
abstract val KtTypeAlias.symbol: KaTypeAliasSymbol
A KaTypeAliasSymbol for the given KtTypeAlias.
abstract val KtTypeParameter.symbol: KaTypeParameterSymbol
A KaTypeParameterSymbol for the given KtTypeParameter.
syntheticJavaPropertiesScope¶
abstract val KaType.syntheticJavaPropertiesScope: KaTypeScope?
A KaTypeScope containing the synthetic Java properties created for a given KaType.
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.
typeCreator¶
abstract val typeCreator: KaTypeCreator
A single entry point for the type building infrastructure.
useSiteModule¶
abstract val useSiteModule: KaModule
useSiteSession¶
open val useSiteSession: KaSession
The KaSession of the current analysis context.
varargArrayType¶
abstract val KaValueParameterSymbol.varargArrayType: KaType?
Functions¶
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.
approximateToDenotableSubtype¶
abstract fun KaType.approximateToDenotableSubtype(): KaType?
approximateToDenotableSubtypeOrSelf¶
open fun KaType.approximateToDenotableSubtypeOrSelf(): KaType
approximateToDenotableSupertype¶
abstract fun KaType.approximateToDenotableSupertype(allowLocalDenotableTypes: Boolean): KaType?
abstract fun KaType.approximateToDenotableSupertype(position: KtElement): KaType?
approximateToDenotableSupertypeOrSelf¶
open fun KaType.approximateToDenotableSupertypeOrSelf(allowLocalDenotableTypes: Boolean): KaType
open fun KaType.approximateToDenotableSupertypeOrSelf(position: KtElement): KaType
asCompositeScope¶
abstract fun List<KaScope>.asCompositeScope(): KaScope
asKaType¶
Converts the given PsiType to a KaType in the context of the useSitePosition.
asPsiType¶
Converts the given KaType to a PsiType in the context of the useSitePosition.
assertIsValidAndAccessible¶
inline fun KaLifetimeOwner.assertIsValidAndAccessible()
asSignature¶
abstract fun <S : KaCallableSymbol> S.asSignature(): KaCallableSignature<S>
Creates a new KaCallableSignature for the given symbol and leaves all types unsubstituted.
abstract fun <S : KaFunctionSymbol> S.asSignature(): KaFunctionSignature<S>
Creates a new KaFunctionSignature for the given symbol and leaves all types unsubstituted.
abstract fun <S : KaVariableSymbol> S.asSignature(): KaVariableSignature<S>
Creates a new KaVariableSignature for the given symbol and leaves all types unsubstituted.
buildArrayType¶
abstract fun buildArrayType(elementType: KaType, init: KaArrayTypeBuilder.() -> Unit = {}): KaType
Builds a boxed / primitive (depending on the init block) array type from the given elementType.
buildClassType¶
abstract fun buildClassType(symbol: KaClassLikeSymbol, init: KaClassTypeBuilder.() -> Unit = {}): KaType
Builds a class type with the given class symbol.
abstract fun buildClassType(classId: ClassId, init: KaClassTypeBuilder.() -> Unit = {}): KaType
Builds a class type with the given class ID.
buildStarTypeProjection¶
abstract fun buildStarTypeProjection(): KaStarTypeProjection
Builds a KaStarTypeProjection (*).
buildTypeParameterType¶
abstract fun buildTypeParameterType(symbol: KaTypeParameterSymbol, init: KaTypeParameterTypeBuilder.() -> Unit = {}): KaTypeParameterType
Builds a KaTypeParameterType with the given type parameter symbol.
buildVarargArrayType¶
abstract fun buildVarargArrayType(elementType: KaType): KaType
Builds the underlying array type of vararg function parameter with the given elementType.
canBeAnalysed¶
abstract fun PsiElement.canBeAnalysed(): Boolean
Checks whether the PsiElement is inside the analysisScope.
collectCallCandidates¶
abstract fun KtResolvableCall.collectCallCandidates(): List<KaCallCandidate>
Returns all candidates considered during overload resolution for the call corresponding to the given KtResolvableCall.
collectDiagnostics¶
abstract fun KtFile.collectDiagnostics(filter: KaDiagnosticCheckerFilter): Collection<KaDiagnosticWithPsi<*>>
Collects all diagnostics for the given file.
collectPossibleReferenceShortenings¶
abstract fun collectPossibleReferenceShortenings(
file: KtFile,
selection: TextRange = file.textRange,
shortenOptions: ShortenOptions = ShortenOptions.DEFAULT,
classShortenStrategy: (KaClassLikeSymbol) -> ShortenStrategy = defaultClassShortenStrategy,
callableShortenStrategy: (KaCallableSymbol) -> ShortenStrategy = defaultCallableShortenStrategy
): ShortenCommand
Collects possible references to shorten.
collectPossibleReferenceShorteningsInElement¶
abstract fun collectPossibleReferenceShorteningsInElement(
element: KtElement,
shortenOptions: ShortenOptions = ShortenOptions.DEFAULT,
classShortenStrategy: (KaClassLikeSymbol) -> ShortenStrategy = defaultClassShortenStrategy,
callableShortenStrategy: (KaCallableSymbol) -> ShortenStrategy = defaultCallableShortenStrategy
): ShortenCommand
Collects possible references to shorten in elements text range.
compile¶
abstract fun compile(file: KtFile, options: KaCompilationOptions): KaCompilationResult
compositeScope¶
open fun KaScopeContext.compositeScope(filter: (KaScopeKind) -> Boolean = { true }): KaScope
computeExitPointSnapshot¶
abstract fun computeExitPointSnapshot(statements: List<KtExpression>): KaDataFlowExitPointSnapshot
computeMissingCases¶
abstract fun KtWhenExpression.computeMissingCases(): List<KaWhenMissingCase>
Computes the missing cases of the given KtWhenExpression.
copy¶
abstract fun <T : KaClassType> T.copy(init: KaClassTypeBuilder.() -> Unit): KaClassType
Creates a copy of this KaClassType with modifications applied via the init block.
abstract fun KaFunctionType.copy(init: KaFunctionTypeBuilder.() -> Unit): KaFunctionType
Creates a copy of this KaFunctionType with modifications applied via the init block.
abstract fun KaTypeParameterType.copy(init: KaTypeParameterTypeBuilder.() -> Unit): KaTypeParameterType
Creates a copy of this KaTypeParameterType with modifications applied via the init block.
abstract fun KaUsualClassType.copy(init: KaClassTypeBuilder.() -> Unit): KaUsualClassType
Creates a copy of this KaUsualClassType with modifications applied via the init block.
createCompilationOptions¶
abstract fun createCompilationOptions(init: KaCompilationOptionsBuilder.() -> Unit): KaCompilationOptions
Creates a new KaCompilationOptions instance using the given DSL init block.
createExtensionCandidateChecker¶
abstract fun createExtensionCandidateChecker(
originalFile: KtFile,
nameExpression: KtSimpleNameExpression,
explicitReceiver: KtExpression?
): KaCompletionExtensionCandidateChecker
Returns an extension applicability checker for the given context nameExpression. The function is meant to only be used for providing auto-completion for Kotlin in IntelliJ IDEA.
createInheritanceTypeSubstitutor¶
abstract fun createInheritanceTypeSubstitutor(subClass: KaClassSymbol, superClass: KaClassSymbol): KaSubstitutor?
Creates a KaSubstitutor based on the inheritance relationship between subClass and superClass. subClass must inherit from superClass and there may not be any error types in the inheritance path. Otherwise, null is returned.
createSubstitutor¶
abstract fun createSubstitutor(mappings: Map<KaTypeParameterSymbol, KaType>): KaSubstitutor
Creates a KaSubstitutor based on the given mappings.
createSubtypingUnificationSubstitutor¶
abstract fun createSubtypingUnificationSubstitutor(leftTypesToRightTypes: List<Pair<KaType, KaType>>, isFreeTypeParameter: (KaTypeParameterSymbol) -> Boolean): KaSubstitutor?
Creates a KaSubstitutor which assigns type arguments such that, for each pair in leftTypesToRightTypes, the substituted left type is a subtype of the substituted right type. Returns null if such an assignment is not possible.
abstract fun createSubtypingUnificationSubstitutor(leftTypesToRightTypes: List<Pair<KaType, KaType>>, constructionPolicy: KaUnificationSubstitutorPolicy): KaSubstitutor?
Creates a KaSubstitutor which assigns type arguments such that, for each pair in leftTypesToRightTypes, the substituted left type is a subtype of the substituted right type. Returns null if such an assignment is not possible.
abstract fun createSubtypingUnificationSubstitutor(
leftType: KaType,
rightType: KaType,
constructionPolicy: KaUnificationSubstitutorPolicy
): KaSubstitutor?
Creates a KaSubstitutor which assigns type arguments such that the substituted leftType is a subtype of the substituted rightType. Returns null if such an assignment is not possible.
createUseSiteVisibilityChecker¶
abstract fun createUseSiteVisibilityChecker(
useSiteFile: KaFileSymbol,
receiverExpression: KtExpression? = null,
position: PsiElement
): KaUseSiteVisibilityChecker
Creates a visibility checker for the given use-site position.
directSupertypes¶
abstract fun KaType.directSupertypes(shouldApproximate: Boolean): Sequence<KaType>
Returns the direct supertypes of the given KaType.
evaluate¶
abstract fun KtExpression.evaluate(): KaConstantValue?
Attempts to evaluate the given KtExpression to a compile-time constant value, or returns null if this is not possible.
evaluateAsAnnotationValue¶
abstract fun KtExpression.evaluateAsAnnotationValue(): KaAnnotationValue?
Attempts to evaluate the given KtExpression to an annotation value (a constant value which can be used as an annotation argument), or returns null if this is not possible.
findClass¶
abstract fun findClass(classId: ClassId): KaClassSymbol?
Returns a KaClassSymbol for the specified ClassId, or null if such a symbol cannot be found.
findClassLike¶
abstract fun findClassLike(classId: ClassId): KaClassLikeSymbol?
Returns a KaClassLikeSymbol for the specified ClassId, or null if such a symbol cannot be found.
findKDoc¶
abstract fun KaDeclarationSymbol.findKDoc(): KDocCommentDescriptor?
Resolves KDoc for this KaDeclarationSymbol.
abstract fun KtDeclaration.findKDoc(): KDocCommentDescriptor?
Resolves KDoc for this KtDeclaration.
findPackage¶
abstract fun findPackage(fqName: FqName): KaPackageSymbol?
Returns a KaPackageSymbol corresponding to the given fqName if that package exists and is visible from the current use site, or null otherwise.
findTopLevelCallables¶
abstract fun findTopLevelCallables(packageFqName: FqName, name: Name): Sequence<KaCallableSymbol>
Finds top-level functions and properties called name in the package called packageFqName. Returns only symbols that are visible from the current use-site module.
findTypeAlias¶
abstract fun findTypeAlias(classId: ClassId): KaTypeAliasSymbol?
Returns a KaTypeAliasSymbol for the specified ClassId, or null if such a symbol cannot be found.
getExpectsForActual¶
abstract fun KaDeclarationSymbol.getExpectsForActual(): List<KaDeclarationSymbol>
Returns an expect symbol for the given actual symbol, if it is available. The function may return multiple expect symbols in case of ambiguity errors.
hasCommonSubtypeWith¶
abstract fun KaType.hasCommonSubtypeWith(that: KaType): Boolean
hasConflictingSignatureWith¶
abstract fun KaFunctionSymbol.hasConflictingSignatureWith(other: KaFunctionSymbol, targetPlatform: TargetPlatform): Boolean
Returns whether this declaration has a conflicting signature with other based on platform-specific checks from targetPlatform.
implementationState¶
abstract fun KaCallableSymbol.implementationState(implementerClassSymbol: KaClassSymbol): KaCallableImplementationState?
Returns the KaCallableImplementationState of the given KaCallableSymbol in the context of implementerClassSymbol.
isDirectSubClassOf¶
abstract fun KaClassSymbol.isDirectSubClassOf(superClass: KaClassSymbol): Boolean
Checks if this class has superClass listed as its direct superclass.
isPublicApi¶
abstract fun isPublicApi(symbol: KaDeclarationSymbol): Boolean
Whether the symbol is effectively public, including internal declarations with the PublishedApi annotation.
isSubClassOf¶
abstract fun KaClassSymbol.isSubClassOf(superClass: KaClassSymbol): Boolean
Checks if this class has superClass as its superclass somewhere in the inheritance hierarchy.
isSubtypeOf¶
abstract fun KaType.isSubtypeOf(symbol: KaClassLikeSymbol, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean
abstract fun KaType.isSubtypeOf(supertype: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean
abstract fun KaType.isSubtypeOf(classId: ClassId, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): 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.
isVisibleInClass¶
abstract fun KaCallableSymbol.isVisibleInClass(classSymbol: KaClassSymbol): Boolean
Checks whether the given KaCallableSymbol (possibly inherited from a superclass) is visible in the given classSymbol.
lowerBoundIfFlexible¶
open fun KaType.lowerBoundIfFlexible(): KaType
Returns the KaFlexibleType's lower bound, or the type itself if it is not flexible.
mapToJvmTypeDescriptor¶
abstract fun KaType.mapToJvmTypeDescriptor(): String
Convert the given KaType to a JVM type descriptor with the KaTypeMappingMode.DEFAULT. To learn more about JVM descriptors, check out the JVM specification.
modify¶
abstract fun KaCompilationOptions.modify(init: KaCompilationOptionsBuilder.() -> Unit): KaCompilationOptions
Creates a copy of these KaCompilationOptions, applying the given init modifications.
render¶
abstract fun KaDeclarationSymbol.render(renderer: KaDeclarationRenderer = KaDeclarationRendererForSource.WITH_QUALIFIED_NAMES): String
Renders the given KaDeclarationSymbol to a string. The particular rendering strategy is defined by the renderer.
abstract fun KaType.render(renderer: KaTypeRenderer = KaTypeRendererForSource.WITH_QUALIFIED_NAMES, position: Variance): String
resolveCall¶
abstract fun KtAnnotationEntry.resolveCall(): KaAnnotationCall?
Resolves the given KtAnnotationEntry to an annotation constructor call.
abstract fun KtArrayAccessExpression.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtArrayAccessExpression to a simple function call representing get/set operator invocation.
abstract fun KtCallElement.resolveCall(): KaFunctionCall<*>?
Resolves the given KtCallElement to a function call.
abstract fun KtCallableReferenceExpression.resolveCall(): KaCallableReferenceCall<*, *>?
Resolves the given KtCallableReferenceExpression to a callable member call.
abstract fun KtCollectionLiteralExpression.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtCollectionLiteralExpression to a simple function call representing the corresponding array factory invocation.
abstract fun KtConstructorCalleeExpression.resolveCall(): KaFunctionCall<KaConstructorSymbol>?
Resolves the given KtConstructorCalleeExpression to a constructor call.
abstract fun KtConstructorDelegationCall.resolveCall(): KaDelegatedConstructorCall?
Resolves the given KtConstructorDelegationCall to a delegated constructor call.
Resolves the given KtConstructorDelegationReferenceExpression to a delegated constructor call.
abstract fun KtDestructuringDeclarationEntry.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtDestructuringDeclarationEntry to a call representing the componentN invocation (for positional destructuring) or the property access (for name-based destructuring).
Resolves the given KtEnumEntrySuperclassReferenceExpression to a delegated constructor call.
abstract fun KtForExpression.resolveCall(): KaForLoopCall?
Resolves the given KtForExpression to a KaForLoopCall representing the desugared for loop.
abstract fun KtNameReferenceExpression.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtNameReferenceExpression to a call representing the referenced declaration.
abstract fun KtPropertyDelegate.resolveCall(): KaDelegatedPropertyCall?
Resolves the given KtPropertyDelegate to a KaDelegatedPropertyCall representing the desugared delegated property.
abstract fun KtQualifiedExpression.resolveCall(): KaSimpleCall<*, *>?
Resolves the given KtQualifiedExpression to a call representing the member or extension access.
abstract fun KtSuperTypeCallEntry.resolveCall(): KaFunctionCall<KaConstructorSymbol>?
Resolves the given KtSuperTypeCallEntry to a constructor call of the referenced supertype.
abstract fun KtWhenConditionInRange.resolveCall(): KaFunctionCall<KaNamedFunctionSymbol>?
Resolves the given KtWhenConditionInRange to a simple function call representing the corresponding contains operator invocation used by the in/!in branch condition.
abstract fun KtResolvableCall.resolveCall(): KaSimpleOrMultiCall?
Resolves the call for the given KtResolvableCall.
resolveSymbol¶
abstract fun KtAnnotationEntry.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol of the annotation referenced by the given KtAnnotationEntry.
abstract fun KtArrayAccessExpression.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the operator function symbol targeted by the given KtArrayAccessExpression.
abstract fun KtCallElement.resolveSymbol(): KaFunctionSymbol?
Resolves the function symbol targeted by the given KtCallElement.
abstract fun KtCallableReferenceExpression.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtCallableReferenceExpression.
abstract fun KtClassLiteralExpression.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtClassLiteralExpression (Foo::class).
abstract fun KtCollectionLiteralExpression.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the function symbol targeted by the given KtCollectionLiteralExpression.
abstract fun KtConstructorCalleeExpression.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorCalleeExpression.
abstract fun KtConstructorDelegationCall.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorDelegationCall.
abstract fun KtConstructorDelegationReferenceExpression.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol referenced by the given KtConstructorDelegationReferenceExpression.
abstract fun KtDelegatedSuperTypeEntry.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtDelegatedSuperTypeEntry (class Foo : Bar by baz).
abstract fun KtDestructuringDeclarationEntry.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtDestructuringDeclarationEntry.
abstract fun KtEnumEntrySuperclassReferenceExpression.resolveSymbol(): KaNamedClassSymbol?
Resolves the enum class symbol referenced by the given KtEnumEntrySuperclassReferenceExpression.
abstract fun KtFunctionType.resolveSymbol(): KaClassSymbol?
Resolves the synthetic function class symbol referenced by the given KtFunctionType.
abstract fun KtInstanceExpressionWithLabel.resolveSymbol(): KaDeclarationSymbol?
Resolves the declaration symbol referenced by the given KtInstanceExpressionWithLabel.
abstract fun KtLabelReferenceExpression.resolveSymbol(): KaDeclarationSymbol?
Resolves the declaration symbol targeted by the given KtLabelReferenceExpression.
abstract fun KtNullableType.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtNullableType.
abstract fun KtQualifiedExpression.resolveSymbol(): KaCallableSymbol?
Resolves the callable symbol targeted by the given KtQualifiedExpression.
abstract fun KtReturnExpression.resolveSymbol(): KaFunctionSymbol?
Resolves the function symbol targeted by the given KtReturnExpression.
abstract fun KtSuperTypeCallEntry.resolveSymbol(): KaConstructorSymbol?
Resolves the constructor symbol by the given KtSuperTypeCallEntry.
abstract fun KtSuperTypeEntry.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtSuperTypeEntry (the no-parens form class Foo : Bar).
abstract fun KtTypeReference.resolveSymbol(): KaClassifierSymbol?
Resolves the classifier symbol referenced by the given KtTypeReference.
abstract fun KtWhenConditionInRange.resolveSymbol(): KaNamedFunctionSymbol?
Resolves the operator function symbol targeted by the given KtWhenConditionInRange.
abstract fun KtResolvable.resolveSymbol(): KaSymbol?
Resolves a single symbol for the given KtResolvable.
resolveSymbols¶
abstract fun KtResolvable.resolveSymbols(): Collection<KaSymbol>
Resolves symbols for the given KtResolvable.
resolveToCall¶
abstract fun KtElement.resolveToCall(): KaCallInfo?
Resolves the given KtElement to a KaCallInfo object. KaCallInfo either contains a successfully resolved call or an error with a list of candidate calls and a diagnostic.
resolveToCallCandidates¶
abstract fun KtElement.resolveToCallCandidates(): List<KaCallCandidateInfo>
Returns all candidates considered during overload resolution for the call corresponding to this KtElement.
resolveToSymbol¶
abstract fun KtReference.resolveToSymbol(): KaSymbol?
Resolves the given KtReference to a symbol.
resolveToSymbols¶
abstract fun KtReference.resolveToSymbols(): Collection<KaSymbol>
Resolves the given KtReference to symbols.
restore¶
Returns the restored KaType (possibly a new type instance) if the pointer is still valid, or null otherwise.
restoreSymbol¶
open fun <S : KaSymbol> KaSymbolPointer<S>.restoreSymbol(): S?
Returns the restored KaSymbol (possibly a new symbol instance) if the pointer is still valid, or null otherwise.
scopeContext¶
abstract fun KtFile.scopeContext(position: KtElement): KaScopeContext
semanticallyEquals¶
abstract fun KaType.semanticallyEquals(other: KaType, errorTypePolicy: KaSubtypingErrorTypePolicy = KaSubtypingErrorTypePolicy.STRICT): Boolean
substitute¶
abstract fun <S : KaCallableSymbol> S.substitute(substitutor: KaSubstitutor): KaCallableSignature<S>
Applies a substitutor to the given symbol and returns a KaCallableSignature with substituted types.
abstract fun <S : KaFunctionSymbol> S.substitute(substitutor: KaSubstitutor): KaFunctionSignature<S>
Applies a substitutor to the given symbol and returns a KaFunctionSignature with substituted types.
abstract fun <S : KaVariableSymbol> S.substitute(substitutor: KaSubstitutor): KaVariableSignature<S>
Applies a substitutor to the given symbol and returns a KaVariableSignature with substituted types.
tryResolveCall¶
abstract fun KtForExpression.tryResolveCall(): KaForLoopCallResolutionAttempt?
Attempts to resolve the given KtForExpression to a KaForLoopCallResolutionAttempt containing the individual resolution results for each desugared operator call (iterator, hasNext, next).
abstract fun KtPropertyDelegate.tryResolveCall(): KaDelegatedPropertyCallResolutionAttempt?
Attempts to resolve the given KtPropertyDelegate to a KaDelegatedPropertyCallResolutionAttempt containing the individual resolution results for each desugared operator call (getValue, setValue, provideDelegate).
abstract fun KtResolvableCall.tryResolveCall(): KaCallResolutionAttempt?
Attempts to resolve the call for the given KtResolvableCall.
tryResolveSymbols¶
abstract fun KtResolvable.tryResolveSymbols(): KaSymbolResolutionAttempt?
Attempts to resolve a symbol for the given KtResolvable.
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.