Skip to content

KaScope

A KaScope provides access to the declarations contained in a specific declaration, file, or package, such as classes, type aliases, functions, properties, and constructors.

To retrieve a scope for a particular declaration, use the various functions available in KaScopeProvider.

Properties

callables

abstract fun callables(nameFilter: (Name) -> Boolean): Sequence<KaCallableSymbol>

Returns a sequence of KaCallableSymbols contained in the scope which match the nameFilter.

The implementation of this function needs to retrieve a set of all possible names before processing callables. The overload with Collection<Name> should be used when the candidate name set is known.

abstract fun callables(names: Collection<Name>): Sequence<KaCallableSymbol>

abstract fun callables(vararg names: Name): Sequence<KaCallableSymbol>

Returns a sequence of KaCallableSymbols contained in the scope which match the given names.

The implementation of this function is optimized compared to using a name filter and should be used when the candidate name set is known.

A sequence of KaCallableSymbols contained in the scope.

The implementation of this property needs to retrieve a set of all possible names before processing callables. The overload with Collection<Name> should be used when the candidate name set is known.

classifiers

abstract fun classifiers(nameFilter: (Name) -> Boolean): Sequence<KaClassifierSymbol>

Returns a sequence of KaClassifierSymbols contained in the scope which match the nameFilter.

The result includes:

  • Nested classes

  • Inner classes

  • Nested type aliases for a class scope

  • Top-level classes and top-level type aliases for a file scope

The implementation of this function needs to retrieve a set of all possible names before processing classifiers. The overload with Collection<Name> should be used when the candidate name set is known.

abstract fun classifiers(names: Collection<Name>): Sequence<KaClassifierSymbol>

abstract fun classifiers(vararg names: Name): Sequence<KaClassifierSymbol>

Returns a sequence of KaClassifierSymbols contained in the scope which match the given names.

The result includes:

  • Nested classes

  • Inner classes

  • Nested type aliases for a class scope

  • Top-level classes and top-level type aliases for a file scope

The implementation of this function is optimized compared to using a name filter and should be used when the candidate name set is known.

A sequence of KaClassifierSymbols contained in the scope.

The result includes:

  • Nested classes

  • Inner classes

  • Nested type aliases for a class scope

  • Top-level classes and top-level type aliases for a file scope

The implementation of this property needs to retrieve a set of all possible names before processing classifiers. The overload with Collection<Name> should be used when the candidate name set is known.

constructors

A sequence of KaConstructorSymbol contained in the scope.

declarations

abstract fun declarations(nameFilter: (Name) -> Boolean): Sequence<KaDeclarationSymbol>

Returns a sequence of KaDeclarationSymbols contained in the scope which match the nameFilter.

Unlike the declarations property, constructors are not included in the result, as they are not filtered by name. Use the constructors property directly if constructors are required.

The implementation of this function needs to retrieve a set of all possible names before processing declarations. The overload with Collection<Name> should be used when the candidate name set is known.

See also

abstract fun declarations(names: Collection<Name>): Sequence<KaDeclarationSymbol>

abstract fun declarations(vararg names: Name): Sequence<KaDeclarationSymbol>

Returns a sequence of KaDeclarationSymbols contained in the scope which match the given names.

Unlike the declarations property, constructors are not included in the result, as they are not filtered by name. Use the constructors property directly if constructors are required.

The implementation of this function is optimized compared to using a name filter and should be used when the candidate name set is known.

See also

A sequence of all KaDeclarationSymbols contained in the scope.

The result yields, in order, every element of callables, classifiers, and constructors — i.e., every declaration this scope can provide:

To restrict the result to declarations matching a given name, use one of the declarations overloads. Those overloads omit constructors, which cannot be meaningfully filtered by name.

token

abstract val token: KaLifetimeToken

The KaLifetimeToken which determines the lifetime of the lifetime owner.

Functions

assertIsValidAndAccessible

getAllPossibleNames

open fun getAllPossibleNames(): Set<Name>

Returns the set of top-level declaration names contained in the scope. The set may contain false positives, i.e. names which aren't contained in the scope.

getPackageSymbols

abstract fun getPackageSymbols(nameFilter: (Name) -> Boolean = { true }): Sequence<KaPackageSymbol>

Returns a sequence of KaPackageSymbols matching nameFilter which are a direct subpackage of the scope's package.

getPossibleCallableNames

abstract fun getPossibleCallableNames(): Set<Name>

Returns the set of top-level callable names contained in the scope. The set may contain false positives, i.e. names which aren't contained in the scope.

getPossibleClassifierNames

abstract fun getPossibleClassifierNames(): Set<Name>

Returns the set of top-level classifier names contained in the scope. The set may contain false positives, i.e. names which aren't contained in the scope.

isValid

Whether the lifetime owner is still valid, i.e. we are still in the scope of the lifetime owner's regular lifetime.

mayContainName

open fun mayContainName(name: Name): Boolean

Checks whether the scope might contain the given name.

Since getPossibleCallableNames and getPossibleClassifierNames admit false positives, the result may be true even if the scope doesn't contain a declaration with such a name. The reverse is not so: when mayContainName is false, the scope definitely doesn't contain a declaration with that name.

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.