public class ElementAnnotationApplier extends Object
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 http://mail.openjdk.java.net/pipermail/type-annotations-dev/2013-December/001449.html 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 TypeFromElement and TypesIntoElements allows us to write the defaulted annotations into the Element and have them read later by other parts.
Constructor and Description |
---|
ElementAnnotationApplier() |
Modifier and Type | Method and Description |
---|---|
static void |
annotateSupers(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes,
TypeElement subtypeElement)
Annotate the list of supertypes using the annotations on the TypeElement representing a class
or interface
|
static void |
apply(AnnotatedTypeMirror type,
Element element,
AnnotatedTypeFactory typeFactory)
Add all of the relevant annotations stored in Element to type.
|
static Pair<VariableTree,LambdaExpressionTree> |
getParamAndLambdaTree(VariableElement varEle,
AnnotatedTypeFactory typeFactory)
Helper method to get the lambda tree for ParamApplier.
|
public static void apply(AnnotatedTypeMirror type, Element element, AnnotatedTypeFactory typeFactory)
Note: Element annotations come from two sources.
TypesIntoElements
). Subsequent, calls to apply
will encounter these annotations on the provided element.
TypeFromTree
.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 typepublic static void annotateSupers(List<AnnotatedTypeMirror.AnnotatedDeclaredType> supertypes, TypeElement subtypeElement)
supertypes
- types representing supertype declarations of TypeElementsubtypeElement
- an element representing the declaration of the class which is a subtype
of supertypespublic static Pair<VariableTree,LambdaExpressionTree> getParamAndLambdaTree(VariableElement varEle, AnnotatedTypeFactory typeFactory)
varEle
- the element that may represent a lambda's parameter