Java/Kotlin Bridging
Last modified: 01 August 2024note
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
.useSitePosition
is the context element used to gather additional information related to the Java type usage.Experimental API.
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.
useSitePosition
is 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.
Symbols
The Analysis API can create symbols for Java declarations.