Package org.checkerframework.javacutil
Class TypesUtils
java.lang.Object
org.checkerframework.javacutil.TypesUtils
A utility class that helps with
TypeMirrors. It complements Types, providing
methods that Types does not.-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareSame(TypeVariable typeVariable1, TypeVariable typeVariable2) Returns true if the two type variables are the same type variable.static booleanareSameDeclaredTypes(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 booleanareSamePrimitiveTypes(TypeMirror left, TypeMirror right) Returns true iff the arguments are both the same primitive type.static @Nullable TypeMirrorasSuper(TypeMirror type, TypeMirror superType, ProcessingEnvironment env) ReturnstypeassuperTypeifsuperTypeis a super type oftype; otherwise, null.static @BinaryName StringbinaryName(TypeMirror type) Returns the binary name of a type.static booleancanBeNarrowingPrimitiveConversion(TypeMirror type, Types types) Returns true if the type is byte, short, char, Byte, Short, or Character.static ArrayTypecreateArrayType(TypeMirror componentType, Types types) Returns anArrayTypewith elements of typecomponentType.static TypeMirrorcreateWildcard(TypeMirror lowerBound, TypeMirror upperBound, Types types) Creates a wildcard with the given bounds.static @Nullable TypeMirrorfindConcreteUpperBound(TypeMirror boundedType) Given a bounded type (wildcard or typevar) get the concrete type of its upper bound.static ExecutableElementfindFunction(TypeMirror functionalInterfaceType, ProcessingEnvironment env) This method returns the single abstract method declared byfunctionalInterfaceType.static ExecutableTypefindFunctionType(TypeMirror functionalInterfaceType, ProcessingEnvironment env) This method returns the type of the single abstract method declared byfunctionalInterfaceType.static TypeMirrorfreshTypeVariable(@Nullable TypeMirror upper, @Nullable TypeMirror lower, ProcessingEnvironment env) Creates a fresh type variable with boundsupperandlower.static TypeMirrorfreshTypeVariable(TypeMirror typeMirror, ProcessingEnvironment env) IftypeMirroris a wildcard, returns a fresh type variable that will be used as a captured type variable for it.static intgetArrayDepth(TypeMirror arrayType) Returns the depth of an array type.static @Nullable WildcardTypegetCapturedWildcard(TypeVariable typeVar) IftypeVaris a captured type variable, then returns its underlying wildcard; otherwise returnsnull.static Class<?> getClassFromType(TypeMirror typeMirror) Returns theClassfor a givenTypeMirror.static TypeMirrorGiven an array type, returns the type with all array levels stripped off.static @Nullable TypeMirrorgetMostSpecificArrayType(TypeMirror type, Types types) Returns the most specific supertype oftypethat is an array, or null iftypeis not a subtype of an array.static DeclaredTypeReturns theDeclaredTypeforjava.lang.Object.Returns the type of primitive conversion fromfromtoto.static @CanonicalNameOrEmpty StringgetQualifiedName(DeclaredType type) Gets the fully qualified name for a provided type.static @Nullable TypeMirrorgetSuperclass(TypeMirror type, Types types) Returns the superclass of the given class.static @Nullable DeclaredTypegetSuperClassOrInterface(TypeMirror type, Types types) Returns the superclass the given type.static @Nullable TypeElementgetTypeElement(TypeMirror type) Returns the type element fortypeiftypeis a class, interface, annotation type, or enum.static TypeMirrorgetTypeVariableLowerBound(TypeVariable typeVariable, ProcessingEnvironment env) Returns the lower bound oftypeVariable.static TypeMirrorgreatestLowerBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv) Returns the greatest lower bound of twoTypeMirrors, ignoring any annotations on the types.static booleanhasEnclosingType(TypeMirror type) Returns true iftypehas an enclosing type.static booleanReturns true iftypeis a wildcard with an explicit extends bound.static booleanReturns true iftypeis a wildcard with an explicit super bound.static booleanhasNoExplicitBound(TypeMirror type) Returns true iftypeis an unbounded wildcard.static booleanisAnonymous(TypeMirror type) Returns true iff the argument is an anonymous type.static booleanisBooleanType(TypeMirror type) Returns true if the type is eitherboolean(primitive type) orjava.lang.Boolean.static booleanisBoxedFloating(TypeMirror type) Returns true iff the argument is a boxed floating point type.static booleanisBoxedPrimitive(TypeMirror type) Check if thetyperepresents a boxed primitive type.static booleanisBoxOf(TypeMirror declaredType, TypeMirror primitiveType) Returns true if declaredType is a Class that is used to box primitive type (e.g.static booleanReturns true iftypeis a type variable created during capture conversion.static booleanisCharOrCharacter(TypeMirror type) Returns true if the type ischarorCharacter.static booleanisClass(TypeMirror type) Checks if the type represents the java.lang.Class declared type.static booleanisClassType(TypeMirror type) Returns whether a TypeMirror represents a class type.static booleanisCompoundType(TypeMirror type) Returns true if the given type is a compound type.static booleanisDeclaredOfName(TypeMirror type, CharSequence qualifiedName) Check if the type represents a declared type of the given qualified name.static booleanisDeclaredOfName(TypeMirror type, Collection<String> qualifiedNames) Check if the type represents a declared type whose fully-qualified name is any of the given names.static booleanisErasedSubtype(TypeMirror subtype, TypeMirror supertype, Types types) Returns true if the erased type ofsubtypeis a subtype of the erased type ofsupertype.static booleanisFloatingPoint(TypeMirror type) Return true if the argument TypeMirror is a (possibly boxed) floating point type.static booleanReturns true iff the argument is a primitive floating point type.static booleanisFunctionalInterface(TypeMirror type, ProcessingEnvironment env) Returns whether or nottypeis a functional interface type (as defined in JLS 9.8).static booleanReturn true if this is an immutable type in the JDK.static booleanReturn true if the argument TypeMirror is a (possibly boxed) integral type, excluding char and Character which do not print as numbers.static booleanReturns true iff the argument is an integral primitive type.static booleanReturns true iff the argument is an integral primitive type.static booleanReturn true if the argument TypeMirror is a (possibly boxed) integral type.static booleanisNumeric(TypeMirror type) Returns true iff the argument is a primitive numeric type.static booleanisNumericBoxed(TypeMirror type) Returns true iff the argument is a boxed numeric type.static booleanisObject(TypeMirror type) Checks if the type represents a java.lang.Object declared type.static booleanReturns true iftypeis a parameterized type.static booleanisPrimitive(TypeMirror type) Returns true iff the argument is a primitive type.static booleanisPrimitiveOrBoxed(TypeMirror type) Returns true iff the argument is a primitive type or a boxed primitive type.static booleanisRaw(TypeMirror type) Return whether or nottypeis raw.static booleanisString(TypeMirror type) Checks if the type represents a java.lang.String declared type.static booleanisThrowable(TypeMirror type) Returns true if type represents a Throwable type (e.g.static booleanisUnboundedOrExtendsBounded(WildcardType wildcardType) Returns true if this type is extends bounded or unbounded.static booleanisUnboundedOrSuperBounded(WildcardType wildcardType) Returns true if this type is super bounded or unbounded.static booleanisWildcardParameterized(TypeMirror typeMirror) Return true iftypeMirroris a declared type that has at least one wildcard as a type argument.static TypeMirrorleastUpperBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv) Returns the least upper bound of twoTypeMirrors, ignoring any annotations on the types.static @Nullable TypeMirrormostSpecific(List<TypeMirror> typeMirrors, ProcessingEnvironment processingEnv) Returns the most specific type from the list, or null if none exists.static List<TypeVariable> order(Collection<TypeVariable> collection, 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 StringsimpleTypeName(TypeMirror type) Returns the simple type name, without annotations but including array brackets.static TypeMirrorsubstitute(TypeMirror type, List<? extends TypeMirror> typeVariables, List<? extends TypeMirror> typeArgs, ProcessingEnvironment env) Returns a new type mirror with the same type astypewhere all the type variables intypeVariableshave been substituted with the type arguments intypeArgs.static TypeMirrorsubstituteMethodReturnType(Element methodElement, TypeMirror substitutedReceiverType, ProcessingEnvironment env) Returns the return type of a method, given the receiver of the method call.static TypeMirrortypeFromClass(Class<?> clazz, Types types, Elements elements) Returns theTypeMirrorfor a givenClass.static TypeMirrorupperBound(TypeMirror type) If the argument is a bounded TypeVariable or WildcardType, return its non-variable, non-wildcard upper bound.static @Nullable TypeParameterElementwildcardToTypeParam(com.sun.tools.javac.code.Type.WildcardType wildcard) Get the type parameter for this wildcard from the underlying type's bound field.static @Nullable TypeParameterElementwildcardToTypeParam(WildcardType wildcard) Get the type parameter for this wildcard from the underlying type's bound field.static com.sun.tools.javac.code.TypeVersion 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.TypeVersion of com.sun.tools.javac.code.Types.wildUpperBound(Type) that works with both jdk8 (called upperBound there) and jdk8u.
-
Method Details
-
typeFromClass
Returns theTypeMirrorfor a givenClass.- Parameters:
clazz- a classtypes- the type utilitieselements- the element utilities- Returns:
- the TypeMirror for
clazz
-
createArrayType
Returns anArrayTypewith elements of typecomponentType.- Parameters:
componentType- the component type of the created array typetypes- the type utilities- Returns:
- an
ArrayTypewhose elements have typecomponentType
-
getClassFromType
Returns theClassfor a givenTypeMirror. ReturnsObject.classif it cannot determine anything more specific.- Parameters:
typeMirror- a TypeMirror- Returns:
- the class for
typeMirror
-
getQualifiedName
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
Returns the simple type name, without annotations but including array brackets.- Parameters:
type- a type- Returns:
- the simple type name
-
binaryName
Returns the binary name of a type.- Parameters:
type- a type- Returns:
- its binary name
-
getTypeElement
Returns the type element fortypeiftypeis a class, interface, annotation type, or enum. Otherwise, returns null.- Parameters:
type- whose element is returned- Returns:
- the type element for
typeiftypeis a class, interface, annotation type, or enum; otherwise, returnsnull
-
getInnermostComponentType
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.ClassTypedoes 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
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
Checks if the type represents a java.lang.Object declared type.- Parameters:
type- the type- Returns:
- true iff type represents java.lang.Object
-
isClass
Checks if the type represents the java.lang.Class declared type.- Parameters:
type- the type- Returns:
- true iff type represents java.lang.Class
-
isString
Checks if the type represents a java.lang.String declared type.- Parameters:
type- the type- Returns:
- true iff type represents java.lang.String
-
isBooleanType
Returns true if the type is eitherboolean(primitive type) orjava.lang.Boolean.- Parameters:
type- the type to test- Returns:
- true iff type represents a boolean type
-
isCharOrCharacter
Returns true if the type ischarorCharacter.- Parameters:
type- a type- Returns:
- true if the type is
charorCharacter
-
isDeclaredOfName
Check if the type represents a declared type of the given qualified name.- Parameters:
type- the typequalifiedName- the name to checktypeagainst- Returns:
- true iff type represents a declared type of the qualified name
-
isDeclaredOfName
Check if the type represents a declared type whose fully-qualified name is any of the given names.- Parameters:
type- the typequalifiedNames- fully-qualified type names to check for- Returns:
- true iff type represents a declared type whose fully-qualified name is one of the given names
-
isBoxedPrimitive
Check if thetyperepresents a boxed primitive type.- Parameters:
type- the type to check- Returns:
- true iff type represents a boxed primitive type
-
isImmutableTypeInJdk
Return true if this is an immutable type in the JDK.This does not use immutability annotations and always returns false for user-defined classes.
-
isThrowable
Returns true if type represents a Throwable type (e.g. Exception, Error).- Returns:
- true if type represents a Throwable type (e.g. Exception, Error)
-
isAnonymous
Returns true iff the argument is an anonymous type.- Returns:
- whether the argument is an anonymous type
-
isPrimitive
Returns true iff the argument is a primitive type.- Parameters:
type- a type- Returns:
- whether the argument is a primitive type
-
isPrimitiveOrBoxed
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
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
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
Returns true iff the argument is an integral primitive type.- Parameters:
type- a type- Returns:
- whether the argument is an integral primitive type
-
isIntegralPrimitiveOrBoxed
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
-
isIntegralNumericPrimitive
Returns true iff the argument is an integral primitive type.- Parameters:
type- a type- Returns:
- whether the argument is an integral primitive type
-
isIntegralNumericOrBoxed
Return true if the argument TypeMirror is a (possibly boxed) integral type, excluding char and Character which do not print as numbers.- Parameters:
type- the type to inspect- Returns:
- true if type is an integral numeric type
-
isBoxOf
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
declaredTypeis a box ofprimitiveType
-
isBoxedFloating
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
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
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
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
Returns whether or nottypeis a functional interface type (as defined in JLS 9.8).- Parameters:
type- possible functional interface typeenv- the processing environment- Returns:
- whether or not
typeis a functional interface type (as defined in JLS 9.8)
-
isCompoundType
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
Returns true iftypehas an enclosing type.- Parameters:
type- type to checker- Returns:
- true if
typehas an enclosing type
-
upperBound
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
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,
nullotherwise
-
wildcardToTypeParam
public static @Nullable 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,
nullotherwise
-
wildUpperBound
public 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. -
getObjectTypeMirror
Returns theDeclaredTypeforjava.lang.Object.- Parameters:
env-ProcessingEnvironment- Returns:
- the
DeclaredTypeforjava.lang.Object
-
getTypeVariableLowerBound
public static TypeMirror getTypeVariableLowerBound(TypeVariable typeVariable, ProcessingEnvironment env) Returns the lower bound oftypeVariable. If it does not have a lower bound, returns the null type.- Parameters:
typeVariable- a type variableenv- the proceProcessingEnvironment- Returns:
- the lower bound of
typeVariableor the null type
-
wildLowerBound
public 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. -
findConcreteUpperBound
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
nullif this type is an unbounded wildcard
-
hasNoExplicitBound
Returns true iftypeis an unbounded wildcard.- Parameters:
type- the type to check- Returns:
- true if the given type is an unbounded wildcard
-
hasExplicitSuperBound
Returns true iftypeis a wildcard with an explicit super bound.- Parameters:
type- thetypeto test- Returns:
- true if
typeis explicitly super bounded
-
hasExplicitExtendsBound
Returns true iftypeis a wildcard with an explicit extends bound.- Parameters:
type- the type to test- Returns:
- true if
typeis a wildcard with an explicit extends bound
-
isUnboundedOrSuperBounded
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
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
Returns true if the erased type ofsubtypeis 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
Returns true iftypeis a type variable created during capture conversion.- Parameters:
type- a type mirror- Returns:
- true if
typeis a type variable created during capture conversion
-
getCapturedWildcard
IftypeVaris a captured type variable, then returns its underlying wildcard; otherwise returnsnull.- Parameters:
typeVar- a type variable that might be a captured type variable- Returns:
typeVaris a captured type variable, then returns its underlying wildcard; otherwise returnsnull
-
leastUpperBound
public static TypeMirror leastUpperBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv) Returns the least upper bound of twoTypeMirrors, ignoring any annotations on the types.Wrapper around Types.lub to add special handling for null types, primitives, and wildcards.
- Parameters:
tm1- aTypeMirrortm2- aTypeMirrorprocessingEnv- theProcessingEnvironmentto use- Returns:
- the least upper bound of
tm1andtm2
-
greatestLowerBound
public static TypeMirror greatestLowerBound(TypeMirror tm1, TypeMirror tm2, ProcessingEnvironment processingEnv) Returns the greatest lower bound of twoTypeMirrors, ignoring any annotations on the types.Wrapper around Types.glb to add special handling for null types, primitives, and wildcards.
- Parameters:
tm1- aTypeMirrortm2- aTypeMirrorprocessingEnv- theProcessingEnvironmentto use- Returns:
- the greatest lower bound of
tm1andtm2
-
mostSpecific
public static @Nullable TypeMirror mostSpecific(List<TypeMirror> typeMirrors, ProcessingEnvironment processingEnv) Returns the most specific type from the list, or null if none exists.- Parameters:
typeMirrors- a list of typesprocessingEnv- theProcessingEnvironmentto use- Returns:
- the most specific of the types, or null if none exists
-
substituteMethodReturnType
public static TypeMirror substituteMethodReturnType(Element methodElement, TypeMirror substitutedReceiverType, 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 TypeMirror asSuper(TypeMirror type, TypeMirror superType, ProcessingEnvironment env) ReturnstypeassuperTypeifsuperTypeis a super type oftype; otherwise, null.- Returns:
typeassuperTypeifsuperTypeis a super type oftype; otherwise, null
-
getSuperclass
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
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(PrimitiveType from, PrimitiveType to) Returns the type of primitive conversion fromfromtoto.- Parameters:
from- a primitive typeto- a primitive type- Returns:
- the type of primitive conversion from
fromtoto
-
substitute
public static TypeMirror substitute(TypeMirror type, List<? extends TypeMirror> typeVariables, List<? extends TypeMirror> typeArgs, ProcessingEnvironment env) Returns a new type mirror with the same type astypewhere all the type variables intypeVariableshave 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 oftypeArgstypeArgs- type mirrors that should replace the type variable at the same index oftypeVariablesenv- processing environment- Returns:
- a new type mirror with the same type as
typewhere all the type variables intypeVariableshave been substituted with the type arguments intypeArgs
-
getArrayDepth
Returns the depth of an array type.- Parameters:
arrayType- an array type- Returns:
- the depth of
arrayType
-
freshTypeVariable
IftypeMirroris a wildcard, returns a fresh type variable that will be used as a captured type variable for it. IftypeMirroris not a wildcard, returnstypeMirror.- Parameters:
typeMirror- a typeenv- processing environment- Returns:
- a fresh type variable if
typeMirroris a wildcard, otherwisetypeMirror
-
freshTypeVariable
public static TypeMirror freshTypeVariable(@Nullable TypeMirror upper, @Nullable TypeMirror lower, ProcessingEnvironment env) Creates a fresh type variable with boundsupperandlower.- Parameters:
upper- the upper bound to use, or ifnull, thenObjectis the upper boundlower- the lower bound to use, or ifnull, thenNullTypeis the lower boundenv- processing environment- Returns:
- a fresh type variable
-
order
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
-
findFunction
public static ExecutableElement findFunction(TypeMirror functionalInterfaceType, ProcessingEnvironment env) This method returns the single abstract method declared byfunctionalInterfaceType. (The type of this method is referred to as the function type.)- Parameters:
functionalInterfaceType- a functional interface typeenv- the processing environment- Returns:
- the single abstract method declared by the type
-
findFunctionType
public static ExecutableType findFunctionType(TypeMirror functionalInterfaceType, ProcessingEnvironment env) This method returns the type of the single abstract method declared byfunctionalInterfaceType.- Parameters:
functionalInterfaceType- functional interfaceenv- ProcessingEnvironment- Returns:
- the single abstract method declared by the type of the tree
-
isRaw
Return whether or nottypeis raw.- Parameters:
type- the type to check- Returns:
- whether or not
typeis raw
-
getMostSpecificArrayType
Returns the most specific supertype oftypethat is an array, or null iftypeis not a subtype of an array.- Parameters:
type- a typetypes- TypesUtils- Returns:
- the most specific supertype of
typethat is an array, or null iftypeis not a subtype of an array
-
isParameterizedType
Returns true iftypeis a parameterized type. A declared type is parameterized if it has parameters. An array type is parameterized if the inner-most component type has parameters.- Parameters:
type- type to check- Returns:
- true if
typeis a parameterized declared type or array type
-
isWildcardParameterized
Return true iftypeMirroris a declared type that has at least one wildcard as a type argument.- Parameters:
typeMirror- type to check- Returns:
- true if
typeMirroris a declared type that has at least one wildcard as a type argument
-
createWildcard
Creates a wildcard with the given bounds. IflowerBoundis non-null, theupperBoundmust benullorObject. IfupperBoundis non-null and notObject, thenlowerBoundmust benull;- Parameters:
lowerBound- the lower bound for the wildcardupperBound- the upper bound for the wildcardtypes- TypesUtils- Returns:
- a wildcard with the given bounds
-
canBeNarrowingPrimitiveConversion
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
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
TypeVariableobject 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
-