Package org.openrewrite.java.tree
Class TypeUtils
java.lang.Object
org.openrewrite.java.tree.TypeUtils
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable JavaType.Arraystatic @Nullable JavaType.Classstatic @Nullable JavaType.FullyQualifiedasFullyQualified(@Nullable JavaType type) static @Nullable JavaType.GenericTypeVariablestatic @Nullable JavaType.ParameterizedasParameterized(@Nullable JavaType type) static @Nullable JavaType.PrimitiveasPrimitive(@Nullable JavaType type) static Optional<JavaType.Method>findDeclaredMethod(@Nullable JavaType.FullyQualified clazz, String name, List<JavaType> argumentTypes) 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.static @Nullable Stringstatic booleanfullyQualifiedNamesAreEqual(@Nullable String fqn1, @Nullable String fqn2) static booleanisAssignableTo(@Nullable JavaType to, @Nullable JavaType from) static booleanisAssignableTo(@Nullable JavaType to, @Nullable JavaType from, TypeUtils.TypePosition position) static booleanisAssignableTo(String to, @Nullable JavaType from) static booleanisAssignableTo(Predicate<JavaType> predicate, @Nullable JavaType from) static booleanisAssignableTo(Pattern to, @Nullable JavaType from) static booleanstatic 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(@Nullable JavaType.FullyQualified type, boolean matchOverride, Predicate<String> matcher) static booleanisOverride(@Nullable 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 Stringstatic Stringstatic Stringstatic JavaTypeunknownIfNull(@Nullable JavaType t) static JavaType.FullyQualifiedunknownIfNull(@Nullable JavaType.FullyQualified t)
-
Method Details
-
isObject
-
findQualifiedJavaLangTypeName
-
isString
-
toFullyQualifiedName
-
fullyQualifiedNamesAreEqual
-
isOfType
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
public static boolean isAssignableTo(@Nullable JavaType to, @Nullable JavaType from, TypeUtils.TypePosition position) -
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
-
toString
-
toGenericTypeString
-