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)
Creates
DependentTypesHelper . |
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.
|
void |
delocalize(MethodTree methodDeclTree,
AnnotatedTypeMirror atm)
Viewpoint-adapt all dependent type annotations to the method declaration,
methodDeclTree . |
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,
@Nullable TreePath localVarPath,
AnnotationMirror anno,
boolean removeErroneousExpressions)
Viewpoint-adapts 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 |
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.
|
protected String |
standardizeString(String expression,
JavaExpressionParseUtil.JavaExpressionContext context,
@Nullable TreePath localVarPath)
Standardizes a Java expression.
|
void |
standardizeVariable(AnnotatedTypeMirror type,
Element elt)
Standardize the Java expressions in annotations in a type.
|
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.
|
AnnotationMirror |
viewpointAdaptQualifierFromContract(AnnotationMirror annoFromContract,
JavaExpressionParseUtil.JavaExpressionContext jeContext,
@Nullable Tree errorTree)
Viewpoint-adapt a type qualifier obtained from a contract to
jeContext . |
void |
viewpointAdaptTypeVariableBounds(TypeElement classDecl,
List<AnnotatedTypeParameterBounds> bounds)
Viewpoint-adapts the dependent type annotations on the bounds to the use of the type.
|
protected final AnnotatedTypeFactory factory
public DependentTypesHelper(AnnotatedTypeFactory factory)
DependentTypesHelper
.factory
- annotated type factorypublic boolean hasDependentAnnotations()
public void viewpointAdaptTypeVariableBounds(TypeElement classDecl, List<AnnotatedTypeParameterBounds> bounds)
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
methodpublic 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 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 AnnotationMirror viewpointAdaptQualifierFromContract(AnnotationMirror annoFromContract, JavaExpressionParseUtil.JavaExpressionContext jeContext, @Nullable Tree errorTree)
jeContext
.
For example, if the contract is @EnsuresKeyFor(value = "this.field", map =
"this.map")
, this method viewpoint-adapts @KeyFor("this.map")
to the given context.
annoFromContract
- an annotation from a contractjeContext
- the context to useerrorTree
- if non-null, where to report any errors that occur when parsing the
dependent type annotation; if null, report no errorspublic void delocalize(MethodTree methodDeclTree, AnnotatedTypeMirror atm)
methodDeclTree
. This changes occurrences of formal parameter names to "#2" syntax, and it
removes expressions that contain other local variables.methodDeclTree
- the method declaration to which the annotations are viewpoint-adaptedatm
- type to viewpoint-adapt; is side-effected by this methodpublic 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)
type
- the type to standardizeelt
- the element whose type is type
protected String standardizeString(String expression, JavaExpressionParseUtil.JavaExpressionContext context, @Nullable TreePath localVarPath)
expression
- a Java expressioncontext
- the contextlocalVarPath
- if non-null, the expression is parsed as if it were written at this
locationpublic AnnotationMirror standardizeAnnotationIfDependentType(JavaExpressionParseUtil.JavaExpressionContext context, @Nullable TreePath localVarPath, AnnotationMirror anno, boolean removeErroneousExpressions)
context
- information about any receiver and argumentslocalVarPath
- if non-null, the expression is parsed as if it were written at this
locationanno
- the annotation to viewpoint-adaptremoveErroneousExpressions
- 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