Skip to content

asPsiField

context(session: KaSession)
fun KaBackingFieldSymbol.asPsiField(): PsiField?

Converts the given KaBackingFieldSymbol to Java PsiField in the context of the useSiteModule.

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

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

Example:

The following Kotlin property with implicit backing field:

// MyFile.kt
val x: Int = 0 // implicit backing field

Is seen as the following PsiMethod getter and PsiField from Java:

public final class MyFileKt {
    private static final int x = 0; // PsiField

    public static int getX();
}
context(session: KaSession)
fun KaClassSymbol.asPsiField(): PsiField?

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

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

KaClassSymbol has be mapped to PsiField in several cases:

  • INSTANCE field for object declarations

  • Companion (or the given name for named companions) field for companion objects

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

Example:

The following Kotlin companion object

package example

class MyClass {
    companion object {
        fun foo() {}
    }
}

Is seen as the following PsiField from Java:

public final class MyClass {
    public static final example.MyClass.Companion Companion; // `Companion` instance field

    public MyClass();

    public static final class Companion {
        private  Companion();

        public final void foo();
    }
}

The following Kotlin object

package example

object MyObject {
    fun foo() {}
}

Is seen as the following PsiField from Java:

public final class MyObject {
    public static final example.MyObject INSTANCE; // `INSTANCE` field

    private MyObject();

    public void foo();
}
context(session: KaSession)
fun KaEnumEntrySymbol.asPsiField(): PsiEnumConstant?

Converts the given KaEnumEntrySymbol to Java PsiEnumConstant in the context of the useSiteModule.

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

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

Example:

The following Kotlin enum entries

enum class MyEnum {
    A,
    B
}

Are seen as the following PsiEnumConstants from Java:

public enum MyEnum {
    A, // PsiEnumConstant for MyEnum.A
    B; // PsiEnumConstant for MyEnum.B

    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();
}