Class ParamApplier
java.lang.Object
org.checkerframework.framework.util.element.ParamApplier
Adds annotations to one formal parameter of a method or lambda within a method.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final ElementAn Element that type represents.static final intprotected final AnnotatedTypeMirrorThe type to which we wish to apply annotations.
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanaccepts(AnnotatedTypeMirror type, Element element) protected com.sun.tools.javac.code.TargetType[]Returns {TargetType.METHOD_FORMAL_PARAMETER, TargetType.METHOD_RECEIVER}.static voidapply(AnnotatedTypeMirror type, VariableElement element, AnnotatedTypeFactory typeFactory) Apply annotations fromelementtotype.voidReads the list of annotations that apply to this element (see getRawTypeAttributes).intReturns the index of element its parent method's parameter list.static com.sun.tools.javac.code.Symbol.MethodSymbolgetParentMethod(Element methodChildElem) Return the enclosing MethodSymbol of the given element, throwing an exception if the symbol's enclosing element is not a MethodSymbol.protected Iterable<com.sun.tools.javac.code.Attribute.TypeCompound>Returns the TypeCompounds (annotations) of the enclosing method for this parameter.intgetTypeCompoundIndex(com.sun.tools.javac.code.Attribute.TypeCompound anno) Returns the parameter index of anno's TypeAnnotationPosition.protected voidhandleInvalid(List<com.sun.tools.javac.code.Attribute.TypeCompound> invalid) This implementation reports all invalid annotations as errors.protected voidhandleTargeted(List<com.sun.tools.javac.code.Attribute.TypeCompound> targeted) This method should apply all annotations that are handled by this object.protected voidhandleValid(List<com.sun.tools.javac.code.Attribute.TypeCompound> valid) The default implementation of this method does nothing.protected booleanTests 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 any annotation TargetType that can be found on a method.
- 
Field Details- 
RECEIVER_PARAM_INDEXpublic static final int RECEIVER_PARAM_INDEX- See Also:
 
- 
typeThe type to which we wish to apply annotations.
- 
elementAn Element that type represents.
 
- 
- 
Method Details- 
applypublic static void apply(AnnotatedTypeMirror type, VariableElement element, AnnotatedTypeFactory typeFactory) throws ElementAnnotationUtil.UnexpectedAnnotationLocationException Apply annotations fromelementtotype.- Parameters:
- type- the type whose annotations to change
- element- where to get annotations from
- typeFactory- the type factory
- Throws:
- ElementAnnotationUtil.UnexpectedAnnotationLocationException- if there is trouble
 
- 
accepts
- 
getElementIndexpublic int getElementIndex()Returns the index of element its parent method's parameter list. Integer.MIN_VALUE if the element is the receiver parameter.- Returns:
- the index of element its parent method's parameter list. Integer.MIN_VALUE if the element is the receiver parameter
 
- 
getTypeCompoundIndexpublic int getTypeCompoundIndex(com.sun.tools.javac.code.Attribute.TypeCompound anno) Returns the parameter index of anno's TypeAnnotationPosition.- Parameters:
- anno- an annotation we might wish to apply
- Returns:
- the parameter index of anno's TypeAnnotationPosition
 
- 
annotatedTargetsprotected com.sun.tools.javac.code.TargetType[] annotatedTargets()Returns {TargetType.METHOD_FORMAL_PARAMETER, TargetType.METHOD_RECEIVER}.- Returns:
- {TargetType.METHOD_FORMAL_PARAMETER, TargetType.METHOD_RECEIVER}
 
- 
validTargetsprotected com.sun.tools.javac.code.TargetType[] validTargets()Returns any annotation TargetType that can be found on a method.- Returns:
- any annotation TargetType that can be found on a method
 
- 
getRawTypeAttributesReturns the TypeCompounds (annotations) of the enclosing method for this parameter.- Returns:
- the TypeCompounds (annotations) of the enclosing method for this parameter
 
- 
siftprotected 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>.
 
- 
handleTargetedprotected 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- type compounds with formal method parameter target types with parameter_index == getIndex
- Throws:
- ElementAnnotationUtil.UnexpectedAnnotationLocationException
 
- 
isAcceptedprotected 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
 
- 
getParentMethodReturn the enclosing MethodSymbol of the given element, throwing an exception if the symbol's enclosing element is not a MethodSymbol.- Parameters:
- methodChildElem- some element that is a child of a method typeDeclaration (e.g. a parameter or return type)
- Returns:
- the MethodSymbol of the method enclosing methodChildElem
 
- 
extractAndApplyReads 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. 
- 
handleValidThe 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
 
- 
handleInvalidThis 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
 
 
-