Skip to content

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