Modifier and Type | Method and Description |
---|---|
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 boolean |
areSame(AnnotatedTypeMirror t1,
AnnotatedTypeMirror t2) |
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.AnnotatedExecutableType |
asMemberOf(Types types,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror t,
ExecutableElement elem) |
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 AnnotatedTypeMirror |
asSuper(Types types,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type,
AnnotatedTypeMirror 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 super types of the given declared type.
|
static Set<AnnotationMirror> |
glbOfBounds(AnnotatedTypeMirror.AnnotatedIntersectionType isect,
QualifierHierarchy qualifierHierarchy)
Get's 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 |
hasTypeQualifierElementTypes(ElementType[] elements,
Class<?> cls)
Sees if the passed in array of
ElementType values have the correct set of values
which defines a type qualifier |
static boolean |
haveSameDeclaration(Types types,
AnnotatedTypeMirror.AnnotatedTypeVariable typeVar1,
AnnotatedTypeMirror.AnnotatedTypeVariable typeVar2) |
static boolean |
implementsAnnotation(AnnotatedTypeMirror atm) |
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) |
static boolean |
isTypeAnnotation(AnnotationMirror anno,
Class<?> cls) |
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 boolean |
isValidType(QualifierHierarchy qualifierHierarchy,
AnnotatedTypeMirror type)
Returns true if the given
AnnotatedTypeMirror passed a set of well-formedness checks. |
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 AnnotatedTypeMirror |
leastUpperBound(ProcessingEnvironment processingEnv,
AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2)
|
static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> |
overriddenMethods(Elements elements,
AnnotatedTypeFactory atypeFactory,
ExecutableElement method)
A utility method that takes a Method element and returns a set of all elements that this
method overrides (as
ExecutableElement s) |
static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> |
overriddenMethods(Elements elements,
ExecutableElement method,
Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
A utility method that takes the element for a method and the set of all supertypes of the
method's containing class and returns the set of all elements that method overrides (as
ExecutableElement s). |
@Deprecated public static AnnotatedTypeMirror asSuper(Types types, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type, AnnotatedTypeMirror superType)
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 call 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 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)
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.
t
- a typeelem
- an elementpublic 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)
ExecutableElement
s)method
- the overriding methodExecutableElement
s representing the elements that
method overridespublic static Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods(Elements elements, ExecutableElement method, Collection<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes)
ExecutableElement
s).method
- the overriding methodsupertypes
- the set of supertypes to check for methods that are overridden by method
ExecutableElement
s representing the elements that method
overrides among supertypes
public 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 elt.@Deprecated public static AnnotatedTypeMirror leastUpperBound(ProcessingEnvironment processingEnv, AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
public 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 boolean areSame(AnnotatedTypeMirror t1, AnnotatedTypeMirror t2)
public 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 isTypeAnnotation(AnnotationMirror anno, Class<?> cls)
public static boolean hasTypeQualifierElementTypes(ElementType[] elements, Class<?> cls)
ElementType
values have the correct set of values
which defines a type qualifierelements
- an array of ElementType
valuescls
- the annotation class being tested; used for diagnostic messages onlyRuntimeException
- if the array contains both ElementType.TYPE_USE
and
something besides ElementType.TYPE_PARAMETER
public static boolean isValidType(QualifierHierarchy qualifierHierarchy, AnnotatedTypeMirror type)
AnnotatedTypeMirror
passed a set of well-formedness checks.
The method will never return false for valid types, but might not catch all invalid types.
Currently, the following is checked:
public static boolean isJavaLangAnnotation(AnnotatedTypeMirror atm)
public static boolean implementsAnnotation(AnnotatedTypeMirror atm)
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 constructor