Class TypeUtils

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

public class TypeUtils extends Object
  • Method Details

    • isString

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

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

      public static Predicate<String> fullyQualifiedNamesAreEqualAsPredicate(@Nullable @Nullable String fqn1)
    • isOfType

      public static boolean isOfType(@Nullable @Nullable JavaType type1, @Nullable @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.
    • isOfClassType

      public static boolean isOfClassType(@Nullable @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 @Nullable JavaType to, @Nullable @Nullable JavaType from)
    • isAssignableTo

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

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

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

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

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

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

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

      @Nullable public static JavaType.FullyQualified asFullyQualified(@Nullable @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 @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 @Nullable JavaType type, Set<JavaType> seen)
    • unknownIfNull

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

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