checkers.nullness
Class NullnessVisitor
java.lang.Object
com.sun.source.util.TreeScanner<R,P>
com.sun.source.util.TreePathScanner<R,P>
checkers.source.SourceVisitor<R,P>
checkers.basetype.BaseTypeVisitor<Void,Void>
checkers.nullness.NullnessVisitor
- All Implemented Interfaces:
- TreeVisitor<Void,Void>
public class NullnessVisitor
- extends BaseTypeVisitor<Void,Void>
A type-checking visitor for the Nullness type system.
This visitor reports errors ("dereference.of.nullable") or
warnings for violations for the following cases:
1. if the receiver of a member dereference is not NonNull
2. if the receiver of an implicit ".iterator()" dereference in an enhanced
for loop is not NonNull
3. if an accessed array is not NonNull
Self-accesses (via this
or super
) can always be dereferenced.
- See Also:
NullnessChecker
Method Summary |
protected boolean |
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. |
Void |
visitArrayAccess(ArrayAccessTree node,
Void p)
|
Void |
visitBinary(BinaryTree node,
Void p)
|
Void |
visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree) . |
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 |
visitMemberSelect(MemberSelectTree node,
Void p)
|
Void |
visitSynchronized(SynchronizedTree node,
Void p)
|
Void |
visitThrow(ThrowTree node,
Void p)
|
Void |
visitUnary(UnaryTree node,
Void p)
Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree) . |
Methods inherited from class checkers.basetype.BaseTypeVisitor |
checkArguments, checkAssignability, checkOverride, checkTypeArguments, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, scan, shouldSkip, shouldSkip, validateTypeOf, visitAnnotation, visitAssignment, visitClass, visitCompilationUnit, visitInstanceOf, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitTypeCast, visitVariable |
Methods inherited from class com.sun.source.util.TreeScanner |
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBlock, visitBreak, visitCase, visitCatch, visitConditionalExpression, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitLabeledStatement, visitLiteral, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitTry, visitTypeParameter, visitWhileLoop, visitWildcard |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NullnessVisitor
public NullnessVisitor(NullnessChecker checker,
CompilationUnitTree root)
- Creates a new visitor for type-checking
NonNull
.
- Parameters:
checker
- the checker to useroot
- the root of the input program's AST to check
visitMemberSelect
public Void visitMemberSelect(MemberSelectTree node,
Void p)
- Specified by:
visitMemberSelect
in interface TreeVisitor<Void,Void>
- Overrides:
visitMemberSelect
in class TreeScanner<Void,Void>
visitEnhancedForLoop
public Void visitEnhancedForLoop(EnhancedForLoopTree node,
Void p)
- Description copied from class:
BaseTypeVisitor
- Performs a subtype check, to test whether the node expression
iterable type is a subtype of the variable type in the enhanced for
loop.
If the subtype check fails, it issues a "type.incompatible" error.
- Specified by:
visitEnhancedForLoop
in interface TreeVisitor<Void,Void>
- Overrides:
visitEnhancedForLoop
in class BaseTypeVisitor<Void,Void>
visitArrayAccess
public Void visitArrayAccess(ArrayAccessTree node,
Void p)
- Specified by:
visitArrayAccess
in interface TreeVisitor<Void,Void>
- Overrides:
visitArrayAccess
in class TreeScanner<Void,Void>
visitThrow
public Void visitThrow(ThrowTree node,
Void p)
- Specified by:
visitThrow
in interface TreeVisitor<Void,Void>
- Overrides:
visitThrow
in class TreeScanner<Void,Void>
visitSynchronized
public Void visitSynchronized(SynchronizedTree node,
Void p)
- Specified by:
visitSynchronized
in interface TreeVisitor<Void,Void>
- Overrides:
visitSynchronized
in class TreeScanner<Void,Void>
visitUnary
public Void visitUnary(UnaryTree node,
Void p)
- Description copied from class:
BaseTypeVisitor
- Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree)
.
- Specified by:
visitUnary
in interface TreeVisitor<Void,Void>
- Overrides:
visitUnary
in class BaseTypeVisitor<Void,Void>
visitBinary
public Void visitBinary(BinaryTree node,
Void p)
- Specified by:
visitBinary
in interface TreeVisitor<Void,Void>
- Overrides:
visitBinary
in class TreeScanner<Void,Void>
visitCompoundAssignment
public Void visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
- Description copied from class:
BaseTypeVisitor
- Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree)
.
- Specified by:
visitCompoundAssignment
in interface TreeVisitor<Void,Void>
- Overrides:
visitCompoundAssignment
in class BaseTypeVisitor<Void,Void>
checkMethodInvocability
protected boolean checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method,
MethodInvocationTree node)
- Description copied from class:
BaseTypeVisitor
- 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.
This implementation tests whether the receiver in the method invocation
is a subtype of the method receiver type.
- Overrides:
checkMethodInvocability
in class BaseTypeVisitor<Void,Void>
- Parameters:
method
- the type of the invoked methodnode
- the method invocation node
- Returns:
- true iff the call of 'node' is a valid call