Skip to content

KaScopeProvider

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

Inheritors

Properties

combinedDeclaredMemberScope

A KaScope containing all members explicitly declared in the given KaDeclarationContainerSymbol.

In contrast to declaredMemberScope and staticDeclaredMemberScope, this scope contains both static and non-static members.

combinedMemberScope

declarationScope

A KaScope containing unsubstituted declarations from the KaType's underlying declaration.

declaredMemberScope

A KaScope containing the non-static callables (functions, properties, and constructors) and inner classes explicitly declared in the given KaDeclarationContainerSymbol.

The declared member scope does not contain classifiers (including the companion object) except for inner classes. To retrieve the classifiers declared in this KaDeclarationContainerSymbol, please use the static declared member scope provided by staticDeclaredMemberScope.

See also

delegatedMemberScope

A KaScope containing synthetic callables (functions and properties) created by interface delegation.

Example

interface I {
    val foo: Int get() = 2
    fun bar(): String
}

class A(
    private val p: I
) : I by p {
    val regularProperty: Int = 5
}

The delegated member scope for A has the following entries:

override val foo: kotlin.Int
  get()

override fun bar(): kotlin.String

regularProperty is not contained in the delegated member scope because it is not a delegated property.

fileScope

A KaScope containing the top-level declarations (such as classes, functions and properties) in the given KaFileSymbol.

importingScopeContext

A KaScopeContext formed from all imports in the KtFile.

By default, the scope context also includes default importing scopes, which can be filtered by KaScopeKind.

memberScope

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.

The member scope doesn't include synthetic Java properties. For a scope which contains synthetic properties, please refer to syntheticJavaPropertiesScope.

See also

packageScope

A KaScope containing all members of the package represented by the given KaPackageSymbol, not including members of subpackages.

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.

Comparing to KaScope, the KaTypeScope contains members whose use-site type parameters have been substituted.

Example

fun foo(list: List<String>) {
    list
}

We can get a KaTypeScope for the expression type of list. This scope contains a get(index: Int): String function, where the return type E from List.get is substituted with the type argument String.

See also

staticDeclaredMemberScope

A KaScope containing the static callables (functions and properties) and all classifiers (classes and objects) explicitly declared in the given KaDeclarationContainerSymbol.

It is worth noting that, while Java classes may contain declarations of static callables freely, in Kotlin only enum classes define static callables. Hence, for non-enum Kotlin classes, it is not expected that the static declared member scope will contain any callables.

See also

staticMemberScope

A KaScope containing the static members of the given KaDeclarationContainerSymbol.

The behavior of the scope differs based on whether the given KaDeclarationContainerSymbol is a Kotlin or Java class:

  • Kotlin class: The scope contains static callables (functions and properties) and classifiers (classes and objects) declared directly in the KaDeclarationContainerSymbol. Hence, the static member scope for Kotlin classes is equivalent to staticDeclaredMemberScope.

  • Java class: The scope contains static callables (functions and properties) declared in the KaDeclarationContainerSymbol or any of its superclasses (excluding static callables from super-interfaces), and classes declared directly in the KaDeclarationContainerSymbol. This follows Kotlin's rules about static inheritance in Java classes, where static callables are propagated from superclasses, but nested classes are not.

Kotlin Example

abstract class A {
    class C1
    inner class D1
    object O1

    // There is no way to declare a static callable in an abstract class, as only enum classes define additional static callables.
}

class B : A() {
    class C2
    inner class D2
    object O2
    companion object {
        val baz: String = ""
    }
}

The static member scope of B contains the following symbols:

class C2
inner class D2
object O2
companion object

Java Example

// SuperInterface.java
public interface SuperInterface {
    public static void fromSuperInterface() { }
}

// SuperClass.java
public abstract class SuperClass implements SuperInterface {
    static class NestedSuperClass { }
    class InnerSuperClass { }
    public static void fromSuperClass() { }
}

// FILE: JavaClass.java
public class JavaClass extends SuperClass {
    static class NestedClass { }
    class InnerClass { }
    public static void fromJavaClass() { }
}

The static member scope of JavaClass contains the following symbols:

public static void fromSuperClass()
public static void fromJavaClass()
static class NestedClass
class InnerClass

See also

syntheticJavaPropertiesScope

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.

Functions

asCompositeScope

Combines a list of KaScopes into a single composite KaScope. The resulting scope contains all members of its constituent scopes.

assertIsValidAndAccessible

compositeScope

open fun KaScopeContext.compositeScope(filter: (KaScopeKind) -> Boolean = { true }): KaScope

Returns a single KaScope that contains declarations from all scopes that satisfy filter.

The order of declarations corresponds to the order of their containing scopes, which are sorted according to their indices in the scope tower.

isValid

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

scopeContext

abstract fun KtFile.scopeContext(position: KtElement): KaScopeContext

Computes the lexical scope context for a given position in the KtFile. The scope context includes all scopes that are relevant for the given position, together with all available implicit receivers.

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.