public class BaseTypeVisitor<Factory extends GenericAnnotatedTypeFactory<?,?,?,?>> extends SourceVisitor<java.lang.Void,java.lang.Void>
SourceVisitor
that performs assignment and pseudo-assignment
checking, method invocation checking, and assignability checking.
This implementation uses the AnnotatedTypeFactory
implementation
provided by an associated BaseTypeChecker
; its visitor methods will
invoke this factory on parts of the AST to determine the "annotated type" of
an expression. Then, the visitor methods will check the types in assignments
and pseudo-assignments using commonAssignmentCheck(com.sun.source.tree.Tree, com.sun.source.tree.ExpressionTree, java.lang.String)
, which ultimately
calls the TypeHierarchy.isSubtype(org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror)
method and reports errors that
violate Java's rules of assignment.
Note that since this implementation only performs assignment and
pseudo-assignment checking, other rules for custom type systems must be added
in subclasses (e.g., dereference checking in the NullnessChecker
is
implemented in the NullnessChecker
's
TreeScanner.visitMemberSelect(com.sun.source.tree.MemberSelectTree, P)
method).
This implementation does the following checks:
1. Assignment and Pseudo-Assignment Check:
It verifies that any assignment type-checks, using
TypeHierarchy.isSubtype
method. This includes method invocation and
method overriding checks.
2. Type Validity Check:
It verifies that any user-supplied type is a valid type, using
isValidUse
method.
3. (Re-)Assignability Check:
It verifies that any assignment is valid, using
Checker.isAssignable
method.
TypeHierarchy.isSubtype(AnnotatedTypeMirror, AnnotatedTypeMirror)
,
AnnotatedTypeFactory
Modifier and Type | Field and Description |
---|---|
protected Factory |
atypeFactory
The factory to use for obtaining "parsed" version of annotations.
|
protected BaseTypeChecker |
checker
The
BaseTypeChecker for error reporting. |
protected ContractsUtils |
contractsUtils
An instance of the
ContractsUtils helper class. |
protected com.sun.source.util.SourcePositions |
positions
For obtaining line numbers in -Ashowchecks debugging output.
|
protected BaseTypeValidator |
typeValidator |
protected VisitorState |
visitorState
For storing visitor state.
|
elements, root, trees, types
Constructor and Description |
---|
BaseTypeVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkAccess(com.sun.source.tree.IdentifierTree node,
java.lang.Void p) |
protected void |
checkArguments(java.util.List<? extends AnnotatedTypeMirror> requiredArgs,
java.util.List<? extends com.sun.source.tree.ExpressionTree> passedArgs)
A helper method to check that each passed argument is a subtype of the
corresponding required argument, and issues "argument.invalid" error
for each passed argument that not a subtype of the required one.
|
protected void |
checkArrayInitialization(AnnotatedTypeMirror type,
java.util.List<? extends com.sun.source.tree.ExpressionTree> initializers) |
protected void |
checkAssignability(AnnotatedTypeMirror varType,
com.sun.source.tree.Tree varTree)
Tests, for a re-assignment, whether the variable is assignable or not.
|
protected void |
checkConditionalPostconditions(com.sun.source.tree.MethodTree node,
javax.lang.model.element.ExecutableElement methodElement)
Checks all conditional postcondition on the method
node with
element methodElement . |
protected void |
checkConditionalPostconditionsConsistency(com.sun.source.tree.MethodTree node,
javax.lang.model.element.ExecutableElement methodElement)
Checks all conditional postcondition on the method with element
methodElement for consistency. |
protected boolean |
checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt,
AnnotatedTypeMirror.AnnotatedExecutableType constructor,
com.sun.source.tree.Tree src) |
protected boolean |
checkContract(FlowExpressions.Receiver expr,
javax.lang.model.element.AnnotationMirror necessaryAnnotation,
javax.lang.model.element.AnnotationMirror inferredAnnotation,
CFAbstractStore<?,?> store)
Returns true if and only if
inferredAnnotation is valid for a
given expression to match the necessaryAnnotation . |
protected void |
checkDefaultConstructor(com.sun.source.tree.ClassTree node) |
protected void |
checkFlowExprParameters(javax.lang.model.element.ExecutableElement method,
java.lang.String stringExpr)
Check that the parameters used in
stringExpr are final for method
method . |
protected void |
checkForAnnotatedJdk()
Warn if the annotated JDK is not being used.
|
protected void |
checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method,
com.sun.source.tree.MethodInvocationTree node)
Tests whether the method can be invoked using the receiver of the 'node'
method invocation, and issues a "method.invocation.invalid" if the
invocation is invalid.
|
protected boolean |
checkOverride(com.sun.source.tree.MethodTree overriderTree,
AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType,
AnnotatedTypeMirror.AnnotatedExecutableType overridden,
AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType,
java.lang.Void p)
Checks that an overriding method's return type, parameter types, and
receiver type are correct with respect to the annotations on the
overridden method's return type, parameter types, and receiver type.
|
protected void |
checkPostconditions(com.sun.source.tree.MethodTree node,
javax.lang.model.element.ExecutableElement methodElement)
Checks all (non-conditional) postcondition on the method
node
with element methodElement . |
protected void |
checkPostconditionsConsistency(com.sun.source.tree.MethodTree node,
javax.lang.model.element.ExecutableElement methodElement)
Checks all (non-conditional) postcondition on the method
node
with element methodElement for consistency. |
protected void |
checkPreconditions(com.sun.source.tree.MethodInvocationTree tree,
javax.lang.model.element.ExecutableElement invokedMethodElement)
Checks all the preconditions of the method invocation
tree with
element invokedMethodElement . |
protected void |
checkPreconditionsConsistency(com.sun.source.tree.MethodTree node,
javax.lang.model.element.ExecutableElement methodElement)
Checks all the preconditions of the method with element
methodElement for consistency. |
protected void |
checkTypeArguments(com.sun.source.tree.Tree toptree,
java.util.List<? extends AnnotatedTypeMirror.AnnotatedTypeVariable> typevars,
java.util.List<? extends AnnotatedTypeMirror> typeargs,
java.util.List<? extends com.sun.source.tree.Tree> typeargTrees)
Checks that the annotations on the type arguments supplied to a type or a
method invocation are within the bounds of the type variables as
declared, and issues the "type.argument.type.incompatible" error if they are
not.
|
protected void |
checkTypecastRedundancy(com.sun.source.tree.TypeCastTree node,
java.lang.Void p) |
protected void |
checkTypecastSafety(com.sun.source.tree.TypeCastTree node,
java.lang.Void p) |
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
com.sun.source.tree.Tree valueTree,
@CompilerMessageKey java.lang.String errorKey,
boolean isLocalVariableAssignement)
Checks the validity of an assignment (or pseudo-assignment) from a value
to a variable and emits an error message (through the compiler's
messaging interface) if it is not valid.
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.String errorKey,
boolean isLocalVariableAssignement)
Checks the validity of an assignment (or pseudo-assignment) from a value
to a variable and emits an error message (through the compiler's
messaging interface) if it is not valid.
|
protected void |
commonAssignmentCheck(com.sun.source.tree.Tree varTree,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.String errorKey)
Checks the validity of an assignment (or pseudo-assignment) from a value
to a variable and emits an error message (through the compiler's
messaging interface) if it is not valid.
|
protected Factory |
createTypeFactory()
Constructs an instance of the appropriate type factory for the
implemented type system.
|
protected BaseTypeValidator |
createTypeValidator() |
protected com.sun.source.tree.MemberSelectTree |
enclosingMemberSelect() |
protected com.sun.source.tree.Tree |
enclosingStatement(com.sun.source.tree.Tree tree) |
Factory |
getTypeFactory() |
protected boolean |
isAccessAllowed(javax.lang.model.element.Element field,
AnnotatedTypeMirror receiver,
com.sun.source.tree.ExpressionTree accessTree) |
protected boolean |
isAssignable(AnnotatedTypeMirror varType,
AnnotatedTypeMirror receiverType,
com.sun.source.tree.Tree variable)
Tests whether the variable accessed is an assignable variable or not,
given the current scope
TODO: document which parameters are nullable; e.g.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedArrayType type,
com.sun.source.tree.Tree tree)
Tests that the qualifiers present on the array type are valid.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType,
com.sun.source.tree.Tree tree)
Tests that the qualifiers present on the useType are valid qualifiers,
given the qualifiers on the declaration of the type, declarationType.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedPrimitiveType type,
com.sun.source.tree.Tree tree)
Tests that the qualifiers present on the primitive type are valid.
|
protected boolean |
isVectorCopyInto(AnnotatedTypeMirror.AnnotatedExecutableType method)
Returns true if the method symbol represents
Vector.copyInto |
protected void |
reportPurityErrors(PurityChecker.PurityResult result,
com.sun.source.tree.MethodTree node,
java.util.Collection<Pure.Kind> expectedTypes)
Reports errors found during purity checking.
|
java.lang.Void |
scan(com.sun.source.tree.Tree tree,
java.lang.Void p) |
protected boolean |
shouldSkipUses(com.sun.source.tree.ExpressionTree exprTree)
Tests whether the expression should not be checked because of the tree
referring to unannotated classes, as specified in
the
checker.skipUses property. |
protected void |
typeCheckVectorCopyIntoArgument(com.sun.source.tree.MethodInvocationTree node,
java.util.List<? extends AnnotatedTypeMirror> params)
Type checks the method arguments of
Vector.copyInto() . |
boolean |
validateTypeOf(com.sun.source.tree.Tree tree)
Tests whether the tree expressed by the passed type tree is a valid type,
and emits an error if that is not the case (e.g.
|
java.lang.Void |
visit(com.sun.source.tree.CompilationUnitTree root,
com.sun.source.util.TreePath path,
java.lang.Void p) |
java.lang.Void |
visitAnnotation(com.sun.source.tree.AnnotationTree node,
java.lang.Void p)
Ensure that the annotation arguments comply to their declarations.
|
java.lang.Void |
visitArrayAccess(com.sun.source.tree.ArrayAccessTree node,
java.lang.Void p) |
java.lang.Void |
visitAssignment(com.sun.source.tree.AssignmentTree node,
java.lang.Void p)
Performs two checks: subtyping and assignability checks, using
commonAssignmentCheck(Tree, ExpressionTree, String) . |
java.lang.Void |
visitClass(com.sun.source.tree.ClassTree node,
java.lang.Void p) |
java.lang.Void |
visitCompilationUnit(com.sun.source.tree.CompilationUnitTree node,
java.lang.Void p)
Override Compilation Unit so we won't visit package names or imports
|
java.lang.Void |
visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node,
java.lang.Void p)
Performs assignability check using
checkAssignability(AnnotatedTypeMirror, Tree) . |
java.lang.Void |
visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node,
java.lang.Void p)
If the computation of the type of the ConditionalExpressionTree in
org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree, AnnotatedTypeFactory)
is correct, the following checks are redundant.
|
java.lang.Void |
visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node,
java.lang.Void p)
Performs a subtype check, to test whether the node expression
iterable type is a subtype of the variable type in the enhanced for
loop.
|
java.lang.Void |
visitIdentifier(com.sun.source.tree.IdentifierTree node,
java.lang.Void p) |
java.lang.Void |
visitInstanceOf(com.sun.source.tree.InstanceOfTree node,
java.lang.Void p) |
java.lang.Void |
visitMethod(com.sun.source.tree.MethodTree node,
java.lang.Void p)
Performs pseudo-assignment check: checks that the method obeys override
and subtype rules to all overridden methods.
|
java.lang.Void |
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
java.lang.Void p)
Performs a method invocation check.
|
java.lang.Void |
visitNewArray(com.sun.source.tree.NewArrayTree node,
java.lang.Void p) |
java.lang.Void |
visitNewClass(com.sun.source.tree.NewClassTree node,
java.lang.Void p)
Performs a new class invocation check.
|
java.lang.Void |
visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree node,
java.lang.Void p)
Do not override this method!
Previously, this method contained some logic, but the main modifier of types was missing.
|
java.lang.Void |
visitReturn(com.sun.source.tree.ReturnTree node,
java.lang.Void p)
Checks that the type of the return expression is a subtype of the
enclosing method required return type.
|
java.lang.Void |
visitTypeCast(com.sun.source.tree.TypeCastTree node,
java.lang.Void p) |
java.lang.Void |
visitTypeParameter(com.sun.source.tree.TypeParameterTree node,
java.lang.Void p) |
java.lang.Void |
visitUnary(com.sun.source.tree.UnaryTree node,
java.lang.Void p)
Performs assignability check using
checkAssignability(AnnotatedTypeMirror, Tree) . |
java.lang.Void |
visitVariable(com.sun.source.tree.VariableTree node,
java.lang.Void p) |
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitThrow, visitTry, visitUnionType, visitWhileLoop, visitWildcard
protected final BaseTypeChecker checker
BaseTypeChecker
for error reporting.protected final Factory extends GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory
protected final com.sun.source.util.SourcePositions positions
protected final VisitorState visitorState
protected final ContractsUtils contractsUtils
ContractsUtils
helper class.protected final BaseTypeValidator typeValidator
public BaseTypeVisitor(BaseTypeChecker checker)
checker
- the type-checker associated with this visitor (for callbacks to
TypeHierarchy.isSubtype(org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror)
)protected Factory createTypeFactory()
BaseAnnotatedTypeFactory
. It reflectively invokes the
constructor that accepts this checker and compilation unit tree
(in that order) as arguments.
Subclasses have to override this method to create the appropriate
visitor if they do not follow the checker naming convention.public final Factory getTypeFactory()
public java.lang.Void visit(com.sun.source.tree.CompilationUnitTree root, com.sun.source.util.TreePath path, java.lang.Void p)
visit
in class SourceVisitor<java.lang.Void,java.lang.Void>
public java.lang.Void scan(com.sun.source.tree.Tree tree, java.lang.Void p)
scan
in class com.sun.source.util.TreePathScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitClass(com.sun.source.tree.ClassTree node, java.lang.Void p)
visitClass
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitClass
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void checkDefaultConstructor(com.sun.source.tree.ClassTree node)
public java.lang.Void visitMethod(com.sun.source.tree.MethodTree node, java.lang.Void p)
visitMethod
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMethod
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void reportPurityErrors(PurityChecker.PurityResult result, com.sun.source.tree.MethodTree node, java.util.Collection<Pure.Kind> expectedTypes)
protected void checkPostconditions(com.sun.source.tree.MethodTree node, javax.lang.model.element.ExecutableElement methodElement)
node
with element methodElement
.protected void checkPostconditionsConsistency(com.sun.source.tree.MethodTree node, javax.lang.model.element.ExecutableElement methodElement)
node
with element methodElement
for consistency.protected void checkConditionalPostconditions(com.sun.source.tree.MethodTree node, javax.lang.model.element.ExecutableElement methodElement)
node
with
element methodElement
.protected void checkConditionalPostconditionsConsistency(com.sun.source.tree.MethodTree node, javax.lang.model.element.ExecutableElement methodElement)
methodElement
for consistency.protected void checkFlowExprParameters(javax.lang.model.element.ExecutableElement method, java.lang.String stringExpr)
stringExpr
are final for method
method
.public java.lang.Void visitTypeParameter(com.sun.source.tree.TypeParameterTree node, java.lang.Void p)
visitTypeParameter
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitTypeParameter
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitVariable(com.sun.source.tree.VariableTree node, java.lang.Void p)
visitVariable
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitVariable
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitAssignment(com.sun.source.tree.AssignmentTree node, java.lang.Void p)
commonAssignmentCheck(Tree, ExpressionTree, String)
.
If the subtype check fails, it issues a "assignment.type.incompatible" error.visitAssignment
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitAssignment
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node, java.lang.Void p)
visitEnhancedForLoop
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitEnhancedForLoop
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, java.lang.Void p)
visitMethodInvocation
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMethodInvocation
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void checkPreconditions(com.sun.source.tree.MethodInvocationTree tree, javax.lang.model.element.ExecutableElement invokedMethodElement)
tree
with
element invokedMethodElement
.protected void checkPreconditionsConsistency(com.sun.source.tree.MethodTree node, javax.lang.model.element.ExecutableElement methodElement)
methodElement
for consistency.protected boolean checkContract(FlowExpressions.Receiver expr, javax.lang.model.element.AnnotationMirror necessaryAnnotation, javax.lang.model.element.AnnotationMirror inferredAnnotation, CFAbstractStore<?,?> store)
inferredAnnotation
is valid for a
given expression to match the necessaryAnnotation
.
By default, inferredAnnotation
must be a subtype of
necessaryAnnotation
, but subclasses might override this behavior.
protected boolean isVectorCopyInto(AnnotatedTypeMirror.AnnotatedExecutableType method)
Vector.copyInto
protected void typeCheckVectorCopyIntoArgument(com.sun.source.tree.MethodInvocationTree node, java.util.List<? extends AnnotatedTypeMirror> params)
Vector.copyInto()
.
The Checker Framework special-cases the method invocation, as it is
type safety cannot be expressed by Java's type system.
For a Vector v
of type Vectory<E>
, the method
invocation v.copyInto(arr)
is type-safe iff arr
is a array of type T[]
, where T
is a subtype of
E
.
In other words, this method checks that the type argument of the
receiver method is a subtype of the component type of the passed array
argument.node
- a method invocation of Vector.copyInto()
params
- the types of the parameters of Vectory.copyInto()
public java.lang.Void visitNewClass(com.sun.source.tree.NewClassTree node, java.lang.Void p)
visitNewClass
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitNewClass
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitReturn(com.sun.source.tree.ReturnTree node, java.lang.Void p)
visitReturn
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitReturn
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitAnnotation(com.sun.source.tree.AnnotationTree node, java.lang.Void p)
visitAnnotation
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitAnnotation
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree node, java.lang.Void p)
visitConditionalExpression
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitConditionalExpression
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitUnary(com.sun.source.tree.UnaryTree node, java.lang.Void p)
checkAssignability(AnnotatedTypeMirror, Tree)
.visitUnary
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitUnary
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node, java.lang.Void p)
checkAssignability(AnnotatedTypeMirror, Tree)
.visitCompoundAssignment
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitCompoundAssignment
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitNewArray(com.sun.source.tree.NewArrayTree node, java.lang.Void p)
visitNewArray
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitNewArray
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public final java.lang.Void visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree node, java.lang.Void p)
visitParameterizedType
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitParameterizedType
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void checkTypecastRedundancy(com.sun.source.tree.TypeCastTree node, java.lang.Void p)
protected void checkTypecastSafety(com.sun.source.tree.TypeCastTree node, java.lang.Void p)
public java.lang.Void visitTypeCast(com.sun.source.tree.TypeCastTree node, java.lang.Void p)
visitTypeCast
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitTypeCast
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitInstanceOf(com.sun.source.tree.InstanceOfTree node, java.lang.Void p)
visitInstanceOf
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitInstanceOf
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitArrayAccess(com.sun.source.tree.ArrayAccessTree node, java.lang.Void p)
visitArrayAccess
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitArrayAccess
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void commonAssignmentCheck(com.sun.source.tree.Tree varTree, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.String errorKey)
varTree
- the AST node for the variablevalueExp
- the AST node for the valueerrorKey
- the error message to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)protected void commonAssignmentCheck(AnnotatedTypeMirror varType, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.String errorKey, boolean isLocalVariableAssignement)
varType
- the annotated type of the variablevalueExp
- the AST node for the valueerrorKey
- the error message to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)isLocalVariableAssignement
- Are we dealing with an assignment and is the lhs a local
variable?protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.String errorKey, boolean isLocalVariableAssignement)
varType
- the annotated type of the variablevalueType
- the annotated type of the valuevalueTree
- the location to use when reporting the error messageerrorKey
- the error message to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)isLocalVariableAssignement
- Are we dealing with an assignment and is the lhs a local
variable?protected void checkArrayInitialization(AnnotatedTypeMirror type, java.util.List<? extends com.sun.source.tree.ExpressionTree> initializers)
protected void checkTypeArguments(com.sun.source.tree.Tree toptree, java.util.List<? extends AnnotatedTypeMirror.AnnotatedTypeVariable> typevars, java.util.List<? extends AnnotatedTypeMirror> typeargs, java.util.List<? extends com.sun.source.tree.Tree> typeargTrees)
toptree
- the tree for error reporting, only used for inferred type argumentstypevars
- the type variables from a class or method declarationtypeargs
- the type arguments from the type or method invocationtypeargTrees
- the type arguments as trees, used for error reportingprotected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, com.sun.source.tree.MethodInvocationTree node)
method
- the type of the invoked methodnode
- the method invocation nodeprotected boolean checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, com.sun.source.tree.Tree src)
protected void checkArguments(java.util.List<? extends AnnotatedTypeMirror> requiredArgs, java.util.List<? extends com.sun.source.tree.ExpressionTree> passedArgs)
requiredArgs
- the required typespassedArgs
- the expressions passed to the corresponding typesprotected boolean checkOverride(com.sun.source.tree.MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, java.lang.Void p)
Furthermore, any contracts on the method must satisfy behavioral subtyping, that is, postconditions must be at least as strong as the postcondition on the superclass, and preconditions must be at most as strong as the condition on the superclass.
This method returns the result of the check, but also emits error messages as a side effect.
overriderTree
- the AST node of the overriding methodenclosingType
- the declared type enclosing the overrider methodoverridden
- the type of the overridden methodoverriddenType
- the declared type enclosing the overridden methodp
- an optional parameter (as supplied to visitor methods)protected void checkAssignability(AnnotatedTypeMirror varType, com.sun.source.tree.Tree varTree)
varType
- the type of the variable being re-assignedvarTree
- the tree used to access the variable in the assignmentprotected boolean isAssignable(AnnotatedTypeMirror varType, AnnotatedTypeMirror receiverType, com.sun.source.tree.Tree variable)
varType
- the annotated variable typevariable
- tree used to access the variableprotected com.sun.source.tree.MemberSelectTree enclosingMemberSelect()
protected com.sun.source.tree.Tree enclosingStatement(com.sun.source.tree.Tree tree)
public java.lang.Void visitIdentifier(com.sun.source.tree.IdentifierTree node, java.lang.Void p)
visitIdentifier
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitIdentifier
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void checkAccess(com.sun.source.tree.IdentifierTree node, java.lang.Void p)
protected boolean isAccessAllowed(javax.lang.model.element.Element field, AnnotatedTypeMirror receiver, com.sun.source.tree.ExpressionTree accessTree)
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, com.sun.source.tree.Tree tree)
The check is shallow, as it does not descend into generic or array
types (i.e. only performing the validity check on the raw type or
outermost array dimension). validateTypeOf(Tree)
would call this for each type argument or array dimension separately.
For instance, in the IGJ type system, a @Mutable
is an invalid
qualifier for String
, as String
is declared as
@Immutable String
.
In most cases, useType
simply needs to be a subtype of
declarationType
, but there are exceptions. In IGJ, a variable may be
declared @ReadOnly String
, even though String
is
@Immutable String
; ReadOnly
is not a subtype of
Immutable
.
declarationType
- the type of the class (TypeElement)useType
- the use of the class (instance type)tree
- the tree where the type is usedpublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedPrimitiveType type, com.sun.source.tree.Tree tree)
type
- the use of the primitive typetree
- the tree where the type is usedpublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedArrayType type, com.sun.source.tree.Tree tree)
type
- the array type usetree
- the tree where the type is usedpublic boolean validateTypeOf(com.sun.source.tree.Tree tree)
tree
- the AST type supplied by the userprotected BaseTypeValidator createTypeValidator()
protected final boolean shouldSkipUses(com.sun.source.tree.ExpressionTree exprTree)
checker.skipUses
property.
It returns true if exprTree is a method invocation or a field access
to a class whose qualified name matches @{link checker.skipUses}
expression.exprTree
- any expression treepublic java.lang.Void visitCompilationUnit(com.sun.source.tree.CompilationUnitTree node, java.lang.Void p)
visitCompilationUnit
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitCompilationUnit
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected void checkForAnnotatedJdk()