Class SuperTypeApplier
java.lang.Object
org.checkerframework.framework.util.element.SuperTypeApplier
When discovering supertypes of an AnnotatedTypeMirror we want to annotate each supertype with the
annotations of the subtypes class declaration. This class provides static methods to do this for
a list of supertypes. An instance of this class handles ONE supertype.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Element
An Element that type represents.protected final AnnotatedTypeMirror
The type to which we wish to apply annotations. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.sun.tools.javac.code.TargetType[]
Returns TargetType.CLASS_EXTENDS.static void
annotateSupers
(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes, TypeElement subtypeElement) Annotates each supertype with annotations from subtypeElement's extends/implements clauses.void
Reads the list of annotations that apply to this element (see getRawTypeAttributes).int
Returns the type_index that should represent supertype.protected Iterable<com.sun.tools.javac.code.Attribute.TypeCompound>
Returns the TypeCompounds (annotations) of the subclass.int
getTypeCompoundIndex
(com.sun.tools.javac.code.Attribute.TypeCompound anno) Returns the type_index of anno's TypeAnnotationPosition.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
Tests element/type fields to ensure that this TargetedElementAnnotationApplier is valid for this element/type pair.protected Map<org.checkerframework.framework.util.element.TargetedElementAnnotationApplier.TargetClass,
List<com.sun.tools.javac.code.Attribute.TypeCompound>> 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[]
Returns TargetType.CLASS_TYPE_PARAMETER, TargetType.CLASS_TYPE_PARAMETER_BOUND.
-
Field Details
-
type
The type to which we wish to apply annotations. -
element
An Element that type represents.
-
-
Method Details
-
annotateSupers
public static void annotateSupers(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes, TypeElement subtypeElement) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException Annotates each supertype with annotations from subtypeElement's extends/implements clauses.- Parameters:
supertypes
- supertypes to annotatesubtypeElement
- element that may have annotations to apply to supertypes- Throws:
ElementAnnotationUtil.UnexpectedAnnotationLocationException
-
getElementIndex
public int getElementIndex()Returns the type_index that should represent supertype.- Returns:
- the type_index that should represent supertype
-
getTypeCompoundIndex
public int getTypeCompoundIndex(com.sun.tools.javac.code.Attribute.TypeCompound anno) Returns the type_index of anno's TypeAnnotationPosition.- Parameters:
anno
- an annotation we might wish to apply- Returns:
- the type_index of anno's TypeAnnotationPosition
-
annotatedTargets
protected com.sun.tools.javac.code.TargetType[] annotatedTargets()Returns TargetType.CLASS_EXTENDS.- Returns:
- TargetType.CLASS_EXTENDS
-
validTargets
protected com.sun.tools.javac.code.TargetType[] validTargets()Returns TargetType.CLASS_TYPE_PARAMETER, TargetType.CLASS_TYPE_PARAMETER_BOUND.- Returns:
- TargetType.CLASS_TYPE_PARAMETER, TargetType.CLASS_TYPE_PARAMETER_BOUND
-
getRawTypeAttributes
Returns the TypeCompounds (annotations) of the subclass.- Returns:
- the TypeCompounds (annotations) of the subclass
-
handleTargeted
protected void handleTargeted(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 returned by getRawTypeAttributes and had a TargetType contained by annotatedTargets- Throws:
ElementAnnotationUtil.UnexpectedAnnotationLocationException
-
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
-
sift
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.- Parameters:
typeCompounds
- annotations to sift through, should be those returned by getRawTypeAttributes- Returns:
- a Map<TargetClass => Annotations>.
-
handleValid
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
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
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.
-