Modifier and Type | Method and Description |
---|---|
static List<AnnotatedTypeMirror> |
adaptParameters(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror.AnnotatedExecutableType method,
List<? extends ExpressionTree> args)
Returns the method parameters for the invoked method (or constructor), with the same number of
arguments as passed to the invocation tree.
|
static AnnotatedTypeMirror |
annotatedGLB(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror type1,
AnnotatedTypeMirror type2)
Returns the "annotated greatest lower bound" of
type1 and type2 . |
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> |
expandVarArgsParameters(AnnotatedTypeFactory atypeFactory,
AnnotatedTypeMirror.AnnotatedExecutableType method,
List<? extends ExpressionTree> args)
Deprecated.
|
static List<AnnotatedTypeMirror> |
expandVarArgsParametersFromTypes(AnnotatedTypeMirror.AnnotatedExecutableType method,
List<AnnotatedTypeMirror> args)
Returns the method parameters for the invoked method, with the same number of formal parameters
as the arguments in the given list.
|
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)
This method returns the effective annotation on the lower bound of a type, or on the type
itself if the type has no lower bound (it is not a type variable, wildcard, or intersection).
|
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
expected at the indexth position (unwrapping varargs if necessary).
|
static List<AnnotatedTypeMirror> |
getAnnotatedTypes(AnnotatedTypeFactory atypeFactory,
List<AnnotatedTypeMirror> paramTypes,
List<? extends ExpressionTree> trees)
Deprecated.
use CollectionsPlume.mapList(atypeFactory::getAnnotatedType, trees) instead.
|
static int |
getArrayDepth(AnnotatedTypeMirror.AnnotatedArrayType array)
Returns the depth of the array type of the provided array.
|
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., an implementation of
java.lang.annotation.Annotation.
|
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
.
Before returning the result, this method adjusts it by calling AnnotatedTypeFactory.postAsMemberOf(AnnotatedTypeMirror, AnnotatedTypeMirror, Element)
.
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 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 AnnotatedTypeMirror annotatedGLB(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror type1, AnnotatedTypeMirror type2)
type1
and type2
.
Suppose that there is an expression e with annotated type T. The underlying type of T must be the same as javac's type for e. (This is a requirement of the Checker Framework.) As a corollary, when computing a glb of atype1 and atype2, it is required that underlyingType(cfGLB(atype1, atype2) == glb(javacGLB(underlyingType(atype1), underlyingType(atype2)). Because of this requirement, the return value of this method (the "annotated GLB") may not be a subtype of one of the types.
The "annotated greatest lower bound" is defined as follows:
type1
and type2
are the same, then return a
copy of type1
whose primary annotations are the greatest lower bound of the
primary annotations on type1
and type2
.
type1
is a subtype of the underlying type of type2
, then return a copy of type1
whose primary annotations are the greatest
lower bound of the primary annotations on type1
and type2
.
type1
is a supertype of the underlying type of type2
, then return a copy of type2
whose primary annotations are the greatest
lower bound of the primary annotations on type1
and type2
.
type1
and type2
are not in a subtyping
relationship, then return an annotated intersection type whose bounds are type1
and type2
.
atypeFactory
- the AnnotatedTypeFactorytype1
- annotated typetype2
- annotated type@Deprecated public static List<AnnotatedTypeMirror> expandVarArgsParameters(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror.AnnotatedExecutableType method, List<? extends ExpressionTree> args)
adaptParameters(AnnotatedTypeFactory,
AnnotatedTypeMirror.AnnotatedExecutableType, List)
insteadIf 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.
atypeFactory
- the type factory to use for fetching annotated typesmethod
- the method's typeargs
- the arguments to the method invocationpublic static List<AnnotatedTypeMirror> adaptParameters(AnnotatedTypeFactory atypeFactory, AnnotatedTypeMirror.AnnotatedExecutableType method, List<? extends ExpressionTree> args)
This expands the parameters if the call uses varargs or contracts the parameters if the call is to an anonymous class that extends a class with an enclosing type. If the call is neither of these, then the parameters are returned unchanged.
atypeFactory
- the type factory to use for fetching annotated typesmethod
- the method or constructor's typeargs
- the arguments to the method or constructor invocationargs
public static List<AnnotatedTypeMirror> expandVarArgsParametersFromTypes(AnnotatedTypeMirror.AnnotatedExecutableType method, List<AnnotatedTypeMirror> args)
method
- the method's typeargs
- the types of the arguments at the call sitepublic static AnnotatedTypeMirror getAnnotatedTypeMirrorOfParameter(AnnotatedTypeMirror.AnnotatedExecutableType methodType, int index)
methodType
- AnnotatedExecutableType of method or constructor containing parameter to
returnindex
- position of parameter type to return@Deprecated public static List<AnnotatedTypeMirror> getAnnotatedTypes(AnnotatedTypeFactory atypeFactory, List<AnnotatedTypeMirror> paramTypes, List<? extends ExpressionTree> trees)
atypeFactory
- a type factoryparamTypes
- 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)
types
- type utilstypeVar1
- a type variabletypeVar2
- a type variablepublic static boolean areCorrespondingTypeVariables(Elements elements, AnnotatedTypeMirror.AnnotatedTypeVariable type1, AnnotatedTypeMirror.AnnotatedTypeVariable type2)
Necessary conditions:
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