Java/Kotlin Bridging¶
Note
Experimental API. Subject to changes.
While the Analysis API exposes declarations and types from the Kotlin standpoint, it works also with Java source and library declarations. The API provides a set of utilities for converting between Kotlin and Java views of declarations.
Types¶
In IntelliJ IDEA, PsiType is a representation for Java types. Conceptually, it is similar to KaType.
The Analysis API provides mapping between the two representations.
fun PsiType.asKaType(useSitePosition: PsiElement): KaType?-
- Convert the given Java type to a
KaType. useSitePositionis the context element used to gather additional information related to the Java type usage.- Experimental API.
- Convert the given Java type to a
fun KaType.asPsiType(useSitePosition: PsiElement, allowErrorTypes: Boolean, mode: KaTypeMappingMode = KaTypeMappingMode.DEFAULT, isAnnotationMethod: Boolean = false, suppressWildcards: Boolean? = null, preserveAnnotations: Boolean = true): PsiType?- Convert the given Kotlin type to a
PsiType. useSitePositionis used to determine if the local type needs to be approximated.- Experimental API.
fun KaType.mapToJvmType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): Type- Convert the given Kotlin type to a JVM ASM type.
- Experimental API.
val KaType.isPrimitiveBacked: Booleantrueif the type is backed by a primitive JVM type.- Experimental API.
Symbols¶
The Analysis API can create symbols for Java declarations.
val PsiClass.namedClassSymbol: KaNamedClassSymbol?-
- Map a Java class to a class symbol. Always
nullfor anonymous classes and type parameters (that are also PsiClasses).- Experimental API.
- Map a Java class to a class symbol. Always
val PsiMember.callableSymbol: KaCallableSymbol?- Map a Java method or a field to a callable symbol. Always
nullfor local Java declarations. - Experimental API.
Other utilities¶
val KaCallableSymbol.containingJvmClassName: String?- The fully qualified class name containing the callable (in the
foo.bar.Class.Companionformat). - Experimental API.
val KaPropertySymbol.javaGetterName: Name- The JVM getter method name for the given property symbol.
val KaPropertySymbol.javaSetterName: Name?- The JVM setter method name for the given property symbol.