Package org.checkerframework.javacutil
Class TypesUtils
- java.lang.Object
-
- org.checkerframework.javacutil.TypesUtils
-
public final class TypesUtils extends java.lang.Object
A utility class that helps withTypeMirror
s. It complementsTypes
, providing methods thatTypes
does not.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areSame(javax.lang.model.type.TypeVariable typeVariable1, javax.lang.model.type.TypeVariable typeVariable2)
Returns true if the two type variables are the same type variable.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 declared types.static boolean
areSamePrimitiveTypes(javax.lang.model.type.TypeMirror left, javax.lang.model.type.TypeMirror right)
Returns true iff the arguments are both the same primitive type.static @Nullable javax.lang.model.type.TypeMirror
asSuper(javax.lang.model.type.TypeMirror type, javax.lang.model.type.TypeMirror superType, javax.annotation.processing.ProcessingEnvironment env)
Returnstype
assuperType
ifsuperType
is a super type oftype
; otherwise, null.static @BinaryName java.lang.String
binaryName(javax.lang.model.type.TypeMirror type)
Returns the binary name.static boolean
canBeNarrowingPrimitiveConversion(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns true if the type is byte, short, char, Byte, Short, or Character.static javax.lang.model.type.ArrayType
createArrayType(javax.lang.model.type.TypeMirror componentType, javax.lang.model.util.Types types)
Returns anArrayType
with elements of typecomponentType
.static @Nullable javax.lang.model.type.TypeMirror
findConcreteUpperBound(javax.lang.model.type.TypeMirror boundedType)
Given a bounded type (wildcard or typevar) get the concrete type of its upper bound.static javax.lang.model.type.TypeMirror
freshTypeVariable(javax.lang.model.type.TypeMirror typeMirror, javax.annotation.processing.ProcessingEnvironment env)
IftypeMirror
is a wildcard, returns a fresh type variable that will be used as a captured type variable for it.static int
getArrayDepth(javax.lang.model.type.TypeMirror arrayType)
Returns the depth of an array type.static @Nullable javax.lang.model.type.WildcardType
getCapturedWildcard(javax.lang.model.type.TypeVariable typeVar)
IftypeVar
is a captured type variable, then returns its underlying wildcard; otherwise returnsnull
.static java.lang.Class<?>
getClassFromType(javax.lang.model.type.TypeMirror typeMirror)
Returns theClass
for a givenTypeMirror
.static javax.lang.model.type.TypeMirror
getInnermostComponentType(javax.lang.model.type.ArrayType at)
Given an array type, returns the type with all array levels stripped off.static javax.lang.model.type.DeclaredType
getObjectTypeMirror(javax.annotation.processing.ProcessingEnvironment env)
Returns theDeclaredType
forjava.lang.Object
.static TypeKindUtils.PrimitiveConversionKind
getPrimitiveConversionKind(javax.lang.model.type.PrimitiveType from, javax.lang.model.type.PrimitiveType to)
Returns the type of primitive conversion fromfrom
toto
.static @CanonicalNameOrEmpty java.lang.String
getQualifiedName(javax.lang.model.type.DeclaredType type)
Gets the fully qualified name for a provided type.static @Nullable javax.lang.model.type.TypeMirror
getSuperclass(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns the superclass of the given class.static @Nullable javax.lang.model.type.DeclaredType
getSuperClassOrInterface(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns the superclass the given type.static @Nullable javax.lang.model.element.TypeElement
getTypeElement(javax.lang.model.type.TypeMirror type)
Returns the type element fortype
iftype
is a class, interface, annotation type, or enum.static javax.lang.model.type.TypeMirror
greatestLowerBound(javax.lang.model.type.TypeMirror tm1, javax.lang.model.type.TypeMirror tm2, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the greatest lower bound of twoTypeMirror
s, ignoring any annotations on the types.static boolean
hasEnclosingType(javax.lang.model.type.TypeMirror type)
Returns true iftype
has an enclosing type.static boolean
hasExplicitExtendsBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a wildcard with an explicit extends bound.static boolean
hasExplicitSuperBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a wildcard with an explicit super bound.static boolean
hasNoExplicitBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is an unbounded wildcard.static boolean
isAnonymous(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is an anonymous type.static boolean
isBooleanType(javax.lang.model.type.TypeMirror type)
Returns true if the type is eitherboolean
(primitive type) orjava.lang.Boolean
.static boolean
isBoxedFloating(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a boxed floating point type.static boolean
isBoxedPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff thetype
represents a boxed primitive type.static boolean
isBoxOf(javax.lang.model.type.TypeMirror declaredType, javax.lang.model.type.TypeMirror primitiveType)
Returns true if declaredType is a Class that is used to box primitive type (e.g.static boolean
isCapturedTypeVariable(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a type variable created during capture conversion.static boolean
isCharType(javax.lang.model.type.TypeMirror type)
Returns true if the type ischar
orCharacter
.static boolean
isClass(javax.lang.model.type.TypeMirror type)
Return true iff the type represents a java.lang.Class declared type.static boolean
isClassType(javax.lang.model.type.TypeMirror type)
Returns whether a TypeMirror represents a class type.static boolean
isCompoundType(javax.lang.model.type.TypeMirror type)
Returns true if the given type is a compound type.static boolean
isDeclaredOfName(javax.lang.model.type.TypeMirror type, java.lang.CharSequence qualifiedName)
Returns true iff the type represents a declared type of the given qualified name.static boolean
isErasedSubtype(javax.lang.model.type.TypeMirror subtype, javax.lang.model.type.TypeMirror supertype, javax.lang.model.util.Types types)
Returns true if the erased type ofsubtype
is a subtype of the erased type ofsupertype
.static boolean
isFloatingPoint(javax.lang.model.type.TypeMirror type)
Return true if the argument TypeMirror is a (possibly boxed) floating point type.static boolean
isFloatingPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive floating point type.static boolean
isFunctionalInterface(javax.lang.model.type.TypeMirror type, javax.annotation.processing.ProcessingEnvironment env)
Returns whether or nottype
is a functional interface type (as defined in JLS 9.8).static boolean
isImmutableTypeInJdk(javax.lang.model.type.TypeMirror type)
Returns true iff this is an immutable type in the JDK.static boolean
isIntegralPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is an integral primitive type.static boolean
isIntegralPrimitiveOrBoxed(javax.lang.model.type.TypeMirror type)
Return true if the argument TypeMirror is a (possibly boxed) integral type.static boolean
isNumeric(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive numeric type.static boolean
isNumericBoxed(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a boxed numeric type.static boolean
isObject(javax.lang.model.type.TypeMirror type)
Returns true iff the type represents a java.lang.Object declared type.static boolean
isPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive type.static boolean
isPrimitiveOrBoxed(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive type or a boxed primitive type.static boolean
isString(javax.lang.model.type.TypeMirror type)
Returns true iff the type represents a java.lang.String declared type.static boolean
isThrowable(javax.lang.model.type.TypeMirror type)
Returns true iff type represents a Throwable type (e.g.static boolean
isUnboundedOrExtendsBounded(javax.lang.model.type.WildcardType wildcardType)
Returns true if this type is extends bounded or unbounded.static boolean
isUnboundedOrSuperBounded(javax.lang.model.type.WildcardType wildcardType)
Returns true if this type is super bounded or unbounded.static javax.lang.model.type.TypeMirror
leastUpperBound(javax.lang.model.type.TypeMirror tm1, javax.lang.model.type.TypeMirror tm2, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the least upper bound of twoTypeMirror
s, ignoring any annotations on the types.static @Nullable javax.lang.model.type.TypeMirror
mostSpecific(java.util.List<javax.lang.model.type.TypeMirror> typeMirrors, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the most specific type from the list, or null if none exists.static java.util.List<javax.lang.model.type.TypeVariable>
order(java.util.Collection<javax.lang.model.type.TypeVariable> collection, javax.lang.model.util.Types types)
Returns the list of type variables such that a type variable in the list only references type variables at a lower index than itself.static java.lang.String
simpleTypeName(javax.lang.model.type.TypeMirror type)
Returns the simple type name, without annotations.static javax.lang.model.type.TypeMirror
substitute(javax.lang.model.type.TypeMirror type, java.util.List<? extends javax.lang.model.type.TypeMirror> typeVariables, java.util.List<? extends javax.lang.model.type.TypeMirror> typeArgs, javax.annotation.processing.ProcessingEnvironment env)
Returns a new type mirror with the same type astype
where all the type variables intypeVariables
have been substituted with the type arguments intypeArgs
.static javax.lang.model.type.TypeMirror
substituteMethodReturnType(javax.lang.model.element.Element methodElement, javax.lang.model.type.TypeMirror substitutedReceiverType, javax.annotation.processing.ProcessingEnvironment env)
Returns the return type of a method, given the receiver of the method call.static javax.lang.model.type.TypeMirror
typeFromClass(java.lang.Class<?> clazz, javax.lang.model.util.Types types, javax.lang.model.util.Elements elements)
Returns theTypeMirror
for a givenClass
.static javax.lang.model.type.TypeMirror
upperBound(javax.lang.model.type.TypeMirror type)
If the argument is a bounded TypeVariable or WildcardType, return its non-variable, non-wildcard upper bound.static @Nullable javax.lang.model.element.TypeParameterElement
wildcardToTypeParam(com.sun.tools.javac.code.Type.WildcardType wildcard)
Get the type parameter for this wildcard from the underlying type's bound field.static @Nullable javax.lang.model.element.TypeParameterElement
wildcardToTypeParam(javax.lang.model.type.WildcardType wildcard)
Get the type parameter for this wildcard from the underlying type's bound field.static com.sun.tools.javac.code.Type
wildLowerBound(javax.lang.model.type.TypeMirror tm, javax.annotation.processing.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(javax.lang.model.type.TypeMirror tm, javax.annotation.processing.ProcessingEnvironment env)
Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) that works with both jdk8 (called upperBound there) and jdk8u.
-
-
-
Method Detail
-
typeFromClass
public static javax.lang.model.type.TypeMirror typeFromClass(java.lang.Class<?> clazz, javax.lang.model.util.Types types, javax.lang.model.util.Elements elements)
Returns theTypeMirror
for a givenClass
.- Parameters:
clazz
- a classtypes
- the type utilitieselements
- the element utilities- Returns:
- the TypeMirror for
clazz
-
createArrayType
public static javax.lang.model.type.ArrayType createArrayType(javax.lang.model.type.TypeMirror componentType, javax.lang.model.util.Types types)
Returns anArrayType
with elements of typecomponentType
.- Parameters:
componentType
- the component type of the created array typetypes
- the type utilities- Returns:
- an
ArrayType
whose elements have typecomponentType
-
getClassFromType
public static java.lang.Class<?> getClassFromType(javax.lang.model.type.TypeMirror typeMirror)
Returns theClass
for a givenTypeMirror
. ReturnsObject.class
if it cannot determine anything more specific.- Parameters:
typeMirror
- a TypeMirror- Returns:
- the class for
typeMirror
-
getQualifiedName
public static @CanonicalNameOrEmpty java.lang.String getQualifiedName(javax.lang.model.type.DeclaredType type)
Gets the fully qualified name for a provided type. It returns an empty name if type is an anonymous type.- Parameters:
type
- the declared type- Returns:
- the name corresponding to that type
-
simpleTypeName
public static java.lang.String simpleTypeName(javax.lang.model.type.TypeMirror type)
Returns the simple type name, without annotations.- Parameters:
type
- a type- Returns:
- the simple type name, without annotations
-
binaryName
public static @BinaryName java.lang.String binaryName(javax.lang.model.type.TypeMirror type)
Returns the binary name.- Parameters:
type
- a type- Returns:
- the binary name
-
getTypeElement
public static @Nullable javax.lang.model.element.TypeElement getTypeElement(javax.lang.model.type.TypeMirror type)
Returns the type element fortype
iftype
is a class, interface, annotation type, or enum. Otherwise, returns null.- Parameters:
type
- whose element is returned- Returns:
- the type element for
type
iftype
is a class, interface, annotation type, or enum; otherwise, returnsnull
-
getInnermostComponentType
public static javax.lang.model.type.TypeMirror getInnermostComponentType(javax.lang.model.type.ArrayType at)
Given an array type, returns the type with all array levels stripped off.- Parameters:
at
- an array type- Returns:
- the type with all array levels stripped off
-
areSameDeclaredTypes
public 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 declared types.This is needed because class
Type.ClassType
does not override equals.- Parameters:
t1
- the first type to testt2
- the second type to test- Returns:
- whether the arguments are the same declared types
-
areSamePrimitiveTypes
public static boolean areSamePrimitiveTypes(javax.lang.model.type.TypeMirror left, javax.lang.model.type.TypeMirror right)
Returns true iff the arguments are both the same primitive type.- Parameters:
left
- a typeright
- a type- Returns:
- whether the arguments are the same primitive type
-
isObject
public static boolean isObject(javax.lang.model.type.TypeMirror type)
Returns true iff the type represents a java.lang.Object declared type.- Parameters:
type
- the type to check- Returns:
- true iff type represents java.lang.Object
-
isClass
public static boolean isClass(javax.lang.model.type.TypeMirror type)
Return true iff the type represents a java.lang.Class declared type.- Parameters:
type
- the type to check- Returns:
- true iff type represents java.lang.Class
-
isString
public static boolean isString(javax.lang.model.type.TypeMirror type)
Returns true iff the type represents a java.lang.String declared type.- Parameters:
type
- the type to check- Returns:
- true iff type represents java.lang.String
-
isBooleanType
public static boolean isBooleanType(javax.lang.model.type.TypeMirror type)
Returns true if the type is eitherboolean
(primitive type) orjava.lang.Boolean
.- Parameters:
type
- the type to check- Returns:
- true iff type represents a boolean type
-
isCharType
public static boolean isCharType(javax.lang.model.type.TypeMirror type)
Returns true if the type ischar
orCharacter
.- Parameters:
type
- a type- Returns:
- true if the type is
char
orCharacter
-
isDeclaredOfName
public static boolean isDeclaredOfName(javax.lang.model.type.TypeMirror type, java.lang.CharSequence qualifiedName)
Returns true iff the type represents a declared type of the given qualified name.- Parameters:
type
- the type to check- Returns:
- type iff type represents a declared type of the qualified name
-
isBoxedPrimitive
public static boolean isBoxedPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff thetype
represents a boxed primitive type.- Parameters:
type
- the type to check- Returns:
- true iff type represents a boxed primitive type
-
isImmutableTypeInJdk
public static boolean isImmutableTypeInJdk(javax.lang.model.type.TypeMirror type)
Returns true iff this is an immutable type in the JDK.This does not use immutability annotations and always returns false for user-defined classes.
- Parameters:
type
- the type to check- Returns:
- true iff this is an immutable type in the JDK
-
isThrowable
public static boolean isThrowable(javax.lang.model.type.TypeMirror type)
Returns true iff type represents a Throwable type (e.g. Exception, Error).- Parameters:
type
- the type to check- Returns:
- true iff type represents a Throwable type (e.g. Exception, Error)
-
isAnonymous
public static boolean isAnonymous(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is an anonymous type.- Parameters:
type
- the type to check- Returns:
- whether the argument is an anonymous type
-
isPrimitive
public static boolean isPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive type.- Parameters:
type
- the type to check- Returns:
- whether the argument is a primitive type
-
isPrimitiveOrBoxed
public static boolean isPrimitiveOrBoxed(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive type or a boxed primitive type.- Parameters:
type
- a type- Returns:
- true if the argument is a primitive type or a boxed primitive type
-
isNumeric
public static boolean isNumeric(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive numeric type.- Parameters:
type
- a type- Returns:
- true if the argument is a primitive numeric type
-
isNumericBoxed
public static boolean isNumericBoxed(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a boxed numeric type.- Parameters:
type
- a type- Returns:
- true if the argument is a boxed numeric type
-
isIntegralPrimitive
public static boolean isIntegralPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is an integral primitive type.- Parameters:
type
- a type- Returns:
- whether the argument is an integral primitive type
-
isIntegralPrimitiveOrBoxed
public static boolean isIntegralPrimitiveOrBoxed(javax.lang.model.type.TypeMirror type)
Return true if the argument TypeMirror is a (possibly boxed) integral type.- Parameters:
type
- the type to inspect- Returns:
- true if type is an integral type
-
isBoxOf
public static boolean isBoxOf(javax.lang.model.type.TypeMirror declaredType, javax.lang.model.type.TypeMirror primitiveType)
Returns true if declaredType is a Class that is used to box primitive type (e.g. declaredType=java.lang.Double and primitiveType=22.5d )- Parameters:
declaredType
- a type that might be a boxed typeprimitiveType
- a type that might be a primitive type- Returns:
- true if
declaredType
is a box ofprimitiveType
-
isBoxedFloating
public static boolean isBoxedFloating(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a boxed floating point type.- Parameters:
type
- type to test- Returns:
- whether the argument is a boxed floating point type
-
isFloatingPrimitive
public static boolean isFloatingPrimitive(javax.lang.model.type.TypeMirror type)
Returns true iff the argument is a primitive floating point type.- Parameters:
type
- type mirror- Returns:
- whether the argument is a primitive floating point type
-
isFloatingPoint
public static boolean isFloatingPoint(javax.lang.model.type.TypeMirror type)
Return true if the argument TypeMirror is a (possibly boxed) floating point type.- Parameters:
type
- the type to inspect- Returns:
- true if type is a floating point type
-
isClassType
public static boolean isClassType(javax.lang.model.type.TypeMirror type)
Returns whether a TypeMirror represents a class type.- Parameters:
type
- a type that might be a class type- Returns:
- true if is a class type
-
isFunctionalInterface
public static boolean isFunctionalInterface(javax.lang.model.type.TypeMirror type, javax.annotation.processing.ProcessingEnvironment env)
Returns whether or nottype
is a functional interface type (as defined in JLS 9.8).- Parameters:
type
- possible functional interface typeenv
- the processing environment- Returns:
- whether or not
type
is a functional interface type (as defined in JLS 9.8)
-
isCompoundType
public static boolean isCompoundType(javax.lang.model.type.TypeMirror type)
Returns true if the given type is a compound type.- Parameters:
type
- a type- Returns:
- true if the given type is a compound type
-
hasEnclosingType
public static boolean hasEnclosingType(javax.lang.model.type.TypeMirror type)
Returns true iftype
has an enclosing type.- Parameters:
type
- type to checker- Returns:
- true if
type
has an enclosing type
-
upperBound
public static javax.lang.model.type.TypeMirror upperBound(javax.lang.model.type.TypeMirror type)
If the argument is a bounded TypeVariable or WildcardType, return its non-variable, non-wildcard upper bound. Otherwise, return the type itself.- Parameters:
type
- a type- Returns:
- the non-variable, non-wildcard upper bound of a type, if it has one, or itself if it has no bounds
-
wildcardToTypeParam
public static @Nullable javax.lang.model.element.TypeParameterElement wildcardToTypeParam(javax.lang.model.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.- Parameters:
wildcard
- wildcard type- Returns:
- the TypeParameterElement the wildcard is an argument to,
null
otherwise
-
wildcardToTypeParam
public static @Nullable javax.lang.model.element.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.- Parameters:
wildcard
- wildcard type- Returns:
- the TypeParameterElement the wildcard is an argument to,
null
otherwise
-
wildUpperBound
public static com.sun.tools.javac.code.Type wildUpperBound(javax.lang.model.type.TypeMirror tm, javax.annotation.processing.ProcessingEnvironment env)
Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) that works with both jdk8 (called upperBound there) and jdk8u.
-
getObjectTypeMirror
public static javax.lang.model.type.DeclaredType getObjectTypeMirror(javax.annotation.processing.ProcessingEnvironment env)
Returns theDeclaredType
forjava.lang.Object
.- Parameters:
env
-ProcessingEnvironment
- Returns:
- the
DeclaredType
forjava.lang.Object
-
wildLowerBound
public static com.sun.tools.javac.code.Type wildLowerBound(javax.lang.model.type.TypeMirror tm, javax.annotation.processing.ProcessingEnvironment env)
Version of com.sun.tools.javac.code.Types.wildLowerBound(Type) that works with both jdk8 (called upperBound there) and jdk8u.
-
findConcreteUpperBound
public static @Nullable javax.lang.model.type.TypeMirror findConcreteUpperBound(javax.lang.model.type.TypeMirror boundedType)
Given a bounded type (wildcard or typevar) get the concrete type of its upper bound. If the bounded type extends other bounded types, this method will iterate through their bounds until a class, interface, or intersection is found.- Returns:
- a type that is not a wildcard or typevar, or
null
if this type is an unbounded wildcard
-
hasNoExplicitBound
public static boolean hasNoExplicitBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is an unbounded wildcard.- Parameters:
type
- the type to check- Returns:
- true if the given type is an unbounded wildcard
-
hasExplicitSuperBound
public static boolean hasExplicitSuperBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a wildcard with an explicit super bound.- Parameters:
type
- thetype
to test- Returns:
- true if
type
is explicitly super bounded
-
hasExplicitExtendsBound
public static boolean hasExplicitExtendsBound(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a wildcard with an explicit extends bound.- Parameters:
type
- the type to test- Returns:
- true if
type
is a wildcard with an explicit extends bound
-
isUnboundedOrSuperBounded
public static boolean isUnboundedOrSuperBounded(javax.lang.model.type.WildcardType wildcardType)
Returns true if this type is super bounded or unbounded.- Parameters:
wildcardType
- the wildcard type to test- Returns:
- true if this type is super bounded or unbounded
-
isUnboundedOrExtendsBounded
public static boolean isUnboundedOrExtendsBounded(javax.lang.model.type.WildcardType wildcardType)
Returns true if this type is extends bounded or unbounded.- Parameters:
wildcardType
- the wildcard type to test- Returns:
- true if this type is extends bounded or unbounded
-
isErasedSubtype
public static boolean isErasedSubtype(javax.lang.model.type.TypeMirror subtype, javax.lang.model.type.TypeMirror supertype, javax.lang.model.util.Types types)
Returns true if the erased type ofsubtype
is a subtype of the erased type ofsupertype
.- Parameters:
subtype
- possible subtypesupertype
- possible supertypetypes
- a Types object- Returns:
- true if the erased type of subtype is a subtype of the erased type of supertype
-
isCapturedTypeVariable
public static boolean isCapturedTypeVariable(javax.lang.model.type.TypeMirror type)
Returns true iftype
is a type variable created during capture conversion.- Parameters:
type
- a type mirror- Returns:
- true if
type
is a type variable created during capture conversion
-
getCapturedWildcard
public static @Nullable javax.lang.model.type.WildcardType getCapturedWildcard(javax.lang.model.type.TypeVariable typeVar)
IftypeVar
is a captured type variable, then returns its underlying wildcard; otherwise returnsnull
.- Parameters:
typeVar
- a type variable that might be a captured type variable- Returns:
typeVar
is a captured type variable, then returns its underlying wildcard; otherwise returnsnull
-
leastUpperBound
public static javax.lang.model.type.TypeMirror leastUpperBound(javax.lang.model.type.TypeMirror tm1, javax.lang.model.type.TypeMirror tm2, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the least upper bound of twoTypeMirror
s, ignoring any annotations on the types.Wrapper around Types.lub to add special handling for null types, primitives, and wildcards.
- Parameters:
tm1
- aTypeMirror
tm2
- aTypeMirror
processingEnv
- theProcessingEnvironment
to use- Returns:
- the least upper bound of
tm1
andtm2
-
greatestLowerBound
public static javax.lang.model.type.TypeMirror greatestLowerBound(javax.lang.model.type.TypeMirror tm1, javax.lang.model.type.TypeMirror tm2, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the greatest lower bound of twoTypeMirror
s, ignoring any annotations on the types.Wrapper around Types.glb to add special handling for null types, primitives, and wildcards.
- Parameters:
tm1
- aTypeMirror
tm2
- aTypeMirror
processingEnv
- theProcessingEnvironment
to use- Returns:
- the greatest lower bound of
tm1
andtm2
-
mostSpecific
public static @Nullable javax.lang.model.type.TypeMirror mostSpecific(java.util.List<javax.lang.model.type.TypeMirror> typeMirrors, javax.annotation.processing.ProcessingEnvironment processingEnv)
Returns the most specific type from the list, or null if none exists.- Parameters:
typeMirrors
- a list of typesprocessingEnv
- theProcessingEnvironment
to use- Returns:
- the most specific of the types, or null if none exists
-
substituteMethodReturnType
public static javax.lang.model.type.TypeMirror substituteMethodReturnType(javax.lang.model.element.Element methodElement, javax.lang.model.type.TypeMirror substitutedReceiverType, javax.annotation.processing.ProcessingEnvironment env)
Returns the return type of a method, given the receiver of the method call.- Parameters:
methodElement
- a methodsubstitutedReceiverType
- the receiver type, after substitutionenv
- the environment- Returns:
- the return type of the method
-
asSuper
public static @Nullable javax.lang.model.type.TypeMirror asSuper(javax.lang.model.type.TypeMirror type, javax.lang.model.type.TypeMirror superType, javax.annotation.processing.ProcessingEnvironment env)
Returnstype
assuperType
ifsuperType
is a super type oftype
; otherwise, null.- Returns:
type
assuperType
ifsuperType
is a super type oftype
; otherwise, null
-
getSuperclass
public static @Nullable javax.lang.model.type.TypeMirror getSuperclass(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns the superclass of the given class. Returns null if there is not one.- Parameters:
type
- a typetypes
- type utilities- Returns:
- the superclass of the given class, or null
-
getSuperClassOrInterface
public static @Nullable javax.lang.model.type.DeclaredType getSuperClassOrInterface(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns the superclass the given type. If there is no superclass the first interface returned byTypes.directSupertypes(TypeMirror)
is returned. If the type has neither a superclass nor a superinterface, then null is returned.- Parameters:
type
- a typetypes
- type utilities- Returns:
- the superclass or super interface of the given type, or null
-
getPrimitiveConversionKind
public static TypeKindUtils.PrimitiveConversionKind getPrimitiveConversionKind(javax.lang.model.type.PrimitiveType from, javax.lang.model.type.PrimitiveType to)
Returns the type of primitive conversion fromfrom
toto
.- Parameters:
from
- a primitive typeto
- a primitive type- Returns:
- the type of primitive conversion from
from
toto
-
substitute
public static javax.lang.model.type.TypeMirror substitute(javax.lang.model.type.TypeMirror type, java.util.List<? extends javax.lang.model.type.TypeMirror> typeVariables, java.util.List<? extends javax.lang.model.type.TypeMirror> typeArgs, javax.annotation.processing.ProcessingEnvironment env)
Returns a new type mirror with the same type astype
where all the type variables intypeVariables
have been substituted with the type arguments intypeArgs
.This is a wrapper around
Types.subst(Type, com.sun.tools.javac.util.List, com.sun.tools.javac.util.List)
.- Parameters:
type
- type to do substitution intypeVariables
- type variables that should be replaced with the type mirror at the same index oftypeArgs
typeArgs
- type mirrors that should replace the type variable at the same index oftypeVariables
env
- processing environment- Returns:
- a new type mirror with the same type as
type
where all the type variables intypeVariables
have been substituted with the type arguments intypeArgs
-
getArrayDepth
public static int getArrayDepth(javax.lang.model.type.TypeMirror arrayType)
Returns the depth of an array type.- Parameters:
arrayType
- an array type- Returns:
- the depth of
arrayType
-
freshTypeVariable
public static javax.lang.model.type.TypeMirror freshTypeVariable(javax.lang.model.type.TypeMirror typeMirror, javax.annotation.processing.ProcessingEnvironment env)
IftypeMirror
is a wildcard, returns a fresh type variable that will be used as a captured type variable for it. IftypeMirror
is not a wildcard, returnstypeMirror
.- Parameters:
typeMirror
- a typeenv
- processing environment- Returns:
- a fresh type variable if
typeMirror
is a wildcard, otherwisetypeMirror
-
order
public static java.util.List<javax.lang.model.type.TypeVariable> order(java.util.Collection<javax.lang.model.type.TypeVariable> collection, javax.lang.model.util.Types types)
Returns the list of type variables such that a type variable in the list only references type variables at a lower index than itself.- Parameters:
collection
- a collection of type variablestypes
- type utilities- Returns:
- the type variables ordered so that each type variable only references earlier type variables
-
canBeNarrowingPrimitiveConversion
public static boolean canBeNarrowingPrimitiveConversion(javax.lang.model.type.TypeMirror type, javax.lang.model.util.Types types)
Returns true if the type is byte, short, char, Byte, Short, or Character. All other narrowings require a cast. See JLS 5.1.3.- Parameters:
type
- a typetypes
- the type utilities- Returns:
- true if assignment to the type may be a narrowing
-
areSame
@EqualsMethod public static boolean areSame(javax.lang.model.type.TypeVariable typeVariable1, javax.lang.model.type.TypeVariable typeVariable2)
Returns true if the two type variables are the same type variable. Meaning they have the same name and the same enclosing element. UnlikeTypes.isSameType(TypeMirror, TypeMirror)
, they do not have to be the same object.This method is needed when a type has gone through type variable substitution, but only some of the type variables were substituted. Also, a new
TypeVariable
object is created as the type of a tree created byTreeBuilder
.- Parameters:
typeVariable1
- a type variabletypeVariable2
- a type variable- Returns:
- if the two type variables are the same type variable
-
-