Package org.openrewrite.java.tree
Class TypeUtils
java.lang.Object
org.openrewrite.java.tree.TypeUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic JavaType.Arraystatic JavaType.Classstatic JavaType.FullyQualifiedasFullyQualified(@Nullable JavaType type) static JavaType.GenericTypeVariablestatic JavaType.ParameterizedasParameterized(@Nullable JavaType type) static JavaType.PrimitiveasPrimitive(@Nullable JavaType type) static Optional<JavaType.Method>findDeclaredMethod(JavaType.FullyQualified clazz, String name, List<JavaType> argumentTypes) static Optional<JavaType.Method>findOverriddenMethod(JavaType.Method method) Given a method type, searches the declaring type's parent and interfaces for a method with the same name and signature.static booleanfullyQualifiedNamesAreEqual(@Nullable String fqn1, @Nullable String fqn2) fullyQualifiedNamesAreEqualAsPredicate(@Nullable String fqn1) static booleanisAssignableTo(@Nullable JavaType to, @Nullable JavaType from) static booleanisAssignableTo(String to, @Nullable JavaType from) static booleanisAssignableTo(Pattern to, @Nullable JavaType from) static booleanisOfClassType(@Nullable JavaType type, String fqn) Returns true if the JavaType matches the FQN.static booleanReturns true if the JavaTypes are of the same type.static booleanisOfTypeWithName(JavaType.FullyQualified type, boolean matchOverride, Predicate<String> matcher) static booleanisOverride(JavaType.Method method) Determine if a method overrides a method from a superclass or interface.static booleanstatic booleanisWellFormedType(@Nullable JavaType type) Checks whether a type is non-null, non-unknown, and is composed entirely of non-null, non-unknown types.static booleanisWellFormedType(@Nullable JavaType type, Set<JavaType> seen) static JavaTypeunknownIfNull(@Nullable JavaType t) static JavaType.FullyQualified
-
Method Details
-
isString
-
fullyQualifiedNamesAreEqual
-
fullyQualifiedNamesAreEqualAsPredicate
-
isOfType
public static boolean isOfType(@Nullable @Nullable JavaType type1, @Nullable @Nullable JavaType type2) Returns true if the JavaTypes are of the same type.JavaType.Parameterizedwill be checked for both the FQN and each of the parameters.JavaType.GenericTypeVariablewill be checked forJavaType.GenericTypeVariable.Varianceand each of the bounds. -
isOfClassType
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 theObjecttype.- Returns:
- True if the declaring type matches the criteria of this matcher.
-
isAssignableTo
-
isAssignableTo
-
isAssignableTo
-
asClass
-
asParameterized
-
asArray
-
asGeneric
-
asPrimitive
-
asFullyQualified
-
isOverride
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
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
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
-
unknownIfNull
-
unknownIfNull
-