Class TypeDeclarationApplier
java.lang.Object
org.checkerframework.framework.util.element.TypeDeclarationApplier
Apply annotations to a declared type based on its declaration.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Element
An Element that type represents.static final int
If a type_index == -1 it means that the index refers to the immediate supertype class of the declaration.protected final AnnotatedTypeMirror
The type to which we wish to apply annotations. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
accepts
(AnnotatedTypeMirror type, Element element) Returns true if type is an annotated declared type and element is a ClassSymbol.protected com.sun.tools.javac.code.TargetType[]
Returns the TargetTypes that identify annotations we wish to apply with this object.static void
apply
(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory typeFactory) void
Adds extends/implements and class annotations to type.protected Iterable<com.sun.tools.javac.code.Attribute.TypeCompound>
All TypeCompounds (annotations) on the ClassSymbol.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> extendsAndImplementsAnnos) While more than just annotations on extends or implements clause are annotated by this class, only these annotations are passed to handleTargeted (as they are the only in the annotatedTargets list).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 the TargetTypes that identify annotations that are valid but we wish to ignore.
-
Field Details
-
SUPERCLASS_INDEX
public static final int SUPERCLASS_INDEXIf a type_index == -1 it means that the index refers to the immediate supertype class of the declaration. There is only ever one of these since Java has no multiple inheritance- See Also:
-
type
The type to which we wish to apply annotations. -
element
An Element that type represents.
-
-
Method Details
-
apply
public static void apply(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory typeFactory) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException -
accepts
Returns true if type is an annotated declared type and element is a ClassSymbol.- Parameters:
type
- a typeelement
- an element- Returns:
- true if type is an annotated declared type and element is a ClassSymbol
-
annotatedTargets
protected com.sun.tools.javac.code.TargetType[] annotatedTargets()Returns the TargetTypes that identify annotations we wish to apply with this object. Any annotations that have these target types will be passed to handleTargeted.- Returns:
- the TargetTypes that identify annotations we wish to apply with this object. Any annotations that have these target types will be passed to handleTargeted
-
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
All TypeCompounds (annotations) on the ClassSymbol.- Returns:
- the annotations that we MAY wish to apply to the given type
-
handleTargeted
protected void handleTargeted(List<com.sun.tools.javac.code.Attribute.TypeCompound> extendsAndImplementsAnnos) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException While more than just annotations on extends or implements clause are annotated by this class, only these annotations are passed to handleTargeted (as they are the only in the annotatedTargets list). See extractAndApply for type parameters- Parameters:
extendsAndImplementsAnnos
- annotations with a TargetType of CLASS_EXTENDS- Throws:
ElementAnnotationUtil.UnexpectedAnnotationLocationException
-
extractAndApply
Adds extends/implements and class annotations to type. Annotates type parameters. -
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
-
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
-
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>.
-