public class MethodTypeParamApplier extends Object
Modifier and Type | Field and Description |
---|---|
protected Element |
element
An Element that type represents.
|
protected AnnotatedTypeMirror |
type
The type to which we wish to apply annotations.
|
protected AnnotatedTypeFactory |
typeFactory |
protected AnnotatedTypeMirror.AnnotatedTypeVariable |
typeParam |
Modifier and Type | Method and Description |
---|---|
static boolean |
accepts(AnnotatedTypeMirror type,
Element element)
Returns true if element represents a type parameter for a method.
|
protected com.sun.tools.javac.code.TargetType[] |
annotatedTargets()
Returns the lower bound and upper bound targets.
|
static void |
apply(AnnotatedTypeMirror.AnnotatedTypeVariable type,
Element element,
AnnotatedTypeFactory typeFactory)
Apply annotations from
element to type . |
void |
extractAndApply()
Reads the list of annotations that apply to this element (see getRawTypeAttributes).
|
int |
getElementIndex()
Returns the index of element in the type parameter list of its enclosing method.
|
protected Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> |
getRawTypeAttributes()
Returns the TypeCompounds (annotations) of the declaring element.
|
int |
getTypeCompoundIndex(com.sun.tools.javac.code.Attribute.TypeCompound anno)
Returns the parameter_index of anno's TypeAnnotationPosition which will actually point to the
type parameter's index in its enclosing type parameter list.
|
protected void |
handleInvalid(List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
This implementation reports all invalid annotations as errors.
|
protected void |
handleTargeted(List<com.sun.tools.javac.code.Attribute.TypeCompound> targeted)
This method should apply all annotations that are handled by this object.
|
protected void |
handleValid(List<com.sun.tools.javac.code.Attribute.TypeCompound> valid)
The default implementation of this method does nothing.
|
protected boolean |
isAccepted()
Tests element/type fields to ensure that this TargetedElementAnnotationApplier is valid for
this element/type pair.
|
protected com.sun.tools.javac.code.TargetType |
lowerBoundTarget()
Returns TargetType.METHOD_TYPE_PARAMETER.
|
protected Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,List<com.sun.tools.javac.code.Attribute.TypeCompound>> |
sift(Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> typeCompounds)
Separate the input annotations into a Map of TargetClass (TARGETED, VALID, INVALID) to the
annotations that fall into each of those categories.
|
protected com.sun.tools.javac.code.TargetType |
upperBoundTarget()
Returns TargetType.METHOD_TYPE_PARAMETER_BOUND.
|
protected com.sun.tools.javac.code.TargetType[] |
validTargets()
Returns the TargetTypes that identify annotations that are valid but we wish to ignore.
|
protected final AnnotatedTypeMirror.AnnotatedTypeVariable typeParam
protected final AnnotatedTypeFactory typeFactory
protected final AnnotatedTypeMirror type
protected final Element element
public static void apply(AnnotatedTypeMirror.AnnotatedTypeVariable type, Element element, AnnotatedTypeFactory typeFactory) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
element
to type
.public static boolean accepts(AnnotatedTypeMirror type, Element element)
type
- ignoredelement
- the element that might be a type parameter for a methodprotected com.sun.tools.javac.code.TargetType lowerBoundTarget()
protected com.sun.tools.javac.code.TargetType upperBoundTarget()
public int getElementIndex()
protected com.sun.tools.javac.code.TargetType[] validTargets()
protected Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> getRawTypeAttributes()
protected boolean isAccepted()
protected com.sun.tools.javac.code.TargetType[] annotatedTargets()
public int getTypeCompoundIndex(com.sun.tools.javac.code.Attribute.TypeCompound anno)
anno
- an annotation we might wish to applyprotected void handleTargeted(List<com.sun.tools.javac.code.Attribute.TypeCompound> targeted) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
targeted
- the list of annotations that were on the lower/upper bounds of the type
parameter
Note: When handling type parameters we NEVER add primary annotations to the type parameter. Primary annotations are reserved for the use of a type parameter (e.g. @Nullable T t; )
If an annotation is present on the type parameter itself, it represents the lower-bound annotation of that type parameter. Any annotation on the extends bound of a type parameter is placed on that bound.
ElementAnnotationUtil.UnexpectedAnnotationLocationException
protected Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,List<com.sun.tools.javac.code.Attribute.TypeCompound>> sift(Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> typeCompounds)
typeCompounds
- annotations to sift through, should be those returned by
getRawTypeAttributesprotected void handleValid(List<com.sun.tools.javac.code.Attribute.TypeCompound> valid)
valid
- the list of annotations that were returned by getRawTypeAttributes and had a
TargetType contained by valid and NOT annotatedTargetsprotected void handleInvalid(List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
invalid
- the list of annotations that were returned by getRawTypeAttributes and were
not handled by handleTargeted or handleValidpublic void extractAndApply() throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
This method will throw a runtime exception if isAccepted returns false.