public class BaseTypeVisitor<Factory extends GenericAnnotatedTypeFactory<?,?,?,?>> extends SourceVisitor<Void,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:
TypeHierarchy.isSubtype
method. This includes method invocation and method
overriding checks.
isValidUse
method.
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 SourcePositions |
positions
For obtaining line numbers in -Ashowchecks debugging output.
|
protected TypeValidator |
typeValidator |
protected VisitorState |
visitorState
For storing visitor state.
|
elements, root, trees, types
Modifier | Constructor and Description |
---|---|
|
BaseTypeVisitor(BaseTypeChecker checker) |
protected |
BaseTypeVisitor(BaseTypeChecker checker,
Factory typeFactory) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkAccess(IdentifierTree node,
Void p) |
protected void |
checkArguments(List<? extends AnnotatedTypeMirror> requiredArgs,
List<? extends 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,
List<? extends ExpressionTree> initializers) |
protected void |
checkAssignability(AnnotatedTypeMirror varType,
Tree varTree)
Tests, for a re-assignment, whether the variable is assignable or not.
|
protected void |
checkConditionalPostcondition(MethodTree node,
AnnotationMirror annotation,
FlowExpressions.Receiver expression,
boolean result)
Check that the expression's type is annotated with
annotation at every regular exit
that returns result |
protected boolean |
checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType invocation,
AnnotatedTypeMirror.AnnotatedExecutableType constructor,
NewClassTree newClassTree) |
protected boolean |
checkContract(FlowExpressions.Receiver expr,
AnnotationMirror necessaryAnnotation,
AnnotationMirror inferredAnnotation,
CFAbstractStore<?,?> store)
Returns true if and only if
inferredAnnotation is valid for a given expression to
match the necessaryAnnotation . |
protected void |
checkDefaultConstructor(ClassTree node) |
protected void |
checkExceptionParameter(CatchTree node)
Issue error if the exception parameter is not a supertype of the annotation specified by
getExceptionParameterLowerBoundAnnotations() , which is top by default. |
protected void |
checkForAnnotatedJdk()
Warn if the annotated JDK is not being used.
|
protected void |
checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method,
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 |
checkMethodReferenceAsOverride(MemberReferenceTree memberReferenceTree,
Void p)
Check that a method reference is allowed.
|
protected boolean |
checkOverride(MethodTree overriderTree,
AnnotatedTypeMirror.AnnotatedDeclaredType overridingType,
AnnotatedTypeMirror.AnnotatedExecutableType overridden,
AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType,
Void p)
Type checks that a method may override another method.
|
protected void |
checkPostcondition(MethodTree methodTree,
AnnotationMirror annotation,
FlowExpressions.Receiver expression)
Check that the expression's type is annotated with
annotation at the regular exit
store. |
protected void |
checkPreconditions(MethodInvocationTree tree,
Set<ContractsUtils.Precondition> preconditions)
Checks that all the given
preconditions hold true immediately prior to the method
invocation or variable access at tree . |
protected void |
checkThrownExpression(ThrowTree node)
Checks the type of the thrown expression.
|
protected void |
checkTypeArguments(Tree toptree,
List<? extends AnnotatedTypeParameterBounds> paramBounds,
List<? extends AnnotatedTypeMirror> typeargs,
List<? extends 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(TypeCastTree node,
Void p) |
protected void |
checkTypecastSafety(TypeCastTree node,
Void p) |
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@CompilerMessageKey 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 void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
ExpressionTree valueExp,
@CompilerMessageKey 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 void |
commonAssignmentCheck(Tree varTree,
ExpressionTree valueExp,
@CompilerMessageKey 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 TypeValidator |
createTypeValidator() |
protected MemberSelectTree |
enclosingMemberSelect() |
protected Tree |
enclosingStatement(Tree tree) |
protected Set<? extends AnnotationMirror> |
getExceptionParameterLowerBoundAnnotations()
Returns a set of AnnotationMirrors that is a lower bound for exception parameters.
|
protected Set<? extends AnnotationMirror> |
getThrowUpperBoundAnnotations()
Returns a set of AnnotationMirrors that is a upper bound for thrown exceptions.
|
Factory |
getTypeFactory() |
protected boolean |
isAccessAllowed(Element field,
AnnotatedTypeMirror receiver,
ExpressionTree accessTree) |
protected boolean |
isAssignable(AnnotatedTypeMirror varType,
AnnotatedTypeMirror receiverType,
Tree variable)
Tests whether the variable accessed is an assignable variable or not, given the current scope
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedArrayType type,
Tree tree)
Tests that the qualifiers present on the array type are valid.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType,
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,
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 |
void |
processClassTree(ClassTree classTree)
Type-check classTree.
|
protected void |
reportPurityErrors(PurityChecker.PurityResult result,
MethodTree node,
Collection<Pure.Kind> expectedTypes)
Reports errors found during purity checking.
|
Void |
scan(Tree tree,
Void p) |
void |
setRoot(CompilationUnitTree root) |
protected boolean |
shouldSkipUses(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 boolean |
skipReceiverSubtypeCheck(MethodInvocationTree node,
AnnotatedTypeMirror methodDefinitionReceiver,
AnnotatedTypeMirror methodCallReceiver)
Indicates whether to skip subtype checks on the receiver when checking method invocability.
|
protected boolean |
testTypevarContainment(AnnotatedTypeMirror inner,
AnnotatedTypeMirror outer) |
protected void |
typeCheckVectorCopyIntoArgument(MethodInvocationTree node,
List<? extends AnnotatedTypeMirror> params)
Type checks the method arguments of
Vector.copyInto() . |
boolean |
validateType(Tree tree,
AnnotatedTypeMirror type)
Tests whether the type and corresponding type tree is a valid type, and emits an error if
that is not the case (e.g.
|
boolean |
validateTypeOf(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.
|
Void |
visitAnnotation(AnnotationTree node,
Void p)
Ensure that the annotation arguments comply to their declarations.
|
Void |
visitArrayAccess(ArrayAccessTree node,
Void p) |
Void |
visitAssignment(AssignmentTree node,
Void p)
Performs two checks: subtyping and assignability checks, using
commonAssignmentCheck(Tree, ExpressionTree, String) . |
Void |
visitCatch(CatchTree node,
Void p)
Checks the type of the exception parameter Subclasses should override
checkExceptionParameter(CatchTree node) rather than this method to change the behavior of
this check.
|
Void |
visitClass(ClassTree classTree,
Void p)
Type-check classTree and skips classes specified by the skipDef option.
|
Void |
visitCompilationUnit(CompilationUnitTree node,
Void p)
Override Compilation Unit so we won't visit package names or imports
|
Void |
visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
Performs assignability check using
checkAssignability(AnnotatedTypeMirror, Tree) . |
Void |
visitConditionalExpression(ConditionalExpressionTree node,
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.
|
Void |
visitEnhancedForLoop(EnhancedForLoopTree node,
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.
|
Void |
visitIdentifier(IdentifierTree node,
Void p) |
Void |
visitInstanceOf(InstanceOfTree node,
Void p) |
Void |
visitLambdaExpression(LambdaExpressionTree node,
Void p) |
Void |
visitMemberReference(MemberReferenceTree node,
Void p) |
Void |
visitMethod(MethodTree node,
Void p)
Performs pseudo-assignment check: checks that the method obeys override and subtype rules to
all overridden methods.
|
Void |
visitMethodInvocation(MethodInvocationTree node,
Void p)
Performs a method invocation check.
|
Void |
visitNewArray(NewArrayTree node,
Void p) |
Void |
visitNewClass(NewClassTree node,
Void p)
Performs a new class invocation check.
|
Void |
visitParameterizedType(ParameterizedTypeTree node,
Void p)
Do not override this method! Previously, this method contained some logic, but the main
modifier of types was missing.
|
Void |
visitReturn(ReturnTree node,
Void p)
Checks that the type of the return expression is a subtype of the enclosing method required
return type.
|
Void |
visitThrow(ThrowTree node,
Void p)
Checks the type of a thrown exception.
|
Void |
visitTypeCast(TypeCastTree node,
Void p) |
Void |
visitTypeParameter(TypeParameterTree node,
Void p) |
Void |
visitUnary(UnaryTree node,
Void p)
Performs assignability check using
checkAssignability(AnnotatedTypeMirror, Tree) . |
Void |
visitVariable(VariableTree node,
Void p) |
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitWhileLoop, visitWildcard
protected final BaseTypeChecker checker
BaseTypeChecker
for error reporting.protected final Factory extends GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory
protected final SourcePositions positions
protected final VisitorState visitorState
protected final ContractsUtils contractsUtils
ContractsUtils
helper class.protected final TypeValidator 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 BaseTypeVisitor(BaseTypeChecker checker, Factory typeFactory)
protected Factory createTypeFactory()
The default implementation uses the checker naming convention to create the appropriate
type factory. If no factory is found, it returns 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 void setRoot(CompilationUnitTree root)
setRoot
in class SourceVisitor<Void,Void>
public final Void visitClass(ClassTree classTree, Void p)
processClassTree(ClassTree)
instead of this method.visitClass
in interface TreeVisitor<Void,Void>
visitClass
in class TreeScanner<Void,Void>
classTree
- class to checkp
- nullpublic void processClassTree(ClassTree classTree)
visitClass(ClassTree, Void)
.classTree
- class to checkprotected void checkDefaultConstructor(ClassTree node)
public Void visitMethod(MethodTree node, Void p)
The override rule specifies that a method, m1, may override a method m2 only if:
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class TreeScanner<Void,Void>
protected void reportPurityErrors(PurityChecker.PurityResult result, MethodTree node, Collection<Pure.Kind> expectedTypes)
protected void checkPostcondition(MethodTree methodTree, AnnotationMirror annotation, FlowExpressions.Receiver expression)
annotation
at the regular exit
store.methodTree
- declaration of the methodannotation
- expression's type must have this annotationexpression
- the expression that the postcondition concernsprotected void checkConditionalPostcondition(MethodTree node, AnnotationMirror annotation, FlowExpressions.Receiver expression, boolean result)
annotation
at every regular exit
that returns result
node
- tree of method with the postconditionannotation
- expression's type must have this annotationexpression
- the expression that the postcondition concernsresult
- result for which the postcondition is validpublic Void visitTypeParameter(TypeParameterTree node, Void p)
visitTypeParameter
in interface TreeVisitor<Void,Void>
visitTypeParameter
in class TreeScanner<Void,Void>
public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class TreeScanner<Void,Void>
public Void visitAssignment(AssignmentTree node, Void p)
commonAssignmentCheck(Tree, ExpressionTree, String)
.
If the subtype check fails, it issues a "assignment.type.incompatible" error.
visitAssignment
in interface TreeVisitor<Void,Void>
visitAssignment
in class TreeScanner<Void,Void>
public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p)
If the subtype check fails, it issues a "enhancedfor.type.incompatible" error.
visitEnhancedForLoop
in interface TreeVisitor<Void,Void>
visitEnhancedForLoop
in class TreeScanner<Void,Void>
public Void visitMethodInvocation(MethodInvocationTree node, Void p)
An invocation of a method, m, on the receiver, r is valid only if:
visitMethodInvocation
in interface TreeVisitor<Void,Void>
visitMethodInvocation
in class TreeScanner<Void,Void>
protected void checkPreconditions(MethodInvocationTree tree, Set<ContractsUtils.Precondition> preconditions)
preconditions
hold true immediately prior to the method
invocation or variable access at tree
.tree
- the Tree immediately prior to which the preconditions must hold truepreconditions
- the preconditions to be checkedprotected boolean checkContract(FlowExpressions.Receiver expr, AnnotationMirror necessaryAnnotation, 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(MethodInvocationTree node, 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 Void visitNewClass(NewClassTree node, Void p)
An invocation of a constructor, c, is valid only if:
visitNewClass
in interface TreeVisitor<Void,Void>
visitNewClass
in class TreeScanner<Void,Void>
public Void visitLambdaExpression(LambdaExpressionTree node, Void p)
visitLambdaExpression
in interface TreeVisitor<Void,Void>
visitLambdaExpression
in class TreeScanner<Void,Void>
public Void visitMemberReference(MemberReferenceTree node, Void p)
visitMemberReference
in interface TreeVisitor<Void,Void>
visitMemberReference
in class TreeScanner<Void,Void>
public Void visitReturn(ReturnTree node, Void p)
visitReturn
in interface TreeVisitor<Void,Void>
visitReturn
in class TreeScanner<Void,Void>
public Void visitAnnotation(AnnotationTree node, Void p)
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class TreeScanner<Void,Void>
public Void visitConditionalExpression(ConditionalExpressionTree node, Void p)
visitConditionalExpression
in interface TreeVisitor<Void,Void>
visitConditionalExpression
in class TreeScanner<Void,Void>
public Void visitUnary(UnaryTree node, Void p)
checkAssignability(AnnotatedTypeMirror, Tree)
.visitUnary
in interface TreeVisitor<Void,Void>
visitUnary
in class TreeScanner<Void,Void>
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
checkAssignability(AnnotatedTypeMirror, Tree)
.visitCompoundAssignment
in interface TreeVisitor<Void,Void>
visitCompoundAssignment
in class TreeScanner<Void,Void>
public Void visitNewArray(NewArrayTree node, Void p)
visitNewArray
in interface TreeVisitor<Void,Void>
visitNewArray
in class TreeScanner<Void,Void>
public final Void visitParameterizedType(ParameterizedTypeTree node, Void p)
visitParameterizedType
in interface TreeVisitor<Void,Void>
visitParameterizedType
in class TreeScanner<Void,Void>
protected void checkTypecastRedundancy(TypeCastTree node, Void p)
protected void checkTypecastSafety(TypeCastTree node, Void p)
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class TreeScanner<Void,Void>
public Void visitInstanceOf(InstanceOfTree node, Void p)
visitInstanceOf
in interface TreeVisitor<Void,Void>
visitInstanceOf
in class TreeScanner<Void,Void>
public Void visitArrayAccess(ArrayAccessTree node, Void p)
visitArrayAccess
in interface TreeVisitor<Void,Void>
visitArrayAccess
in class TreeScanner<Void,Void>
public Void visitCatch(CatchTree node, Void p)
visitCatch
in interface TreeVisitor<Void,Void>
visitCatch
in class TreeScanner<Void,Void>
public Void visitThrow(ThrowTree node, Void p)
visitThrow
in interface TreeVisitor<Void,Void>
visitThrow
in class TreeScanner<Void,Void>
protected void checkExceptionParameter(CatchTree node)
getExceptionParameterLowerBoundAnnotations()
, which is top by default.
Subclasses may override this method to change the behavior of this check. Subclasses
wishing to enforce that exception parameter be annotated with other annotations can just
override getExceptionParameterLowerBoundAnnotations()
.
node
- CatchTree to checkprotected Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotations()
Note: by default this method is called by getThrowUpperBoundAnnotations(), so that this annotation is enforced.
(Default is top)
protected void checkThrownExpression(ThrowTree node)
By default, this method checks that the thrown expression is a subtype of top.
Issue error if the thrown expression is not a sub type of the annotation given by getThrowUpperBoundAnnotations()
, the same as getExceptionParameterLowerBoundAnnotations()
by default.
Subclasses may override this method to change the behavior of this check. Subclasses
wishing to enforce that the thrown expression be a subtype of a type besides getExceptionParameterLowerBoundAnnotations()
, should override getThrowUpperBoundAnnotations()
.
node
- ThrowTree to checkprotected Set<? extends AnnotationMirror> getThrowUpperBoundAnnotations()
Note: by default this method is returns by getExceptionParameterLowerBoundAnnotations(), so that this annotation is enforced.
(Default is top)
protected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
varTree
- the AST node for the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message to use if the check fails (must be a compiler message key,
see CompilerMessageKey
)protected void commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
varType
- the annotated type of the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message to use if the check fails (must be a compiler message key,
see CompilerMessageKey
)protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey)
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
)protected void checkArrayInitialization(AnnotatedTypeMirror type, List<? extends ExpressionTree> initializers)
protected void checkTypeArguments(Tree toptree, List<? extends AnnotatedTypeParameterBounds> paramBounds, List<? extends AnnotatedTypeMirror> typeargs, List<? extends Tree> typeargTrees)
toptree
- the tree for error reporting, only used for inferred type argumentsparamBounds
- the bounds of the type parameters from a class or method declarationtypeargs
- the type arguments from the type or method invocationtypeargTrees
- the type arguments as trees, used for error reportingprotected boolean skipReceiverSubtypeCheck(MethodInvocationTree node, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver)
node
- the method invocation nodemethodDefinitionReceiver
- the ATM of the receiver of the method definitionmethodCallReceiver
- the ATM of the receiver of the method callprotected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree node)
This implementation tests whether the receiver in the method invocation is a subtype of the method receiver type. This behavior can be specialized by overriding skipReceiverSubtypeCheck.
method
- the type of the invoked methodnode
- the method invocation nodeprotected boolean checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType invocation, AnnotatedTypeMirror.AnnotatedExecutableType constructor, NewClassTree newClassTree)
protected void checkArguments(List<? extends AnnotatedTypeMirror> requiredArgs, List<? extends ExpressionTree> passedArgs)
Note this method requires the lists to have the same length, as it does not handle cases like var args.
requiredArgs
- the required typespassedArgs
- the expressions passed to the corresponding typesprotected boolean testTypevarContainment(AnnotatedTypeMirror inner, AnnotatedTypeMirror outer)
protected boolean checkOverride(MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType overridingType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, Void p)
overriderTree
- declaration tree of overriding methodoverridingType
- type of overriding classoverridden
- type of overridden methodoverriddenType
- type of overridden classprotected boolean checkMethodReferenceAsOverride(MemberReferenceTree memberReferenceTree, Void p)
memberReferenceTree
- the tree for the method referenceprotected void checkAssignability(AnnotatedTypeMirror varType, 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, Tree variable)
TODO: document which parameters are nullable; e.g. receiverType is null in many cases, e.g. local variables.
varType
- the annotated variable typevariable
- tree used to access the variableprotected MemberSelectTree enclosingMemberSelect()
public Void visitIdentifier(IdentifierTree node, Void p)
visitIdentifier
in interface TreeVisitor<Void,Void>
visitIdentifier
in class TreeScanner<Void,Void>
protected void checkAccess(IdentifierTree node, Void p)
protected boolean isAccessAllowed(Element field, AnnotatedTypeMirror receiver, ExpressionTree accessTree)
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, 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.
In most cases, useType
simply needs to be a subtype of declarationType
,
but there are exceptions.
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, Tree tree)
The default implementation always returns true. Subclasses should override this method to limit what annotations are allowed on primitive types.
type
- the use of the primitive typetree
- the tree where the type is usedpublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedArrayType type, Tree tree)
The default implementation always returns true. Subclasses should override this method to limit what annotations are allowed on array types.
type
- the array type usetree
- the tree where the type is usedpublic boolean validateTypeOf(Tree tree)
tree
- the AST type supplied by the userpublic boolean validateType(Tree tree, AnnotatedTypeMirror type)
tree
- the type tree supplied by the usertype
- the type corresponding to treeprotected TypeValidator createTypeValidator()
protected final boolean shouldSkipUses(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 Void visitCompilationUnit(CompilationUnitTree node, Void p)
visitCompilationUnit
in interface TreeVisitor<Void,Void>
visitCompilationUnit
in class TreeScanner<Void,Void>
protected void checkForAnnotatedJdk()