Class TypeUtils

java.lang.Object
org.openrewrite.java.tree.TypeUtils

public class TypeUtils extends Object
  • Method Details

    • isObject

      public static boolean isObject(@Nullable JavaType type)
    • findQualifiedJavaLangTypeName

      public static @Nullable String findQualifiedJavaLangTypeName(String name)
    • isString

      public static boolean isString(@Nullable JavaType type)
    • toFullyQualifiedName

      public static String toFullyQualifiedName(String fqn)
    • fullyQualifiedNamesAreEqual

      public static boolean fullyQualifiedNamesAreEqual(@Nullable String fqn1, @Nullable String fqn2)
    • isOfType

      public static boolean isOfType(@Nullable JavaType type1, @Nullable JavaType type2)
      Returns true if the JavaTypes are of the same type. JavaType.Parameterized will be checked for both the FQN and each of the parameters. JavaType.GenericTypeVariable will be checked for JavaType.GenericTypeVariable.Variance and each of the bounds.
    • isOfType

      public static boolean isOfType(@Nullable JavaType type1, @Nullable JavaType type2, TypeUtils.ComparisonContext context)
    • isOfClassType

      public static boolean isOfClassType(@Nullable JavaType type, String fqn)
      Returns true if the JavaType matches the FQN.
    • isOfTypeWithName

      @Incubating(since="8.1.4") public static boolean isOfTypeWithName(@Nullable JavaType.FullyQualified type, boolean matchOverride, Predicate<String> matcher)
      Parameters:
      type - The declaring type of the method invocation or constructor.
      matchOverride - Whether to match the Object type.
      Returns:
      True if the declaring type matches the criteria of this matcher.
    • isAssignableTo

      public static boolean isAssignableTo(@Nullable JavaType to, @Nullable JavaType from)
    • isAssignableTo

      public static boolean isAssignableTo(@Nullable JavaType to, @Nullable JavaType from, TypeUtils.ComparisonContext context)
    • isAssignableTo

      public static boolean isAssignableTo(String to, @Nullable JavaType from)
    • isAssignableTo

      public static boolean isAssignableTo(Pattern to, @Nullable JavaType from)
    • isAssignableTo

      public static boolean isAssignableTo(Predicate<JavaType> predicate, @Nullable JavaType from)
    • asClass

      public static @Nullable JavaType.Class asClass(@Nullable JavaType type)
    • asParameterized

      public static @Nullable JavaType.Parameterized asParameterized(@Nullable JavaType type)
    • asArray

      public static @Nullable JavaType.Array asArray(@Nullable JavaType type)
    • asGeneric

      public static @Nullable JavaType.GenericTypeVariable asGeneric(@Nullable JavaType type)
    • asPrimitive

      public static @Nullable JavaType.Primitive asPrimitive(@Nullable JavaType type)
    • asFullyQualified

      public static @Nullable JavaType.FullyQualified asFullyQualified(@Nullable JavaType type)
    • isOverride

      public static boolean isOverride(@Nullable JavaType.Method method)
      Determine if a method overrides a method from a superclass or interface.
      Returns:
      `true` if a superclass or implemented interface declares a non-private method with matching signature. `false` if a match is not found or the method, declaring type, or generic signature is null.
    • findOverriddenMethod

      public static Optional<JavaType.Method> findOverriddenMethod(@Nullable JavaType.Method method)
      Given a method type, searches the declaring type's parent and interfaces for a method with the same name and signature.

      NOTE: This method will return an empty optional if the method, the method's declaring type, or the method's generic signature is null.

      Returns:
      An optional overridden method type declared in the parent.
    • findDeclaredMethod

      public static Optional<JavaType.Method> findDeclaredMethod(@Nullable JavaType.FullyQualified clazz, String name, List<JavaType> argumentTypes)
    • isWellFormedType

      public static boolean isWellFormedType(@Nullable JavaType type)
      Checks whether a type is non-null, non-unknown, and is composed entirely of non-null, non-unknown types.
      Returns:
      true when a type has no null, unknown, or invalid parts
    • isWellFormedType

      public static boolean isWellFormedType(@Nullable JavaType type, Set<JavaType> seen)
    • unknownIfNull

      public static JavaType.FullyQualified unknownIfNull(@Nullable JavaType.FullyQualified t)
    • unknownIfNull

      public static JavaType unknownIfNull(@Nullable JavaType t)
    • toString

      public static String toString(JavaType type)
    • toGenericTypeString

      public static String toGenericTypeString(JavaType.GenericTypeVariable type)