public class ExpressionAnnotationHelper extends Object
1. Standardizes/canonicalizes the expressions in the annotations such that two expression strings that are equivalent are made to be equal. For example, an instance field f may appear in an expression string as "f" or "this.f"; this class standardizes both strings to "this.f".
2. Viewpoint-adapts annotations on field or method declarations at field accesses or method invocations.
3. Changes invalid expression strings to an error string that includes the reason why the
expression is invalid. For example, @KeyFor("m")
would be changed to
@KeyFor("[error for expression: m error: m: identifier not found]")
if m is not a valid
identifier.
4. Checks annotated types for error strings that have been added by this class and issues an error if any are found.
Steps 3 and 4 are separated so that an error is issued only once per invalid expression string rather than every time the expression string is parsed. (The expression string is parsed multiple times because annotated types are created multiple times.)
Modifier and Type | Field and Description |
---|---|
protected List<Class<? extends Annotation>> |
expressionAnnos
A list of annotations that are expression annotations.
|
protected AnnotatedTypeFactory |
factory |
Constructor and Description |
---|
ExpressionAnnotationHelper(AnnotatedTypeFactory factory,
Class<? extends Annotation> anno) |
ExpressionAnnotationHelper(AnnotatedTypeFactory factory,
List<Class<? extends Annotation>> expressionAnnos) |
Modifier and Type | Method and Description |
---|---|
void |
checkMethod(MethodTree methodTree,
AnnotatedTypeMirror.AnnotatedExecutableType type)
Checks all expression annotations in the method declaration to see if the expression string
is an error string as specified by ExpressionAnnotationError#isExpressionError.
|
void |
checkType(AnnotatedTypeMirror atm,
Tree errorTree)
Checks all expression annotations in the given annotated type to see if the expression string
is an error string as specified by ExpressionAnnotationError#isExpressionError.
|
TreeAnnotator |
createExpressionAnnotationTreeAnnotator(AnnotatedTypeFactory factory)
Creates a TreeAnnotator that standarizes expression annotations.
|
protected void |
reportErrors(Tree errorTree,
List<ExpressionAnnotationError> errors) |
void |
standardizeExpression(ExpressionTree tree,
AnnotatedTypeMirror annotatedType) |
void |
standardizeFieldAccess(MemberSelectTree node,
AnnotatedTypeMirror type) |
void |
standardizeNewClassTree(NewClassTree tree,
AnnotatedTypeMirror.AnnotatedDeclaredType type) |
void |
standardizeReturnType(MethodTree m,
AnnotatedTypeMirror atm) |
protected String |
standardizeString(String expression,
FlowExpressionParseUtil.FlowExpressionContext context,
TreePath localScope,
boolean useLocalScope) |
void |
standardizeVariable(AnnotatedTypeMirror type,
Element elt) |
void |
standardizeVariable(Tree node,
AnnotatedTypeMirror type,
Element ele) |
void |
viewpointAdaptConstructor(NewClassTree newClassTree,
AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
Viewpoint adapts the expression annotations in the constructorType based on the newClassTree.
|
void |
viewpointAdaptMethod(MethodInvocationTree methodInvocationTree,
AnnotatedTypeMirror.AnnotatedExecutableType methodDeclType)
Viewpoint adapts the expression annotations in the methodDeclType based on the
methodInvocationTree.
|
void |
viewpointAdaptTypeVariableBounds(TypeElement classDecl,
List<AnnotatedTypeParameterBounds> bounds,
TreePath pathToUse)
Viewpoint adapts the expression annotations on the bounds to the use of the type.
|
protected final AnnotatedTypeFactory factory
protected final List<Class<? extends Annotation>> expressionAnnos
public ExpressionAnnotationHelper(AnnotatedTypeFactory factory, List<Class<? extends Annotation>> expressionAnnos)
public ExpressionAnnotationHelper(AnnotatedTypeFactory factory, Class<? extends Annotation> anno)
public TreeAnnotator createExpressionAnnotationTreeAnnotator(AnnotatedTypeFactory factory)
factory
- annotated type factorypublic void viewpointAdaptTypeVariableBounds(TypeElement classDecl, List<AnnotatedTypeParameterBounds> bounds, TreePath pathToUse)
classDecl
- class or interface declaration whose type variables should be viewpoint
adaptedbounds
- annotated types of the bounds of the type variablespathToUse
- tree path to the use of the class or interfacepublic void viewpointAdaptMethod(MethodInvocationTree methodInvocationTree, AnnotatedTypeMirror.AnnotatedExecutableType methodDeclType)
methodInvocationTree
- use of the methodmethodDeclType
- type of the method declarationpublic void viewpointAdaptConstructor(NewClassTree newClassTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
newClassTree
- invocation of the constructorconstructorType
- type of the constructorpublic void standardizeNewClassTree(NewClassTree tree, AnnotatedTypeMirror.AnnotatedDeclaredType type)
public void standardizeReturnType(MethodTree m, AnnotatedTypeMirror atm)
public void standardizeVariable(Tree node, AnnotatedTypeMirror type, Element ele)
public void standardizeFieldAccess(MemberSelectTree node, AnnotatedTypeMirror type)
public void standardizeExpression(ExpressionTree tree, AnnotatedTypeMirror annotatedType)
public void standardizeVariable(AnnotatedTypeMirror type, Element elt)
protected String standardizeString(String expression, FlowExpressionParseUtil.FlowExpressionContext context, TreePath localScope, boolean useLocalScope)
public void checkType(AnnotatedTypeMirror atm, Tree errorTree)
atm
- annotated type to check for expression errorserrorTree
- the tree at which to report any found errorsprotected void reportErrors(Tree errorTree, List<ExpressionAnnotationError> errors)
public void checkMethod(MethodTree methodTree, AnnotatedTypeMirror.AnnotatedExecutableType type)
methodTree
- method to checktype
- annotated type of the method