Class ClassTypeParamApplier
- java.lang.Object
-
- org.checkerframework.framework.util.element.ClassTypeParamApplier
-
public class ClassTypeParamApplier extends java.lang.Object
Applies the annotations present for a class type parameter onto an AnnotatedTypeVariable. SeeTypeParamElementAnnotationApplier
for details.
-
-
Field Summary
Fields Modifier and Type Field Description protected AnnotatedTypeFactory
atypeFactory
protected javax.lang.model.element.Element
element
An Element that type represents.protected AnnotatedTypeMirror
type
The type to which we wish to apply annotations.protected AnnotatedTypeMirror.AnnotatedTypeVariable
typeParam
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
accepts(AnnotatedTypeMirror type, javax.lang.model.element.Element element)
Returns true if element represents a type parameter for a class.protected com.sun.tools.javac.code.TargetType[]
annotatedTargets()
Returns the lower bound and upper bound targets.static void
apply(AnnotatedTypeMirror.AnnotatedTypeVariable type, javax.lang.model.element.Element element, AnnotatedTypeFactory typeFactory)
Apply annotations fromelement
totype
.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 class.protected java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound>
getRawTypeAttributes()
Returns the raw type attributes of the enclosing class.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(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
This implementation reports all invalid annotations as errors.protected void
handleTargeted(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> targeted)
This method should apply all annotations that are handled by this object.protected void
handleValid(java.util.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.CLASS_TYPE_PARAMETER.protected java.util.Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound>>
sift(java.lang.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.CLASS_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.
-
-
-
Field Detail
-
typeParam
protected final AnnotatedTypeMirror.AnnotatedTypeVariable typeParam
-
atypeFactory
protected final AnnotatedTypeFactory atypeFactory
-
type
protected final AnnotatedTypeMirror type
The type to which we wish to apply annotations.
-
element
protected final javax.lang.model.element.Element element
An Element that type represents.
-
-
Method Detail
-
apply
public static void apply(AnnotatedTypeMirror.AnnotatedTypeVariable type, javax.lang.model.element.Element element, AnnotatedTypeFactory typeFactory) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
Apply annotations fromelement
totype
.
-
accepts
public static boolean accepts(AnnotatedTypeMirror type, javax.lang.model.element.Element element)
Returns true if element represents a type parameter for a class.- Parameters:
type
- ignoredelement
- the element that might be a type parameter- Returns:
- true if element represents a type parameter for a class
-
lowerBoundTarget
protected com.sun.tools.javac.code.TargetType lowerBoundTarget()
Returns TargetType.CLASS_TYPE_PARAMETER.- Returns:
- TargetType.CLASS_TYPE_PARAMETER
-
upperBoundTarget
protected com.sun.tools.javac.code.TargetType upperBoundTarget()
Returns TargetType.CLASS_TYPE_PARAMETER_BOUND.- Returns:
- TargetType.CLASS_TYPE_PARAMETER_BOUND
-
getElementIndex
public int getElementIndex()
Returns the index of element in the type parameter list of its enclosing class.- Returns:
- the index of element in the type parameter list of its enclosing class
-
validTargets
protected com.sun.tools.javac.code.TargetType[] validTargets()
Returns the TargetTypes that identify annotations that are valid but we wish to ignore. Any annotations that have these target types will be passed to handleValid, providing they aren't also in annotatedTargets.- Returns:
- the TargetTypes that identify annotations that are valid but we wish to ignore
-
getRawTypeAttributes
protected java.lang.Iterable<com.sun.tools.javac.code.Attribute.TypeCompound> getRawTypeAttributes()
Returns the raw type attributes of the enclosing class.- Returns:
- the raw type attributes of the enclosing class
-
isAccepted
protected boolean isAccepted()
Tests element/type fields to ensure that this TargetedElementAnnotationApplier is valid for this element/type pair.- Returns:
- true if the type/element members are handled by this class false otherwise
-
annotatedTargets
protected com.sun.tools.javac.code.TargetType[] annotatedTargets()
Returns the lower bound and upper bound targets.- Returns:
- the lower bound and upper bound targets
-
getTypeCompoundIndex
public 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.- Parameters:
anno
- an annotation we might wish to apply- Returns:
- the parameter_index of anno's TypeAnnotationPosition which will actually point to the type parameter's index in its enclosing type parameter list
-
handleTargeted
protected void handleTargeted(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> targeted) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
This method should apply all annotations that are handled by this object.- Parameters:
targeted
- the list of annotations that were on the lower/upper bounds of the type parameterNote: 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.
- Throws:
ElementAnnotationUtil.UnexpectedAnnotationLocationException
-
sift
protected java.util.Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound>> sift(java.lang.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.- Parameters:
typeCompounds
- annotations to sift through, should be those returned by getRawTypeAttributes- Returns:
- a Map<TargetClass => Annotations>.
-
handleValid
protected void handleValid(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> valid)
The default implementation of this method does nothing.- Parameters:
valid
- the list of annotations that were returned by getRawTypeAttributes and had a TargetType contained by valid and NOT annotatedTargets
-
handleInvalid
protected void handleInvalid(java.util.List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid)
This implementation reports all invalid annotations as errors.- Parameters:
invalid
- the list of annotations that were returned by getRawTypeAttributes and were not handled by handleTargeted or handleValid
-
extractAndApply
public void extractAndApply() throws ElementAnnotationUtil.UnexpectedAnnotationLocationException
Reads the list of annotations that apply to this element (see getRawTypeAttributes). Sifts them into three groups (TARGETED, INVALID, VALID) and then calls the appropriate handle method on them. The handleTargeted method should apply all annotations that are handled by this object.This method will throw a runtime exception if isAccepted returns false.
-
-