Class MethodApplier
java.lang.Object
org.checkerframework.framework.util.element.MethodApplier
Adds annotations from element to the return type, formal parameter types, type parameters, and
throws clauses of the AnnotatedExecutableType type.
-
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 TypeMethodDescriptionstatic boolean
accepts
(AnnotatedTypeMirror typeMirror, Element element) Returns true if typeMirror represents anAnnotatedTypeMirror.AnnotatedExecutableType
and element represents aSymbol.MethodSymbol
.protected com.sun.tools.javac.code.TargetType[]
Returns receiver, returns, and throws.static void
apply
(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory atypeFactory) Apply annotations fromelement
totype
.void
Sets the method's element, annotates its return type, parameters, type parameters, and throws annotations.protected Iterable
<com.sun.tools.javac.code.Attribute.TypeCompound> Returns the annotations on the method symbol (element).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 all possible annotation positions for a method except those in annotatedTargets.
-
Field Details
-
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 atypeFactory) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException Apply annotations fromelement
totype
.- Parameters:
type
- the type to annotateelement
- the corresponding elementatypeFactory
- the type factory- Throws:
ElementAnnotationUtil.UnexpectedAnnotationLocationException
- if there is trouble
-
accepts
Returns true if typeMirror represents anAnnotatedTypeMirror.AnnotatedExecutableType
and element represents aSymbol.MethodSymbol
.- Parameters:
typeMirror
- the type to testelement
- the corresponding element- Returns:
- true if the MethodApplier accepts the type and element
-
annotatedTargets
protected com.sun.tools.javac.code.TargetType[] annotatedTargets()Returns receiver, returns, and throws. See extract and apply as we also annotate type params.- Returns:
- receiver, returns, and throws
-
validTargets
protected com.sun.tools.javac.code.TargetType[] validTargets()Returns all possible annotation positions for a method except those in annotatedTargets.- Returns:
- all possible annotation positions for a method except those in annotatedTargets
-
getRawTypeAttributes
Returns the annotations on the method symbol (element).- Returns:
- the annotations on the method symbol (element)
-
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
-
extractAndApply
Sets the method's element, annotates its return type, parameters, type parameters, and throws annotations. -
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
-
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>.
-