Skip to content

asPsiClass

context(session: KaSession)
fun KaClassSymbol.asPsiClass(): PsiClass?

Converts the given KaClassSymbol to Java PsiClass in the context of the useSiteModule.

The resulting PsiClass is the view on the given Kotlin class 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.

If useSiteModule is not a JVM module or the provided KaClassSymbol is not visible from Java, returns null.

Example:

The following Kotlin class:

interface MyInterface {
    val property: String

    fun function(argument: Int): Int
}

Is seen as the following PsiClass from Java:

public interface MyInterface {
    @org.jetbrains.annotations.NotNull()
    java.lang.String getProperty();

    int function(int argument);
}

The following Kotlin enum class:

package example

enum class MyEnum {
    A {
        fun foo() {}
    },
    B,
}

Is seen as the following PsiClass from Java:

public enum MyEnum {
    A // PsiField
    {
        A();                     // Anonymous initializer PsiClass
        public final void foo(); //
    },

    B; // Does not have an anonymous initializer class, just PsiField

    public static kotlin.enums.EnumEntries<example.MyEnum> getEntries();
    public static example.MyEnum [] values();
    public static example.MyEnum valueOf(java.lang.String) throws java.lang.IllegalArgumentException, java.lang.NullPointerException;
    private  MyEnum();
}