Package org.openrewrite.kotlin.tree
Class KotlinTypeUtils
java.lang.Object
org.openrewrite.kotlin.tree.KotlinTypeUtils
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 TypeMethodDescriptionstatic booleanisAny(@Nullable org.openrewrite.java.tree.JavaType type) True whentypeiskotlin.Any/java.lang.Object.static booleanisAssignableTo(String to, @Nullable org.openrewrite.java.tree.JavaType from) TypeUtils.isAssignableTo(String, JavaType)that also recognises Kotlin built-in FQNs.static booleanisKotlinBoolean(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sBoolean— either as the JVM primitivebooleanor as the boxedjava.lang.Boolean.static booleanisKotlinByte(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sByte— either as the JVM primitivebyteor as the boxedjava.lang.Byte.static booleanisKotlinChar(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sChar— either as the JVM primitivecharor as the boxedjava.lang.Character.static booleanisKotlinDouble(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sDouble— either as the JVM primitivedoubleor as the boxedjava.lang.Double.static booleanisKotlinFloat(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sFloat— either as the JVM primitivefloator as the boxedjava.lang.Float.static booleanisKotlinInt(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sInt— either as the JVM primitiveintor as the boxedjava.lang.Integer.static booleanisKotlinLong(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sLong— either as the JVM primitivelongor as the boxedjava.lang.Long.static booleanisKotlinShort(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sShort— either as the JVM primitiveshortor as the boxedjava.lang.Short.static booleanisKotlinUnit(@Nullable org.openrewrite.java.tree.JavaType type) True whentypeis Kotlin'sUnitor the JVM'svoid.static booleanisOfClassType(@Nullable org.openrewrite.java.tree.JavaType type, String fqn) TypeUtils.isOfClassType(JavaType, String)that also recognises Kotlin built-in FQNs.static StringIffqnis a recognised Kotlin built-in name (e.g.static StringtoKotlinFqn(String fqn) Iffqnhas a canonical Kotlin alias (e.g.
-
Method Details
-
toJvmFqn
Iffqnis 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 returnsfqnunchanged. -
toKotlinFqn
Iffqnhas a canonical Kotlin alias (e.g.java.lang.Object), returns that alias (e.g.kotlin.Any). Otherwise returnsfqnunchanged. -
isOfClassType
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
TypeUtils.isAssignableTo(String, JavaType)that also recognises Kotlin built-in FQNs. Callers may pass either form forto; 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 whentypecorresponds to Kotlin'sInt— either as the JVM primitiveintor as the boxedjava.lang.Integer. -
isKotlinLong
public static boolean isKotlinLong(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sLong— either as the JVM primitivelongor as the boxedjava.lang.Long. -
isKotlinShort
public static boolean isKotlinShort(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sShort— either as the JVM primitiveshortor as the boxedjava.lang.Short. -
isKotlinByte
public static boolean isKotlinByte(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sByte— either as the JVM primitivebyteor as the boxedjava.lang.Byte. -
isKotlinFloat
public static boolean isKotlinFloat(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sFloat— either as the JVM primitivefloator as the boxedjava.lang.Float. -
isKotlinDouble
public static boolean isKotlinDouble(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sDouble— either as the JVM primitivedoubleor as the boxedjava.lang.Double. -
isKotlinBoolean
public static boolean isKotlinBoolean(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sBoolean— either as the JVM primitivebooleanor as the boxedjava.lang.Boolean. -
isKotlinChar
public static boolean isKotlinChar(@Nullable org.openrewrite.java.tree.JavaType type) True whentypecorresponds to Kotlin'sChar— either as the JVM primitivecharor as the boxedjava.lang.Character. -
isKotlinUnit
public static boolean isKotlinUnit(@Nullable org.openrewrite.java.tree.JavaType type) True whentypeis Kotlin'sUnitor the JVM'svoid. The Kotlin type model keepskotlin.Unitas a class in non-return positions; in return positions Kotlin's compiler normalises to JVMvoid. -
isAny
public static boolean isAny(@Nullable org.openrewrite.java.tree.JavaType type) True whentypeiskotlin.Any/java.lang.Object.
-