Class KotlinTypeUtils

java.lang.Object
org.openrewrite.kotlin.tree.KotlinTypeUtils

public final class KotlinTypeUtils extends Object
Kotlin-aware counterpart to TypeUtils.

KotlinTypeMapping produces JavaType instances that use JVM fully-qualified names (so kotlin.Any becomes java.lang.Object, kotlin.String becomes java.lang.String, and so on). That means Java-authored recipes matching on java.lang.Object / java.lang.String work uniformly over Kotlin sources.

Recipes written from the Kotlin author's perspective — e.g. ones that refer to kotlin.collections.List or kotlin.Int — should use the methods in this class so the Kotlin FQN is accepted as an alias for the JVM FQN that the type model actually carries.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isAny(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type is kotlin.Any / java.lang.Object.
    static boolean
    isAssignableTo(String to, @Nullable org.openrewrite.java.tree.JavaType from)
    TypeUtils.isAssignableTo(String, JavaType) that also recognises Kotlin built-in FQNs.
    static boolean
    isKotlinBoolean(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Boolean — either as the JVM primitive boolean or as the boxed java.lang.Boolean.
    static boolean
    isKotlinByte(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Byte — either as the JVM primitive byte or as the boxed java.lang.Byte.
    static boolean
    isKotlinChar(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Char — either as the JVM primitive char or as the boxed java.lang.Character.
    static boolean
    isKotlinDouble(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Double — either as the JVM primitive double or as the boxed java.lang.Double.
    static boolean
    isKotlinFloat(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Float — either as the JVM primitive float or as the boxed java.lang.Float.
    static boolean
    isKotlinInt(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Int — either as the JVM primitive int or as the boxed java.lang.Integer.
    static boolean
    isKotlinLong(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Long — either as the JVM primitive long or as the boxed java.lang.Long.
    static boolean
    isKotlinShort(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type corresponds to Kotlin's Short — either as the JVM primitive short or as the boxed java.lang.Short.
    static boolean
    isKotlinUnit(@Nullable org.openrewrite.java.tree.JavaType type)
    True when type is Kotlin's Unit or the JVM's void.
    static boolean
    isOfClassType(@Nullable org.openrewrite.java.tree.JavaType type, String fqn)
    TypeUtils.isOfClassType(JavaType, String) that also recognises Kotlin built-in FQNs.
    static String
    If fqn is a recognised Kotlin built-in name (e.g.
    static String
    If fqn has a canonical Kotlin alias (e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toJvmFqn

      public static String toJvmFqn(String fqn)
      If fqn is a recognised Kotlin built-in name (e.g. kotlin.Any), returns the JVM FQN that the type model uses for it (e.g. java.lang.Object). Otherwise returns fqn unchanged.
    • toKotlinFqn

      public static String toKotlinFqn(String fqn)
      If fqn has a canonical Kotlin alias (e.g. java.lang.Object), returns that alias (e.g. kotlin.Any). Otherwise returns fqn unchanged.
    • isOfClassType

      public static boolean isOfClassType(@Nullable org.openrewrite.java.tree.JavaType type, String fqn)
      TypeUtils.isOfClassType(JavaType, String) that also recognises Kotlin built-in FQNs. Callers may pass either the Kotlin name or the JVM name; both forms match types that carry the JVM representation. For Kotlin primitive FQNs (e.g. kotlin.Int) the match also accepts the JVM primitive (e.g. int), since the parser unboxes non-nullable primitive uses.
    • isAssignableTo

      public static boolean isAssignableTo(String to, @Nullable org.openrewrite.java.tree.JavaType from)
      TypeUtils.isAssignableTo(String, JavaType) that also recognises Kotlin built-in FQNs. Callers may pass either form for to; both are treated as equivalent when checking assignability against the JVM-oriented type model.
    • isKotlinInt

      public static boolean isKotlinInt(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Int — either as the JVM primitive int or as the boxed java.lang.Integer.
    • isKotlinLong

      public static boolean isKotlinLong(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Long — either as the JVM primitive long or as the boxed java.lang.Long.
    • isKotlinShort

      public static boolean isKotlinShort(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Short — either as the JVM primitive short or as the boxed java.lang.Short.
    • isKotlinByte

      public static boolean isKotlinByte(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Byte — either as the JVM primitive byte or as the boxed java.lang.Byte.
    • isKotlinFloat

      public static boolean isKotlinFloat(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Float — either as the JVM primitive float or as the boxed java.lang.Float.
    • isKotlinDouble

      public static boolean isKotlinDouble(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Double — either as the JVM primitive double or as the boxed java.lang.Double.
    • isKotlinBoolean

      public static boolean isKotlinBoolean(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Boolean — either as the JVM primitive boolean or as the boxed java.lang.Boolean.
    • isKotlinChar

      public static boolean isKotlinChar(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type corresponds to Kotlin's Char — either as the JVM primitive char or as the boxed java.lang.Character.
    • isKotlinUnit

      public static boolean isKotlinUnit(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type is Kotlin's Unit or the JVM's void. The Kotlin type model keeps kotlin.Unit as a class in non-return positions; in return positions Kotlin's compiler normalises to JVM void.
    • isAny

      public static boolean isAny(@Nullable org.openrewrite.java.tree.JavaType type)
      True when type is kotlin.Any / java.lang.Object.