checkers.nullness
Class NullnessVisitor

java.lang.Object
  extended by com.sun.source.util.TreeScanner<R,P>
      extended by com.sun.source.util.TreePathScanner<R,P>
          extended by checkers.source.SourceVisitor<R,P>
              extended by checkers.basetype.BaseTypeVisitor<Void,Void>
                  extended by 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 4. if a thrown exception is not NonNull 5. if the lock in a synchronized block is not NonNull 6. if a NonNull reference is checked for nullness 7. if a value in implicit unboxed operation is not NonNull Self-accesses (via this or super) can always be dereferenced.

See Also:
NullnessChecker

Field Summary
 
Fields inherited from class checkers.basetype.BaseTypeVisitor
annoFactory, annoTypes, checker, visitorState
 
Fields inherited from class checkers.source.SourceVisitor
atypeFactory, elements, root, trees, types
 
Constructor Summary
NullnessVisitor(NullnessChecker checker, CompilationUnitTree root)
          Creates a new visitor for type-checking NonNull.
 
Method Summary
protected  boolean checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree node)
          Special casing NonNull and Raw method calls
 Void visitArrayAccess(ArrayAccessTree node, Void p)
          Case 3: Check for array dereferencing
 Void visitBinary(BinaryTree node, Void p)
          Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations
 Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
          Case 7: unboxing case: primitive operation
 Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p)
          Case 2: Check for implicit .iterator call
 Void visitMemberSelect(MemberSelectTree node, Void p)
          Case 1: Check for null dereferecing
 Void visitSynchronized(SynchronizedTree node, Void p)
          Case 5: Check for synchronizing locks
 Void visitThrow(ThrowTree node, Void p)
          Case 4: Check for thrown exception nullness
 Void visitTypeCast(TypeCastTree node, Void p)
          Case 7: unboxing case: casting to a primitive
 Void visitUnary(UnaryTree node, Void p)
          Case 7: unboxing case: primitive operation
 
Methods inherited from class checkers.basetype.BaseTypeVisitor
checkArguments, checkArrayInitialization, checkAssignability, checkOverride, checkTypeArguments, checkTypecastSafety, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheck, scan, shouldSkip, shouldSkip, validateTypeOf, visitAnnotation, visitAssignment, visitClass, visitCompilationUnit, visitInstanceOf, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitVariable
 
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
 
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
 

Constructor Detail

NullnessVisitor

public NullnessVisitor(NullnessChecker checker,
                       CompilationUnitTree root)
Creates a new visitor for type-checking NonNull.

Parameters:
checker - the checker to use
root - the root of the input program's AST to check
Method Detail

visitMemberSelect

public Void visitMemberSelect(MemberSelectTree node,
                              Void p)
Case 1: Check for null dereferecing

Specified by:
visitMemberSelect in interface TreeVisitor<Void,Void>
Overrides:
visitMemberSelect in class TreeScanner<Void,Void>

visitEnhancedForLoop

public Void visitEnhancedForLoop(EnhancedForLoopTree node,
                                 Void p)
Case 2: Check for implicit .iterator call

Specified by:
visitEnhancedForLoop in interface TreeVisitor<Void,Void>
Overrides:
visitEnhancedForLoop in class BaseTypeVisitor<Void,Void>

visitArrayAccess

public Void visitArrayAccess(ArrayAccessTree node,
                             Void p)
Case 3: Check for array dereferencing

Specified by:
visitArrayAccess in interface TreeVisitor<Void,Void>
Overrides:
visitArrayAccess in class TreeScanner<Void,Void>

visitThrow

public Void visitThrow(ThrowTree node,
                       Void p)
Case 4: Check for thrown exception nullness

Specified by:
visitThrow in interface TreeVisitor<Void,Void>
Overrides:
visitThrow in class TreeScanner<Void,Void>

visitSynchronized

public Void visitSynchronized(SynchronizedTree node,
                              Void p)
Case 5: Check for synchronizing locks

Specified by:
visitSynchronized in interface TreeVisitor<Void,Void>
Overrides:
visitSynchronized in class TreeScanner<Void,Void>

visitBinary

public Void visitBinary(BinaryTree node,
                        Void p)
Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations

Specified by:
visitBinary in interface TreeVisitor<Void,Void>
Overrides:
visitBinary in class TreeScanner<Void,Void>

visitUnary

public Void visitUnary(UnaryTree node,
                       Void p)
Case 7: unboxing case: primitive operation

Specified by:
visitUnary in interface TreeVisitor<Void,Void>
Overrides:
visitUnary in class BaseTypeVisitor<Void,Void>

visitCompoundAssignment

public Void visitCompoundAssignment(CompoundAssignmentTree node,
                                    Void p)
Case 7: unboxing case: primitive operation

Specified by:
visitCompoundAssignment in interface TreeVisitor<Void,Void>
Overrides:
visitCompoundAssignment in class BaseTypeVisitor<Void,Void>

visitTypeCast

public Void visitTypeCast(TypeCastTree node,
                          Void p)
Case 7: unboxing case: casting to a primitive

Specified by:
visitTypeCast in interface TreeVisitor<Void,Void>
Overrides:
visitTypeCast in class BaseTypeVisitor<Void,Void>

checkMethodInvocability

protected boolean checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method,
                                          MethodInvocationTree node)
Special casing NonNull and Raw method calls

Overrides:
checkMethodInvocability in class BaseTypeVisitor<Void,Void>
Parameters:
method - the type of the invoked method
node - the method invocation node
Returns:
true iff the call of 'node' is a valid call