Modifier and Type | Method and Description |
---|---|
static void |
applyAnnotationsFromDeclaredType(AnnotatedTypeMirror.AnnotatedDeclaredType annotatedDeclaredType,
DeclaredType declaredType)
Add all the annotations in
declaredType to annotatedDeclaredType . |
static boolean |
areCorrespondingTypeVariables(Elements elements,
AnnotatedTypeMirror.AnnotatedTypeVariable type1,
AnnotatedTypeMirror.AnnotatedTypeVariable type2)
When overriding a method, you must include the same number of type parameters as the base
method.
|
static AnnotatedTypeMirror |
asMemberOf(Types types,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror t,
Element elem)
Returns the type of an element when that element is viewed as a member of, or otherwise
directly contained by, a given type.
|
static AnnotatedTypeMirror |
asMemberOf(Types types,
AnnotatedTypeFactory atypeFactory,
@Nullable AnnotatedTypeMirror t,
Element elem,
AnnotatedTypeMirror elemType)
Returns the type of an element when that element is viewed as a member of, or otherwise
directly contained by, a given type.
|
static AnnotatedTypeMirror.AnnotatedExecutableType |
asMemberOf(Types types,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror t,
ExecutableElement elem)
Specialization of
asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror,
Element) with more precise return type. |
static AnnotatedTypeMirror.AnnotatedExecutableType |
asMemberOf(Types types,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror t,
ExecutableElement elem,
AnnotatedTypeMirror.AnnotatedExecutableType type)
Specialization of
asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror,
Element, AnnotatedTypeMirror) with more precise return type. |
static <T extends AnnotatedTypeMirror> |
asSuper(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type,
T superType)
Copies annotations from
type to a copy of superType where the type variables
of superType have been substituted. |
static <T extends AnnotatedTypeMirror> |
castedAsSuper(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror subtype,
T supertype)
Calls asSuper and casts the result to the same type as the input supertype.
|
static boolean |
containsModifier(AnnotatedTypeMirror type,
AnnotationMirror modifier)
Checks whether type contains the given modifier, also recursively in type arguments and
arrays.
|
static void |
copyOnlyExplicitConstructorAnnotations(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror.AnnotatedDeclaredType returnType,
AnnotatedTypeMirror.AnnotatedExecutableType constructor)
Copies explicit annotations and annotations resulting from resolution of polymorphic
qualifiers from
constructor to returnType . |
static List<AnnotatedTypeMirror> |
expandVarArgs(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror.AnnotatedExecutableType method,
List<? extends ExpressionTree> args)
Returns the method parameters for the invoked method, with the same number of arguments
passed in the methodInvocation tree.
|
static List<AnnotatedTypeMirror> |
expandVarArgsFromTypes(AnnotatedTypeMirror.AnnotatedExecutableType method,
List<AnnotatedTypeMirror> args) |
static AnnotationMirror |
findEffectiveAnnotationInHierarchy(QualifierHierarchy qualifierHierarchy,
AnnotatedTypeMirror toSearch,
AnnotationMirror top)
When comparing types against the bounds of a type variable, we may encounter other type
variables, wildcards, and intersections in those bounds.
|
static AnnotationMirror |
findEffectiveAnnotationInHierarchy(QualifierHierarchy qualifierHierarchy,
AnnotatedTypeMirror toSearch,
AnnotationMirror top,
boolean canBeEmpty)
When comparing types against the bounds of a type variable, we may encounter other type
variables, wildcards, and intersections in those bounds.
|
static Set<AnnotationMirror> |
findEffectiveAnnotations(QualifierHierarchy qualifierHierarchy,
AnnotatedTypeMirror toSearch)
When comparing types against the bounds of a type variable, we may encounter other type
variables, wildcards, and intersections in those bounds.
|
static Set<AnnotationMirror> |
findEffectiveLowerBoundAnnotations(QualifierHierarchy qualifierHierarchy,
AnnotatedTypeMirror toSearch)
When comparing types against the bounds of a type variable, we may encounter other type
variables, wildcards, and intersections in those bounds.
|
static Map<TypeVariable,AnnotatedTypeMirror> |
findTypeArguments(ProcessingEnvironment processingEnv,
AnnotatedTypeFactory atypeFactory,
ExpressionTree expr,
ExecutableElement elt,
AnnotatedTypeMirror.AnnotatedExecutableType preType)
Given a method or constructor invocation, return a mapping of the type variables to their
type arguments, if any exist.
|
static AnnotatedTypeMirror |
getAnnotatedTypeMirrorOfParameter(AnnotatedTypeMirror.AnnotatedExecutableType methodType,
int index)
Given an AnnotatedExecutableType of a method or constructor declaration, get the parameter
type expect at the indexth position (unwrapping var args if necessary).
|
static List<AnnotatedTypeMirror> |
getAnnotatedTypes(AnnotatedTypeFactory atypeFactory,
List<AnnotatedTypeMirror> paramTypes,
List<? extends ExpressionTree> trees)
Return a list of the AnnotatedTypeMirror of the passed expression trees, in the same order as
the trees.
|
static int |
getArrayDepth(AnnotatedTypeMirror.AnnotatedArrayType array)
Returns the depth of the array type of the provided array.
|
static AnnotatedTypeMirror |
getIteratedType(ProcessingEnvironment processingEnv,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror iterableType)
Returns the iterated type of the passed iterable type, and throws
IllegalArgumentException if the passed type is not iterable. |
static Set<AnnotatedTypeMirror.AnnotatedDeclaredType> |
getSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)
Returns all the supertypes (direct or indirect) of the given declared type.
|
static Set<AnnotationMirror> |
glbOfBounds(AnnotatedTypeMirror.AnnotatedIntersectionType isect,
QualifierHierarchy qualifierHierarchy)
Gets the lowest primary annotation of all bounds in the intersection.
|
static boolean |
hasExplicitExtendsBound(AnnotatedTypeMirror wildcard)
This method identifies wildcard types that have an explicit extends bound.
|
static boolean |
hasExplicitSuperBound(AnnotatedTypeMirror wildcard)
This method identifies wildcard types that have an explicit super bound.
|
static boolean |
hasNoExplicitBound(AnnotatedTypeMirror wildcard)
This method identifies wildcard types that are unbound.
|
static boolean |
haveSameDeclaration(Types types,
AnnotatedTypeMirror.AnnotatedTypeVariable typeVar1,
AnnotatedTypeMirror.AnnotatedTypeVariable typeVar2)
Returns true if the typeVar1 and typeVar2 are two uses of the same type variable.
|
static boolean |
implementsAnnotation(AnnotatedTypeMirror atm)
Returns true if atm is an Annotation interface, i.e.
|
static AnnotatedTypeMirror |
innerMostType(AnnotatedTypeMirror t) |
static boolean |
isDeclarationOfJavaLangEnum(Types types,
Elements elements,
AnnotatedTypeMirror typeMirror) |
static boolean |
isEnum(AnnotatedTypeMirror typeMirror) |
static boolean |
isExplicitlyExtendsBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
Returns true if wildcard type was explicitly unbounded.
|
static boolean |
isExplicitlySuperBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType) |
static boolean |
isJavaLangAnnotation(AnnotatedTypeMirror atm)
Returns true if the underlying type of this atm is a java.lang.annotation.Annotation.
|
static boolean |
isUnboundedOrExtendsBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
Returns true if this type is extends bounded or unbounded.
|
static boolean |
isUnboundedOrSuperBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
Returns true if this type is super bounded or unbounded.
|
static AnnotatedTypeMirror |
leastUpperBound(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2)
Returns the lub of two annotated types.
|
static AnnotatedTypeMirror |
leastUpperBound(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2,
TypeMirror lubTypeMirror)
Returns the lub, whose underlying type is
lubTypeMirror of two annotated types. |
static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> |
overriddenMethods(Elements elements,
AnnotatedTypeFactory atypeFactory,
ExecutableElement method)
Given a method, return the methods that it overrides.
|
static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> |
overriddenMethods(Elements elements,
ExecutableElement method,
Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
Given a method and all supertypes (recursively) of the method's containing class, returns the
methods that the method overrides.
|
public static <T extends AnnotatedTypeMirror> T asSuper(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type, T superType)
type
to a copy of superType
where the type variables
of superType
have been substituted. How the annotations are copied depends on the
kinds of AnnotatedTypeMirrors given. Generally, if type
and superType
are
both declared types, asSuper is called recursively on the direct super types, see AnnotatedTypeMirror.directSuperTypes()
, of type
until type
's erased Java
type is the same as superType
's erased super type. Then type is returned
. For
compound types, asSuper is called recursively on components.
Preconditions:
superType
may have annotations, but they are ignored.
type
may not be an instanceof AnnotatedNullType, because if superType
is a
compound type, the annotations on the component types are undefined.
The underlying type
(ie the Java type) of type
should be a subtype (or the
same type) of the underlying type of superType
. Except for these cases:
type
is a primitive, then the boxed type of type
must be subtype of
superType
.
superType
is a primitive, then type
must be convertible to superType
.
superType
is a type variable or wildcard without a lower bound, then type
must be a subtype of the upper bound of superType
. (This relaxed rule is
used during type argument inference where the type variable or wildcard is the type
argument that was inferred.)
superType
is a wildcard with a lower bound, then type
must be a
subtype of the lower bound of superType
.
Postconditions: type
and superType
are not modified.
atypeFactory
- AnnotatedTypeFactory
type
- type from which to copy annotationssuperType
- a type whose erased Java type is a supertype of type
's erased Java
type.superType
with annotations copied from type
and type variables
substituted from type
.public static <T extends AnnotatedTypeMirror> T castedAsSuper(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror subtype, T supertype)
T
- the type of supertype and return typesubtype
- subtype to be transformed to supertypesupertype
- supertype that subtype is transformed topublic static boolean hasNoExplicitBound(AnnotatedTypeMirror wildcard)
public static boolean hasExplicitSuperBound(AnnotatedTypeMirror wildcard)
public static boolean hasExplicitExtendsBound(AnnotatedTypeMirror wildcard)
public static AnnotatedTypeMirror.AnnotatedExecutableType asMemberOf(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror t, ExecutableElement elem)
asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror,
Element)
with more precise return type.types
- the Types instance to useatypeFactory
- the type factory to uset
- the receiver typeelem
- the element that should be viewed as member of tasMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
public static AnnotatedTypeMirror.AnnotatedExecutableType asMemberOf(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror t, ExecutableElement elem, AnnotatedTypeMirror.AnnotatedExecutableType type)
asMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror,
Element, AnnotatedTypeMirror)
with more precise return type.types
- the Types instance to useatypeFactory
- the type factory to uset
- the receiver typeelem
- the element that should be viewed as member of ttype
- unsubstituted type of memberasMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element,
AnnotatedTypeMirror)
public static AnnotatedTypeMirror asMemberOf(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror t, Element elem)
For example, when viewed as a member of the parameterized type Set<@NonNull
String>
, the Set.add
method is an ExecutableType
whose parameter is of type
@NonNull String
.
The result is customized according to the type system semantics, according to AnnotatedTypeFactory.postAsMemberOf(AnnotatedTypeMirror, AnnotatedTypeMirror, Element)
.
Note that this method does not currently return (top level) captured types for type parameters, parameters, and return types. Instead, the original wildcard is returned, or sometimes inferring type arguments will create a wildcard type which is returned. The bounds of an inferred wildcard may itself have captures.
To prevent unsoundness, the rest of the checker framework must expect wildcard in places where captures should appear (like type arguments). This should just involve the bounds of the wildcard where the bounds of the capture would have been used.
types
- the Types instance to useatypeFactory
- the type factory to uset
- the receiver typeelem
- the element that should be viewed as member of tpublic static AnnotatedTypeMirror asMemberOf(Types types, AnnotatedTypeFactory atypeFactory, @Nullable AnnotatedTypeMirror t, Element elem, AnnotatedTypeMirror elemType)
types
- the Types instance to useatypeFactory
- the type factory to uset
- the receiver typeelem
- the element that should be viewed as member of telemType
- unsubstituted type of elemasMemberOf(Types, AnnotatedTypeFactory, AnnotatedTypeMirror, Element)
public static AnnotatedTypeMirror getIteratedType(ProcessingEnvironment processingEnv, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror iterableType)
IllegalArgumentException
if the passed type is not iterable.
The iterated type is the component type of an array, and the type argument of Iterable
for declared types.
iterableType
- the iterable type (either array or declared)public static Set<AnnotatedTypeMirror.AnnotatedDeclaredType> getSuperTypes(AnnotatedTypeMirror.AnnotatedDeclaredType type)
type
- a declared typepublic static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(Elements elements, AnnotatedTypeFactory atypeFactory, ExecutableElement method)
method
- the overriding methodmethod
overridespublic static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(Elements elements, ExecutableElement method, Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
method
- the overriding methodsupertypes
- the set of supertypes to check for methods that are overridden by method
method
overridespublic static Map<TypeVariable,AnnotatedTypeMirror> findTypeArguments(ProcessingEnvironment processingEnv, AnnotatedTypeFactory atypeFactory, ExpressionTree expr, ExecutableElement elt, AnnotatedTypeMirror.AnnotatedExecutableType preType)
It uses the method or constructor invocation type arguments if they were specified and otherwise it infers them based on the passed arguments or the return type context, according to JLS 15.12.2.
atypeFactory
- the annotated type factoryexpr
- the method or constructor invocation tree; the passed argument has to be a
subtype of MethodInvocationTree or NewClassTreeelt
- the element corresponding to the treepreType
- the (partially annotated) type corresponding to the tree - the result of
AnnotatedTypes.asMemberOf with the receiver and eltpublic static AnnotatedTypeMirror leastUpperBound(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
atypeFactory
- AnnotatedTypeFactorytype1
- annotated typetype2
- annotated typepublic static AnnotatedTypeMirror leastUpperBound(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type1, AnnotatedTypeMirror type2, TypeMirror lubTypeMirror)
lubTypeMirror
of two annotated types.atypeFactory
- AnnotatedTypeFactorytype1
- annotated type whose underlying type must be a subtype or convertible to
lubTypeMirrortype2
- annotated type whose underlying type must be a subtype or convertible to
lubTypeMirrorlubTypeMirror
- underlying type of the returned lubpublic static List<AnnotatedTypeMirror> expandVarArgs(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror.AnnotatedExecutableType method, List<? extends ExpressionTree> args)
If the invoked method is not a vararg method or it is a vararg method but the invocation passes an array to the vararg parameter, it would simply return the method parameters.
Otherwise, it would return the list of parameters as if the vararg is expanded to match the size of the passed arguments.
method
- the method's typeargs
- the arguments to the method invocationpublic static List<AnnotatedTypeMirror> expandVarArgsFromTypes(AnnotatedTypeMirror.AnnotatedExecutableType method, List<AnnotatedTypeMirror> args)
public static AnnotatedTypeMirror getAnnotatedTypeMirrorOfParameter(AnnotatedTypeMirror.AnnotatedExecutableType methodType, int index)
methodType
- AnnotatedExecutableType of method or constructor containing parameter to
returnindex
- position of parameter type to returnpublic static List<AnnotatedTypeMirror> getAnnotatedTypes(AnnotatedTypeFactory atypeFactory, List<AnnotatedTypeMirror> paramTypes, List<? extends ExpressionTree> trees)
paramTypes
- the parameter types to use as assignment contexttrees
- the AST nodespublic static int getArrayDepth(AnnotatedTypeMirror.AnnotatedArrayType array)
array
- the type of the arraypublic static AnnotatedTypeMirror innerMostType(AnnotatedTypeMirror t)
public static boolean containsModifier(AnnotatedTypeMirror type, AnnotationMirror modifier)
AnnotatedTypeMirror.hasAnnotation(AnnotationMirror)
.type
- the type to searchmodifier
- the modifier to search forpublic static boolean isJavaLangAnnotation(AnnotatedTypeMirror atm)
public static boolean implementsAnnotation(AnnotatedTypeMirror atm)
@interface MyAnno
, a call to implementsAnnotation
returns true when called on an AnnotatedDeclaredType representing a use
of MyAnno.public static boolean isEnum(AnnotatedTypeMirror typeMirror)
public static boolean isDeclarationOfJavaLangEnum(Types types, Elements elements, AnnotatedTypeMirror typeMirror)
public static boolean haveSameDeclaration(Types types, AnnotatedTypeMirror.AnnotatedTypeVariable typeVar1, AnnotatedTypeMirror.AnnotatedTypeVariable typeVar2)
public static boolean areCorrespondingTypeVariables(Elements elements, AnnotatedTypeMirror.AnnotatedTypeVariable type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2)
public static AnnotationMirror findEffectiveAnnotationInHierarchy(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror toSearch, AnnotationMirror top)
top
- the top of the hierarchy for which you are searchingpublic static AnnotationMirror findEffectiveAnnotationInHierarchy(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror toSearch, AnnotationMirror top, boolean canBeEmpty)
top
- the top of the hierarchy for which you are searchingcanBeEmpty
- whether or not the effective type can have NO annotation in the hierarchy
specified by top If this param is false, an exception will be thrown if no annotation is
found Otherwise the result is nullpublic static Set<AnnotationMirror> findEffectiveLowerBoundAnnotations(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror toSearch)
public static Set<AnnotationMirror> findEffectiveAnnotations(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror toSearch)
public static Set<AnnotationMirror> glbOfBounds(AnnotatedTypeMirror.AnnotatedIntersectionType isect, QualifierHierarchy qualifierHierarchy)
isect
- the intersection for which we are glbing boundsqualifierHierarchy
- the qualifier used to get the hierarchies in which to glbpublic static boolean isExplicitlySuperBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
public static boolean isExplicitlyExtendsBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
public static boolean isUnboundedOrSuperBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
public static boolean isUnboundedOrExtendsBounded(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
public static void copyOnlyExplicitConstructorAnnotations(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror.AnnotatedDeclaredType returnType, AnnotatedTypeMirror.AnnotatedExecutableType constructor)
constructor
to returnType
. If returnType
has an
annotation in the same hierarchy of an annotation to be copied, that annotation is not
copied.atypeFactory
- type factoryreturnType
- return type to copy annotations toconstructor
- the ATM for the constructorpublic static void applyAnnotationsFromDeclaredType(AnnotatedTypeMirror.AnnotatedDeclaredType annotatedDeclaredType, DeclaredType declaredType)
declaredType
to annotatedDeclaredType
.
(The TypeMirror
returned by annotatedDeclaredType#getUnderlyingType
may
have not have all the annotations on the type, so allow the user to specify a different one.)
annotatedDeclaredType
- annotated type to which annotations are addeddeclaredType
- TypeMirror that may have annotations