public class NullnessVisitor extends InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>
BaseTypeVisitor.OverrideCheckerannoFormatter, initializedFieldsatypeFactory, checker, contractsUtils, positions, typeValidator, visitorStateelements, root, trees, types| Constructor and Description |
|---|
NullnessVisitor(BaseTypeChecker checker,
boolean useFbc) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkExceptionParameter(com.sun.source.tree.CatchTree node)
Issue error if the exception parameter is not a supertype of the annotation specified by
BaseTypeVisitor.getExceptionParameterLowerBoundAnnotations(), which is top by default. |
protected void |
checkForRedundantTests(com.sun.source.tree.BinaryTree node)
Reports an error if a comparison of a @NonNull expression with the null literal is performed.
|
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 void |
checkThrownExpression(com.sun.source.tree.ThrowTree node)
Case 4: Check for thrown exception nullness
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
com.sun.source.tree.Tree valueTree,
@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 void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
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 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.
|
NullnessAnnotatedTypeFactory |
createTypeFactory()
Constructs an instance of the appropriate type factory for the implemented type system.
|
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.
|
java.lang.Void |
visitArrayAccess(com.sun.source.tree.ArrayAccessTree node,
java.lang.Void p)
Case 3: Check for array dereferencing
|
java.lang.Void |
visitAssert(com.sun.source.tree.AssertTree node,
java.lang.Void p) |
java.lang.Void |
visitBinary(com.sun.source.tree.BinaryTree node,
java.lang.Void p)
Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations
|
java.lang.Void |
visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node,
java.lang.Void p)
Case 7: unboxing case: primitive operation
|
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 |
visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree node,
java.lang.Void p) |
java.lang.Void |
visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree node,
java.lang.Void p)
Case 2: Check for implicit
.iterator call |
java.lang.Void |
visitForLoop(com.sun.source.tree.ForLoopTree node,
java.lang.Void p) |
java.lang.Void |
visitIf(com.sun.source.tree.IfTree node,
java.lang.Void p) |
java.lang.Void |
visitMemberSelect(com.sun.source.tree.MemberSelectTree node,
java.lang.Void p)
Case 1: Check for null dereferencing
|
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 |
visitSwitch(com.sun.source.tree.SwitchTree node,
java.lang.Void p) |
java.lang.Void |
visitSynchronized(com.sun.source.tree.SynchronizedTree node,
java.lang.Void p)
Case 5: Check for synchronizing locks
|
java.lang.Void |
visitTypeCast(com.sun.source.tree.TypeCastTree node,
java.lang.Void p)
Case 7: unboxing case: casting to a primitive
|
java.lang.Void |
visitUnary(com.sun.source.tree.UnaryTree node,
java.lang.Void p)
Case 7: unboxing case: primitive operation
|
java.lang.Void |
visitWhileLoop(com.sun.source.tree.WhileLoopTree node,
java.lang.Void p) |
checkConstructorInvocation, checkContract, checkFieldsInitialized, processClassTree, setRoot, visitBlock, visitMethod, visitVariablecheckAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostcondition, checkDefaultConstructor, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, createOverrideChecker, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isVectorCopyInto, reportPurityErrors, scan, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitParameterizedType, visitReturn, visitThrow, visitTry, visitTypeParametervisitreduce, scan, visitAnnotatedType, visitArrayType, visitBreak, visitCase, visitContinue, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitUnionType, visitWildcardpublic NullnessVisitor(BaseTypeChecker checker, boolean useFbc)
public NullnessAnnotatedTypeFactory createTypeFactory()
BaseTypeVisitorThe 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.
createTypeFactory in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, com.sun.source.tree.Tree tree)
BaseTypeVisitorThe 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). BaseTypeVisitor.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.
isValidUse in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>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)
BaseTypeVisitorThe default implementation always returns true. Subclasses should override this method to limit what annotations are allowed on primitive types.
isValidUse in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>type - the use of the primitive typetree - the tree where the type is usedprotected void commonAssignmentCheck(com.sun.source.tree.Tree varTree,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcommonAssignmentCheck in class InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>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, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcommonAssignmentCheck in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>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, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.String errorKey)
BaseTypeVisitorcommonAssignmentCheck in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>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)public java.lang.Void visitMemberSelect(com.sun.source.tree.MemberSelectTree node,
java.lang.Void p)
visitMemberSelect in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitMemberSelect 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)
.iterator callvisitEnhancedForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitEnhancedForLoop in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>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 BaseTypeVisitor<NullnessAnnotatedTypeFactory>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 BaseTypeVisitor<NullnessAnnotatedTypeFactory>protected void checkThrownExpression(com.sun.source.tree.ThrowTree node)
checkThrownExpression in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>node - ThrowTree to checkpublic java.lang.Void visitSynchronized(com.sun.source.tree.SynchronizedTree node,
java.lang.Void p)
visitSynchronized in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitSynchronized in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>public java.lang.Void visitAssert(com.sun.source.tree.AssertTree node,
java.lang.Void p)
visitAssert in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitAssert in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>public java.lang.Void visitIf(com.sun.source.tree.IfTree node,
java.lang.Void p)
visitIf in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitIf in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>protected void checkForRedundantTests(com.sun.source.tree.BinaryTree node)
public java.lang.Void visitBinary(com.sun.source.tree.BinaryTree node,
java.lang.Void p)
visitBinary in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitBinary 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)
visitUnary in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitUnary in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>public java.lang.Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node,
java.lang.Void p)
visitCompoundAssignment in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitCompoundAssignment in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>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 InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>protected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, com.sun.source.tree.MethodInvocationTree node)
BaseTypeVisitorThis 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.
checkMethodInvocability in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>method - the type of the invoked methodnode - the method invocation nodepublic java.lang.Void visitSwitch(com.sun.source.tree.SwitchTree node,
java.lang.Void p)
visitSwitch in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitSwitch in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>public java.lang.Void visitForLoop(com.sun.source.tree.ForLoopTree node,
java.lang.Void p)
visitForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitForLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>public java.lang.Void visitNewClass(com.sun.source.tree.NewClassTree node,
java.lang.Void p)
BaseTypeVisitorAn invocation of a constructor, c, is valid only if:
visitNewClass in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitNewClass in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>public java.lang.Void visitWhileLoop(com.sun.source.tree.WhileLoopTree node,
java.lang.Void p)
visitWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitWhileLoop in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>public java.lang.Void visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree node,
java.lang.Void p)
visitDoWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitDoWhileLoop 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)
BaseTypeVisitorvisitConditionalExpression in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>visitConditionalExpression in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>protected void checkExceptionParameter(com.sun.source.tree.CatchTree node)
BaseTypeVisitorBaseTypeVisitor.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 BaseTypeVisitor.getExceptionParameterLowerBoundAnnotations().
checkExceptionParameter in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>node - CatchTree to check