Skip to content

asFacadePsiClass

context(session: KaSession)
fun KaFileSymbol.asFacadePsiClass(): PsiClass?

Converts the given KaFileSymbol to Java facade PsiClass in the context of the useSiteModule.

The resulting PsiClass is the view on the given Kotlin file from Java. E.g., main.kt file is converted to MainKt class facade. useSiteModule for the current KaSession is used to provide proper actualizations for expect declarations. Since the produced PsiClass is a JVM-specific representation, useSiteModule is expected to be a JVM one.

Note that the produced facade class only stores non-class declarations. Each Kotlin class is mapped to its own top-level PsiClass.

If useSiteModule is not a JVM module or the provided KaFileSymbol is not supported, returns null.

Examples of non-supported files are:

  • Scripts

  • Files with no top-level callables

If the provided KaFileSymbol has a kotlin.jvm.JvmMultifileClass annotation, the constructed PsiClass is a facade for all other files with kotlin.jvm.JvmMultifileClass annotation and the same kotlin.jvm.JvmName.

Example:

The following Kotlin file:

// MyFile.kt
class MyClass

fun foo(t: Int) {}

val x: Int = 0

Is seen as the following PsiClass from Java:

public final class MyFileKt { // Doesn't contain `MyClass` declaration
    private static final int x = 0;

    public static int getX();

    public static void foo(int);
}

The following multifile class file FirstFacadeClass:

// FirstFacadeClass.kt
@file:JvmMultifileClass
@file:JvmName("SomeFacade")
package pkg

fun foo() = 42

val x = 24

// SecondFacadeClass.kt
@file:JvmMultifileClass
@file:JvmName("SomeFacade")
package pkg

private fun privateFoo(): Int = 3

const val myConst = 42

Is seen as the following PsiClass from Java:

public final class SomeFacade {
  public static final int myConst = 42;

  public static final int foo();

  public static final int getX();
}

See also

context(session: KaSession)
fun KaScriptSymbol.asFacadePsiClass(): PsiClass?

Converts the given KaScriptSymbol to Java facade PsiClass in the context of the useSiteModule.

The resulting PsiClass is the view on the given Kotlin script from Java. useSiteModule for the current KaSession is used to provide proper actualizations for expect declarations. Since the produced PsiClass is a JVM-specific representation, useSiteModule is expected to be a JVM one.

In contrast to KaFileSymbol.asFacadePsiClass, regular Kotlin classes in scripts are mapped to nested PsiClasses.

If useSiteModule is not a JVM module or the provided KaScriptSymbol comes from a code fragment, returns null.

Example:

The following Kotlin script:

// MyScript.kts
println("Hello, World!")

val x = 1

class MyClass {
    fun bar() {}
}

Is seen as the following PsiClass from Java:

public final class MyScript extends kotlin.script.experimental.templates.ScriptWithArgs {
    public static void main(java.lang.String[]);

    public MyScript(java.lang.String[]);

    private final int x = 1;
    public int getX();

    public static final class MyClass {
        public MyClass();
        public void bar();
    }
}

See also