public class DependentTypesHelper 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 AnnotatedTypeFactory |
factory |
Constructor and Description |
---|
DependentTypesHelper(AnnotatedTypeFactory factory) |
Modifier and Type | Method and Description |
---|---|
void |
checkMethod(MethodTree methodTree,
AnnotatedTypeMirror.AnnotatedExecutableType type)
Checks all expressions in the method declaration AnnotatedTypeMirror to see if the expression
string is an error string as specified by DependentTypesError#isExpressionError.
|
void |
checkType(AnnotatedTypeMirror atm,
Tree errorTree)
Checks all expression in the given annotated type to see if the expression string is an error
string as specified by
DependentTypesError.isExpressionError(java.lang.String) . |
TreeAnnotator |
createDependentTypesTreeAnnotator(AnnotatedTypeFactory factory)
Creates a TreeAnnotator that standardizes dependent type annotations.
|
boolean |
hasDependentAnnotations()
Returns true if any qualifier in the type system is a dependent type annotation.
|
protected void |
reportErrors(Tree errorTree,
List<DependentTypesError> 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 dependent type annotations in the constructorType based on the
newClassTree.
|
void |
viewpointAdaptMethod(MethodInvocationTree methodInvocationTree,
AnnotatedTypeMirror.AnnotatedExecutableType methodDeclType)
Viewpoint adapts the dependent type annotations in the methodDeclType based on the
methodInvocationTree.
|
void |
viewpointAdaptTypeVariableBounds(TypeElement classDecl,
List<AnnotatedTypeParameterBounds> bounds,
TreePath pathToUse)
Viewpoint adapts the dependent type annotations on the bounds to the use of the type.
|
protected final AnnotatedTypeFactory factory
public DependentTypesHelper(AnnotatedTypeFactory factory)
public TreeAnnotator createDependentTypesTreeAnnotator(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 boolean hasDependentAnnotations()
public void checkType(AnnotatedTypeMirror atm, Tree errorTree)
DependentTypesError.isExpressionError(java.lang.String)
. If the annotated type
has any errors, a flowexpr.parse.error is issued at the errorTree.atm
- annotated type to check for expression errorserrorTree
- the tree at which to report any found errorsprotected void reportErrors(Tree errorTree, List<DependentTypesError> errors)
public void checkMethod(MethodTree methodTree, AnnotatedTypeMirror.AnnotatedExecutableType type)
methodTree
- method to checktype
- annotated type of the method