public class DependentTypesHelper extends Object
@KeyFor("m")
would be changed to
@KeyFor("[error for expression: m error: m: identifier not found]")
if m is not a
valid identifier. This allows subtyping checks to assume that if two strings are equal and
not errors, the reference the same valid Java expression.
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 |
checkAnnotation(AnnotationMirror annotation,
Tree errorTree)
Checks every Java expression element of the annotation to see if the expression is an error
string as specified by DependentTypesError#isExpressionError.
|
void |
checkClass(ClassTree classTree,
AnnotatedTypeMirror.AnnotatedDeclaredType type)
Checks all Java expressions in the class declaration AnnotatedTypeMirror to see if the
expression string is an error string as specified by DependentTypesError#isExpressionError.
|
void |
checkMethod(MethodTree methodDeclTree,
AnnotatedTypeMirror.AnnotatedExecutableType type)
Checks all Java 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 Java expressions 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()
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)
Report the given errors as "expression.unparsable.type.invalid".
|
AnnotationMirror |
standardizeAnnotationIfDependentType(JavaExpressionParseUtil.JavaExpressionContext context,
TreePath localScope,
AnnotationMirror anno,
boolean useLocalScope,
boolean removeErroneousExpressions)
Standardizes Java expressions in an annotation.
|
void |
standardizeClass(ClassTree node,
AnnotatedTypeMirror type,
Element classElt)
Standardize the Java expressions in annotations in a class declaration.
|
void |
standardizeExpression(ExpressionTree tree,
AnnotatedTypeMirror annotatedType)
Standardize the Java expressions in annotations in the type of an expression.
|
void |
standardizeFieldAccess(MemberSelectTree node,
AnnotatedTypeMirror type)
Standardize the Java expressions in annotations in a field access.
|
void |
standardizeForMethodSignature(MethodTree methodDeclTree,
TreePath pathToMethodDecl,
Element elt,
AnnotatedTypeMirror atm,
boolean removeErroneousExpressions)
Standardizes the Java expressions in annotations for a method signature location, including:
type annotations on a return type, formal parameter type, or exception type, and
declaration annotations on a method (such as a pre- or post-condition contract
annotation) or formal parameter.
|
void |
standardizeNewClassTree(NewClassTree tree,
AnnotatedTypeMirror.AnnotatedDeclaredType type)
Standardizes the Java expressions in annotations on a constructor invocation.
|
void |
standardizeReturnType(MethodTree methodDeclTree,
AnnotatedTypeMirror atm)
Standardizes the Java expressions in annotations for a method return type.
|
void |
standardizeReturnType(MethodTree methodDeclTree,
AnnotatedTypeMirror atm,
boolean removeErroneousExpressions)
Standardizes the Java expressions in annotations for a method return type.
|
protected String |
standardizeString(String expression,
JavaExpressionParseUtil.JavaExpressionContext context,
TreePath localScope,
boolean useLocalScope)
Standardizes a Java expression.
|
void |
standardizeVariable(AnnotatedTypeMirror type,
Element elt) |
void |
standardizeVariable(Tree declarationTree,
AnnotatedTypeMirror type,
Element variableElt)
Standardize the Java expressions in annotations in a variable declaration.
|
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 boolean hasDependentAnnotations()
public 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 variables; side-effected by this
methodpathToUse
- 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 declaration; is side-effected by this methodpublic void viewpointAdaptConstructor(NewClassTree newClassTree, AnnotatedTypeMirror.AnnotatedExecutableType constructorType)
newClassTree
- invocation of the constructorconstructorType
- type of the constructor; is side-effected by this methodpublic TreeAnnotator createDependentTypesTreeAnnotator()
public void standardizeNewClassTree(NewClassTree tree, AnnotatedTypeMirror.AnnotatedDeclaredType type)
tree
- the constructor invocationtype
- the type of the expression; is side-effected by this methodpublic void standardizeClass(ClassTree node, AnnotatedTypeMirror type, Element classElt)
node
- the class declarationtype
- the type of the class declaration; is side-effected by this methodclassElt
- the element of the class declarationpublic final void standardizeReturnType(MethodTree methodDeclTree, AnnotatedTypeMirror atm)
atm
might
come from the method declaration or from the type of the expression in a return
statement.methodDeclTree
- a method declarationatm
- the method return type; is side-effected by this methodpublic void standardizeReturnType(MethodTree methodDeclTree, AnnotatedTypeMirror atm, boolean removeErroneousExpressions)
atm
might
come from the method declaration or from the type of the expression in a return
statement.methodDeclTree
- a method declarationatm
- the method return type; is side-effected by this methodremoveErroneousExpressions
- if true, remove erroneous expressions rather than
converting them into an explanation of why they are illegalpublic void standardizeForMethodSignature(MethodTree methodDeclTree, TreePath pathToMethodDecl, Element elt, AnnotatedTypeMirror atm, boolean removeErroneousExpressions)
methodDeclTree
- a method declarationpathToMethodDecl
- the path to the method declarationelt
- the element for the method or a formal parameter; used for obtaining the enclosing
classatm
- a type that has a dependent type annotation; is side-effected by this methodremoveErroneousExpressions
- if true, remove erroneous expressions rather than
converting them into an explanation of why they are illegalpublic void standardizeVariable(Tree declarationTree, AnnotatedTypeMirror type, Element variableElt)
declarationTree
- the variable declarationtype
- the type of the variable declarationvariableElt
- the element of the variable declarationpublic void standardizeFieldAccess(MemberSelectTree node, AnnotatedTypeMirror type)
node
- a field accesstype
- its type; is side-effected by this methodpublic void standardizeExpression(ExpressionTree tree, AnnotatedTypeMirror annotatedType)
tree
- an expressionannotatedType
- its type; is side-effected by this methodpublic void standardizeVariable(AnnotatedTypeMirror type, Element elt)
protected String standardizeString(String expression, JavaExpressionParseUtil.JavaExpressionContext context, TreePath localScope, boolean useLocalScope)
expression
- a Java expressioncontext
- the contextlocalScope
- the local scopeuseLocalScope
- whether localScope
should be used to resolve identifierspublic AnnotationMirror standardizeAnnotationIfDependentType(JavaExpressionParseUtil.JavaExpressionContext context, TreePath localScope, AnnotationMirror anno, boolean useLocalScope, boolean removeErroneousExpressions)
context
- information about any receiver and argumentslocalScope
- path to local scope to useanno
- the annotation to be standardizeduseLocalScope
- whether the local scope should be used to resolve identifiersremoveErroneousExpressions
- if true, remove erroneous expressions rather than
converting them into an explanation of why they are illegalpublic void checkType(AnnotatedTypeMirror atm, Tree errorTree)
DependentTypesError.isExpressionError(java.lang.String)
. If the annotated
type has any errors, an expression.unparsable.type.invalid 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)
errorTree
- where to report the errorserrors
- the errors to reportpublic void checkAnnotation(AnnotationMirror annotation, Tree errorTree)
errorTree
.annotation
- annotation to checkerrorTree
- location at which to issue errorspublic void checkClass(ClassTree classTree, AnnotatedTypeMirror.AnnotatedDeclaredType type)
classTree
- class to checktype
- annotated type of the classpublic void checkMethod(MethodTree methodDeclTree, AnnotatedTypeMirror.AnnotatedExecutableType type)
methodDeclTree
- method to checktype
- annotated type of the method