public class NullnessVisitor extends InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>
annoFormatter, initializedFields
atypeFactory, checker, contractsUtils, positions, typeValidator, visitorState
elements, root, trees, types
Constructor and Description |
---|
NullnessVisitor(BaseTypeChecker checker,
boolean useFbc) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkExceptionParameter(CatchTree node)
Issue error if the exception parameter is not a super type of the
annotation specified by getExceptionParameterLowerBoundAnnotations(), which is top
by default (Subclasses may override this method to change the behavior of
this check.
|
protected void |
checkForRedundantTests(BinaryTree node)
Reports an error if a comparison of a @NonNull expression with the null
literal is performed.
|
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 void |
checkThrownExpression(ThrowTree node)
Case 4: Check for thrown exception nullness
|
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.
|
NullnessAnnotatedTypeFactory |
createTypeFactory()
Constructs an instance of the appropriate type factory for the
implemented type system.
|
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.
|
Void |
visitArrayAccess(ArrayAccessTree node,
Void p)
Case 3: Check for array dereferencing
|
Void |
visitAssert(AssertTree node,
Void p) |
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 |
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 |
visitDoWhileLoop(DoWhileLoopTree node,
Void p) |
Void |
visitEnhancedForLoop(EnhancedForLoopTree node,
Void p)
Case 2: Check for implicit
.iterator call |
Void |
visitForLoop(ForLoopTree node,
Void p) |
Void |
visitIf(IfTree node,
Void p) |
Void |
visitMemberSelect(MemberSelectTree node,
Void p)
Case 1: Check for null dereferencing
|
Void |
visitNewArray(NewArrayTree node,
Void p) |
Void |
visitNewClass(NewClassTree node,
Void p)
Performs a new class invocation check.
|
Void |
visitSwitch(SwitchTree node,
Void p) |
Void |
visitSynchronized(SynchronizedTree node,
Void p)
Case 5: Check for synchronizing locks
|
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
|
Void |
visitWhileLoop(WhileLoopTree node,
Void p) |
checkConstructorInvocation, checkContract, checkFieldsInitialized, getExplicitReturnTypeAnnotations, setRoot, visitBlock, visitClass, visitMethod, visitVariable
checkAccess, checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostconditions, checkConditionalPostconditionsConsistency, checkDefaultConstructor, checkFlowExprParameters, checkForAnnotatedJdk, checkMethodReferenceAsOverride, checkOverride, checkPostconditions, checkPostconditionsConsistency, checkPreconditions, checkPreconditions, checkPreconditionsConsistency, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, commonAssignmentCheck, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isVectorCopyInto, reportPurityErrors, scan, shouldSkipUses, skipContractCheck, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitAssignment, visitCatch, visitCompilationUnit, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitParameterizedType, visitReturn, visitThrow, visitTypeParameter
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitBreak, visitCase, visitContinue, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitTry, visitUnionType, visitWildcard
public NullnessVisitor(BaseTypeChecker checker, boolean useFbc)
public NullnessAnnotatedTypeFactory createTypeFactory()
BaseTypeVisitor
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, Tree tree)
BaseTypeVisitor
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). BaseTypeVisitor.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
.
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, Tree tree)
BaseTypeVisitor
isValidUse
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
type
- the use of the primitive typetree
- the tree where the type is usedprotected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
BaseTypeVisitor
commonAssignmentCheck
in class InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>
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, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
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
)public Void visitMemberSelect(MemberSelectTree node, Void p)
visitMemberSelect
in interface TreeVisitor<Void,Void>
visitMemberSelect
in class TreeScanner<Void,Void>
public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p)
.iterator
callvisitEnhancedForLoop
in interface TreeVisitor<Void,Void>
visitEnhancedForLoop
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
public Void visitArrayAccess(ArrayAccessTree node, Void p)
visitArrayAccess
in interface TreeVisitor<Void,Void>
visitArrayAccess
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
public Void visitNewArray(NewArrayTree node, Void p)
visitNewArray
in interface TreeVisitor<Void,Void>
visitNewArray
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
protected void checkThrownExpression(ThrowTree node)
checkThrownExpression
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
node
- ThrowTree to checkpublic Void visitSynchronized(SynchronizedTree node, Void p)
visitSynchronized
in interface TreeVisitor<Void,Void>
visitSynchronized
in class TreeScanner<Void,Void>
public Void visitAssert(AssertTree node, Void p)
visitAssert
in interface TreeVisitor<Void,Void>
visitAssert
in class TreeScanner<Void,Void>
public Void visitIf(IfTree node, Void p)
visitIf
in interface TreeVisitor<Void,Void>
visitIf
in class TreeScanner<Void,Void>
protected void checkForRedundantTests(BinaryTree node)
public Void visitBinary(BinaryTree node, Void p)
visitBinary
in interface TreeVisitor<Void,Void>
visitBinary
in class TreeScanner<Void,Void>
public Void visitUnary(UnaryTree node, Void p)
visitUnary
in interface TreeVisitor<Void,Void>
visitUnary
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
visitCompoundAssignment
in interface TreeVisitor<Void,Void>
visitCompoundAssignment
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class InitializationVisitor<NullnessAnnotatedTypeFactory,NullnessValue,NullnessStore>
protected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree node)
BaseTypeVisitor
checkMethodInvocability
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
method
- the type of the invoked methodnode
- the method invocation nodepublic Void visitSwitch(SwitchTree node, Void p)
visitSwitch
in interface TreeVisitor<Void,Void>
visitSwitch
in class TreeScanner<Void,Void>
public Void visitForLoop(ForLoopTree node, Void p)
visitForLoop
in interface TreeVisitor<Void,Void>
visitForLoop
in class TreeScanner<Void,Void>
public Void visitNewClass(NewClassTree node, Void p)
BaseTypeVisitor
visitNewClass
in interface TreeVisitor<Void,Void>
visitNewClass
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
public Void visitWhileLoop(WhileLoopTree node, Void p)
visitWhileLoop
in interface TreeVisitor<Void,Void>
visitWhileLoop
in class TreeScanner<Void,Void>
public Void visitDoWhileLoop(DoWhileLoopTree node, Void p)
visitDoWhileLoop
in interface TreeVisitor<Void,Void>
visitDoWhileLoop
in class TreeScanner<Void,Void>
public Void visitConditionalExpression(ConditionalExpressionTree node, Void p)
BaseTypeVisitor
visitConditionalExpression
in interface TreeVisitor<Void,Void>
visitConditionalExpression
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
protected void checkExceptionParameter(CatchTree node)
BaseTypeVisitor
checkExceptionParameter
in class BaseTypeVisitor<NullnessAnnotatedTypeFactory>
node
- CatchTree to check