Skip to content

KaSymbolProvider

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

KaSymbolProvider provides KaSymbols for given PSI elements.

Important: Symbols can be created only for elements which are a part of the current KaSession.

See also

Inheritors

Properties

classSymbol

A KaClassSymbol for the given KtClassOrObject, or null for KtEnumEntry declarations.

To retrieve a KaEnumEntrySymbol, please refer to KtEnumEntry.symbol.

namedClassSymbol

A KaNamedClassSymbol for the given named KtClassOrObject, or null for KtEnumEntry declarations and object literals.

rootPackageSymbol

A KaPackageSymbol for the root package, which is the special package with an empty fully-qualified name.

symbol

A KaDeclarationSymbol for the given KtDeclaration.

There are more specific symbol endpoints, such as KtNamedFunction.symbol and KtClassOrObject.classSymbol, which can be used when more specific PSI elements are available.

A KaVariableSymbol for the given KtParameter.

Unfortunately, KtParameter in PSI stands for many things, and not all of them are represented by a single type of symbol, so this function does not work for all possible KtParameters.

If KtParameter.isFunctionTypeParameter is true, i.e. if the given KtParameter is used as a function type parameter, it is not possible to create KaValueParameterSymbol, hence an error will be raised.

If KtParameter.isLoopParameter is true, i.e. if the given KtParameter is a loop variable in for expression, then the symbol is KaLocalVariableSymbol.

If KtParameter.isContextParameter is true, i.e. if the given KtParameter is used as a context parameter, then the symbol is KaContextParameterSymbol.

Otherwise, the symbol is KaValueParameterSymbol.

A KaVariableSymbol for the given KtProperty.

The symbol is a KaKotlinPropertySymbol for non-local properties, and a KaLocalVariableSymbol for local ones.

A KaClassSymbol for the given KtObjectDeclaration.

The symbol may either be a KaAnonymousObjectSymbol if the given declaration is an object expression, or a KaNamedClassSymbol if it is a named object declaration.

A KaVariableSymbol that corresponds to the local variable introduced by the given KtDestructuringDeclarationEntry.

The symbol is usually a KaLocalVariableSymbol. However, for a top-level destructuring declaration in a script, the symbol is a KaKotlinPropertySymbol.

Example

val (x, y) = p

The destructuring declaration above has two entries, one corresponding to x and another to y. For both of these entries, we can retrieve a KaVariableSymbol which describes the entry.

abstract val KtFile.symbol: KaFileSymbol

A KaFileSymbol for a KtFile.

Represents KtContextReceiver as a KaContextParameterSymbol.

This is a temporary API for simplicity during the transition from context receivers to context parameters.

Note: context receivers inside KtFunctionType are not supported.

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

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.

The function combines both class search (see findClass) and type alias search (see findTypeAlias).

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.

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.