Skip to content

asPsiType

context(session: KaSession)
fun KaType.asPsiType(
    useSitePosition: PsiElement, 
    allowErrorTypes: Boolean, 
    mode: KaTypeMappingMode = KaTypeMappingMode.DEFAULT, 
    isAnnotationMethod: Boolean = false, 
    suppressWildcards: Boolean? = null, 
    preserveAnnotations: Boolean = true, 
    allowNonJvmPlatforms: Boolean = false
): PsiType?

Converts the given KaType to a PsiType in the context of the useSitePosition.

PsiType is JVM conception, so this method will return null for non-JVM platforms, unless allowNonJvmPlatforms is set.

Receiver

The KaType to convert.

Parameters

  • useSitePosition: Determines whether the given KaType needs to be approximated. For instance, if the given type is local but the use site is in the same local scope, we do not need to approximate the local type. However, when exposed to the public as a return type, the resulting type must be approximated accordingly.

  • allowErrorTypes: Determines whether the KaType should still be converted if it contains an error type. When this option is false, the result will be null if the KaType contains an error type. When true, erroneous types will be replaced with the error.NonExistentClass type.

  • suppressWildcards: Indicates whether wildcards in type arguments should be suppressed. This option works similar to adding a JvmSuppressWildcards annotation to the containing declaration.

  • true means they should be suppressed.

  • false means they should appear.

  • null means that the default applies, where wildcard suppression/appearance is determined by type annotations.

  • preserveAnnotations: Whether annotations from the original KaType should be included in the resulting PsiType with an appropriate conversion.

  • allowNonJvmPlatforms: Whether the PsiType should be computed even for non-JVM modules. The flag provides no validity guarantees – the returned type may be unresolvable from Java, or null.