Class ElementAnnotationApplier
java.lang.Object
org.checkerframework.framework.type.ElementAnnotationApplier
Utility methods for adding the annotations that are stored in an Element to the type that
represents that element (or a use of that Element).
In a way, this class is a hack: the Type representation for the Elements should contain all annotations that we want. However, due to javac bugs, decoding the type annotations from the Element is necessary.
Even once these bugs are fixed, this class might be useful: in TypesIntoElements it is easy to add additional annotations to the element and have them stored in the bytecode by the compiler. It would be more work (and might not work in the end) to instead modify the Type directly. The interaction between this class and TypesIntoElements allows us to write the defaulted annotations into the Element and have them read later by other parts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA lambda parameter declaration and the lambda that declares it. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidannotateSupers(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes, TypeElement subtypeElement) Annotates the list of supertypes using the annotations on the TypeElement representing a class or interface.static voidapply(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory typeFactory) Adds all of the relevant annotations stored in Element to type.getParamAndLambdaTree(VariableElement varEle, AnnotatedTypeFactory typeFactory) Helper method to get the lambda tree for ParamApplier.
-
Method Details
-
apply
public static void apply(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory typeFactory) Adds all of the relevant annotations stored in Element to type. This includes both top-level primary annotations and nested annotations. For the most part, the TypeAnnotationPosition of each element annotation is used to locate the annotation in the right AnnotatedTypeMirror location, though the individual applier classes can have special rules (such as those for upper and lower bounds and intersections).Note: Element annotations come from two sources.
- Annotations found on elements can represent those in source code or bytecode; these are added to the element by the compiler.
- The annotations can also represent those that were inferred or defaulted by the Checker
Framework after a previous call to this method. The Checker Framework will store any
annotations on declarations back into the elements that represent them (see
TypesIntoElements). Subsequent calls to apply will encounter these annotations on the provided element.
TypeFromTree.- Parameters:
type- the type to which we wish to apply the element's annotationselement- an element that possibly contains annotationstypeFactory- the typeFactory used to create the given type
-
annotateSupers
public static void annotateSupers(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes, TypeElement subtypeElement) Annotates the list of supertypes using the annotations on the TypeElement representing a class or interface.- Parameters:
supertypes- types representing supertype declarations of TypeElementsubtypeElement- an element representing the declaration of the class which is a subtype of supertypes
-
getParamAndLambdaTree
public static @Nullable ElementAnnotationApplier.LambdaParam getParamAndLambdaTree(VariableElement varEle, AnnotatedTypeFactory typeFactory) Helper method to get the lambda tree for ParamApplier. Ideally, this method would be located in ElementAnnotationUtil but since AnnotatedTypeFactory.declarationFromElement is protected, it has been placed here.- Parameters:
varEle- the element that might represent a lambda's parametertypeFactory- the type factory- Returns:
- the parameter declaration and its LambdaExpressionTree if
varElerepresents a parameter in a lambda expression, otherwise null
-