public final class TypesUtils extends Object
TypeMirror
s.Modifier and Type | Method and Description |
---|---|
static boolean |
areSameDeclaredTypes(com.sun.tools.javac.code.Type.ClassType t1,
com.sun.tools.javac.code.Type.ClassType t2)
Returns true iff the arguments are both the same primitive types.
|
static boolean |
areSamePrimitiveTypes(TypeMirror left,
TypeMirror right)
Returns true iff the arguments are both the same primitive types.
|
static TypeMirror |
asSuper(TypeMirror type,
TypeMirror superType,
ProcessingEnvironment env) |
static ArrayType |
createArrayType(TypeMirror componentType,
Types types)
Returns an
ArrayType with elements of type componentType . |
static TypeMirror |
findConcreteUpperBound(TypeMirror boundedType)
Given a bounded type (wildcard or typevar) get the concrete type of its upper bound.
|
static WildcardType |
getCapturedWildcard(TypeVariable typeVar)
If typeVar is a captured wildcard, returns that wildcard; otherwise returns null.
|
static Name |
getQualifiedName(DeclaredType type)
Gets the fully qualified name for a provided type.
|
static TypeElement |
getTypeElement(TypeMirror type)
Returns the type element for
type if type is a class, interface, annotation
type, or enum. |
static TypeMirror |
greatestLowerBound(TypeMirror tm1,
TypeMirror tm2,
ProcessingEnvironment processingEnv)
Returns the greatest lower bound of two
TypeMirror s, ignoring any annotations on the
types. |
static boolean |
isAnonymous(TypeMirror type)
Returns true iff the argument is an anonymous type.
|
static boolean |
isBooleanType(TypeMirror type)
Checks if the type represents a boolean type, that is either boolean (primitive type) or
java.lang.Boolean.
|
static boolean |
isBoxedPrimitive(TypeMirror type) |
static boolean |
isBoxOf(TypeMirror declaredType,
TypeMirror primitiveType)
Returns true if declaredType is a Class that is used to box primitive type (e.g.
|
static boolean |
isCaptured(TypeMirror typeVar)
Returns whether a TypeVariable represents a captured type.
|
static boolean |
isClass(TypeMirror type)
Checks if the type represents a java.lang.Class declared type.
|
static boolean |
isClassType(TypeMirror type)
Returns whether a TypeMirror represents a class type.
|
static boolean |
isDeclaredOfName(TypeMirror type,
CharSequence qualifiedName)
Check if the type represents a declared type of the given qualified name.
|
static boolean |
isErasedSubtype(TypeMirror subtype,
TypeMirror supertype,
Types types)
Returns true if the erased type of subtype is a subtype of the erased type of supertype.
|
static boolean |
isFloating(TypeMirror type)
Returns true iff the argument is a floating point type.
|
static boolean |
isFunctionalInterface(TypeMirror type,
ProcessingEnvironment env)
Returns whether or not
type is a functional interface type (as defined in JLS 9.8). |
static boolean |
isIntegral(TypeMirror type)
Returns true iff the argument is an integral type.
|
static boolean |
isNumeric(TypeMirror type)
Returns true iff the argument is a primitive numeric type.
|
static boolean |
isObject(TypeMirror type)
Checks if the type represents a java.lang.Object declared type.
|
static boolean |
isPrimitive(TypeMirror type)
Returns true iff the argument is a primitive type.
|
static boolean |
isString(TypeMirror type)
Checks if the type represents a java.lang.String declared type.
|
static boolean |
isThrowable(TypeMirror type) |
static TypeMirror |
leastUpperBound(TypeMirror tm1,
TypeMirror tm2,
ProcessingEnvironment processingEnv)
Returns the least upper bound of two
TypeMirror s, ignoring any annotations on the
types. |
static TypeMirror |
substituteMethodReturnType(Element methodElement,
TypeMirror substitutedReceiverType,
ProcessingEnvironment env)
Returns the return type of a method, given the receiver of the method call.
|
static TypeMirror |
typeFromClass(Class<?> clazz,
Types types,
Elements elements)
Returns the
TypeMirror for a given Class . |
static TypeMirror |
upperBound(TypeMirror type)
If the argument is a bounded TypeVariable or WildcardType, return its non-variable,
non-wildcard upper bound.
|
static TypeKind |
widenedNumericType(TypeMirror left,
TypeMirror right)
Returns the widened numeric type for an arithmetic operation performed on a value of the left
type and the right type.
|
static TypeParameterElement |
wildcardToTypeParam(com.sun.tools.javac.code.Type.WildcardType wildcard)
Get the type parameter for this wildcard from the underlying type's bound field This field is
sometimes null, in that case this method will return null.
|
static com.sun.tools.javac.code.Type |
wildLowerBound(TypeMirror tm,
ProcessingEnvironment env)
Version of com.sun.tools.javac.code.Types.wildLowerBound(Type) that works with both jdk8
(called upperBound there) and jdk8u.
|
static com.sun.tools.javac.code.Type |
wildUpperBound(TypeMirror tm,
ProcessingEnvironment env)
Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) that works with both jdk8
(called upperBound there) and jdk8u.
|
public static Name getQualifiedName(DeclaredType type)
type
- the declared typepublic static boolean isObject(TypeMirror type)
type
- the typepublic static boolean isClass(TypeMirror type)
type
- the typepublic static boolean isString(TypeMirror type)
type
- the typepublic static boolean isBooleanType(TypeMirror type)
type
- the type to testpublic static boolean isDeclaredOfName(TypeMirror type, CharSequence qualifiedName)
type
- the typepublic static boolean isBoxedPrimitive(TypeMirror type)
public static boolean isThrowable(TypeMirror type)
public static boolean isAnonymous(TypeMirror type)
public static boolean isPrimitive(TypeMirror type)
public static boolean areSameDeclaredTypes(com.sun.tools.javac.code.Type.ClassType t1, com.sun.tools.javac.code.Type.ClassType t2)
This is needed because class Type.ClassType
does not override equals.
public static boolean areSamePrimitiveTypes(TypeMirror left, TypeMirror right)
public static boolean isNumeric(TypeMirror type)
public static boolean isIntegral(TypeMirror type)
public static boolean isFloating(TypeMirror type)
public static TypeKind widenedNumericType(TypeMirror left, TypeMirror right)
TypeKind
because creating
a TypeMirror
requires a Types
object from the ProcessingEnvironment
.public static TypeMirror upperBound(TypeMirror type)
type
- a typepublic static TypeParameterElement wildcardToTypeParam(com.sun.tools.javac.code.Type.WildcardType wildcard)
public static com.sun.tools.javac.code.Type wildUpperBound(TypeMirror tm, ProcessingEnvironment env)
public static com.sun.tools.javac.code.Type wildLowerBound(TypeMirror tm, ProcessingEnvironment env)
public static TypeMirror typeFromClass(Class<?> clazz, Types types, Elements elements)
TypeMirror
for a given Class
.public static ArrayType createArrayType(TypeMirror componentType, Types types)
ArrayType
with elements of type componentType
.public static boolean isBoxOf(TypeMirror declaredType, TypeMirror primitiveType)
public static TypeMirror findConcreteUpperBound(TypeMirror boundedType)
public static boolean isErasedSubtype(TypeMirror subtype, TypeMirror supertype, Types types)
subtype
- possible subtypesupertype
- possible supertypetypes
- a Types objectpublic static boolean isCaptured(TypeMirror typeVar)
public static WildcardType getCapturedWildcard(TypeVariable typeVar)
public static boolean isClassType(TypeMirror type)
public static TypeMirror leastUpperBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv)
TypeMirror
s, ignoring any annotations on the
types.
Wrapper around Types.lub to add special handling for null types, primitives, and wildcards.
tm1
- a TypeMirror
tm2
- a TypeMirror
processingEnv
- the ProcessingEnvironment
to usetm1
and tm2
.public static TypeMirror greatestLowerBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv)
TypeMirror
s, ignoring any annotations on the
types.
Wrapper around Types.glb to add special handling for null types, primitives, and wildcards.
tm1
- a TypeMirror
tm2
- a TypeMirror
processingEnv
- the ProcessingEnvironment
to usetm1
and tm2
.public static TypeMirror substituteMethodReturnType(Element methodElement, TypeMirror substitutedReceiverType, ProcessingEnvironment env)
public static TypeElement getTypeElement(TypeMirror type)
type
if type
is a class, interface, annotation
type, or enum. Otherwise, returns null.type
- whose element is returnedtype
if type
is a class, interface, annotation
type, or enum; otherwise, returns nullpublic static TypeMirror asSuper(TypeMirror type, TypeMirror superType, ProcessingEnvironment env)
type
as superType
if superType
is a super type of type
; otherwise, nullpublic static boolean isFunctionalInterface(TypeMirror type, ProcessingEnvironment env)
type
is a functional interface type (as defined in JLS 9.8).type
- possible functional interface typeenv
- ProcessingEnvironmenttype
is a functional interface type (as defined in JLS 9.8)