Class NullnessNoInitVisitor
- All Implemented Interfaces:
TreeVisitor<Void,
Void>
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.FoundRequired, BaseTypeVisitor.OverrideChecker
-
Field Summary
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
assumePureGetters, atypeFactory, checker, DETERMINISTIC, ignoreTargetLocations, IMPURE, methodTree, positions, PURE, qualAllowedLocations, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
Constructor Summary
ConstructorDescriptionNullnessNoInitVisitor
(BaseTypeChecker checker) Create a new NullnessVisitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkConstructorResult
(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.protected void
Issue error if the exception parameter is not a supertype of the annotation specified byBaseTypeVisitor.getExceptionParameterLowerBoundAnnotations()
, which is top by default.protected void
Reports an error if a comparison of a @NonNull expression with the null literal is performed.protected void
checkMethodInvocability
(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree tree) Tests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation.invalid" if the invocation is invalid.protected void
checkThisOrSuperConstructorCall
(MethodInvocationTree superCall, @CompilerMessageKey String errorKey) Checks that the following rule is satisfied: The type on a constructor declaration must be a supertype of the return type of "this()" or "super()" invocation within that constructor.protected void
Case 4: Check for thrown exception nullness.protected boolean
commonAssignmentCheck
(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) 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 boolean
commonAssignmentCheck
(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) 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 boolean
commonAssignmentCheck
(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) 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.Constructs an instance of the appropriate type factory for the implemented type system.protected TypeValidator
boolean
isValidUse
(AnnotatedTypeMirror.AnnotatedPrimitiveType type, Tree tree) Tests that the qualifiers present on the primitive type are valid.void
processClassTree
(ClassTree classTree) Type-check classTree.void
visitAnnotatedType
(@Nullable List<? extends AnnotationTree> annoTrees, Tree typeTree) Checks an annotated type.visitAnnotation
(AnnotationTree tree, Void p) Ensure that the annotation arguments comply to their declarations.visitArrayAccess
(ArrayAccessTree tree, Void p) Case 3: Check for array dereferencing.visitAssert
(AssertTree tree, Void p) visitBinary
(BinaryTree tree, Void p) Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations.Case 7: unboxing case: primitive operation.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.visitDoWhileLoop
(DoWhileLoopTree tree, Void p) visitEnhancedForLoop
(EnhancedForLoopTree tree, Void p) Case 2: Check for implicit.iterator
call.visitForLoop
(ForLoopTree tree, Void p) visitInstanceOf
(InstanceOfTree tree, Void p) visitMemberSelect
(MemberSelectTree tree, Void p) Case 1: Check for null dereferencing.visitMethod
(MethodTree tree, Void p) Checks that the method obeys override and subtype rules to all overridden methods.Performs a method invocation check.visitNewArray
(NewArrayTree tree, Void p) visitNewClass
(NewClassTree tree, Void p) Performs a new class invocation check.visitSwitch
(SwitchTree tree, Void p) void
visitSwitchExpression17
(Tree switchExprTree) This method validates the type of the switch expression.visitSynchronized
(SynchronizedTree tree, Void p) Case 5: Check for synchronizing locks.visitTypeCast
(TypeCastTree tree, Void p) Case 7: unboxing case: casting to a primitive.visitUnary
(UnaryTree tree, Void p) Case 7: unboxing case: primitive operation.visitWhileLoop
(WhileLoopTree tree, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkEnclosingExpr, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createQualAllowedLocations, createTypeFactoryPublic, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, reportCommonAssignmentError, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTargetLocation, validateType, validateTypeOf, validateVariablesTargetLocation, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitIdentifier, visitLambdaExpression, visitMemberReference, visitReturn, visitThrow, visitTypeParameter, visitVariable, warnAboutIrrelevantJavaTypes, warnRedundantAnnotations
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnyPattern, visitArrayType, visitBindingPattern, visitBlock, visitBreak, visitCase, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitStringTemplate, visitSwitchExpression, visitTry, visitUnionType, visitUses, visitWildcard, visitYield
-
Constructor Details
-
NullnessNoInitVisitor
Create a new NullnessVisitor.- Parameters:
checker
- the checker to which this visitor belongs
-
-
Method Details
-
createTypeFactory
Description copied from class:BaseTypeVisitor
Constructs an instance of the appropriate type factory for the implemented type system.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.
- Overrides:
createTypeFactory
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Returns:
- the appropriate type factory
-
isValidUse
Description copied from class:BaseTypeVisitor
Tests that the qualifiers present on the primitive type are valid.- Overrides:
isValidUse
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
type
- the use of the primitive typetree
- the tree where the type is used- Returns:
- true if the type is a valid use of the primitive type
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Description copied from class:BaseTypeVisitor
Issue a warning if the result type of the constructor declaration is not top. If it is a supertype of the class, then a type.invalid.conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.- Overrides:
checkConstructorResult
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
constructorType
- the AnnotatedExecutableType for the constructorconstructorElement
- the element that declares the constructor
-
checkThisOrSuperConstructorCall
protected void checkThisOrSuperConstructorCall(MethodInvocationTree superCall, @CompilerMessageKey String errorKey) Description copied from class:BaseTypeVisitor
Checks that the following rule is satisfied: The type on a constructor declaration must be a supertype of the return type of "this()" or "super()" invocation within that constructor.- Overrides:
checkThisOrSuperConstructorCall
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
superCall
- the AST node for the constructor callerrorKey
- the error message key to use if the check fails
-
commonAssignmentCheck
protected boolean commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitor
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.- Overrides:
commonAssignmentCheck
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
varTree
- the AST node for the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" types- Returns:
- true if the check succeeds, false if an error message was issued
-
commonAssignmentCheck
protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitor
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.- Overrides:
commonAssignmentCheck
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
varType
- the annotated type for the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" types- Returns:
- true if the check succeeds, false if an error message was issued
-
commonAssignmentCheck
@FormatMethod protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitor
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.- Overrides:
commonAssignmentCheck
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
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 key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" types- Returns:
- true if the check succeeds, false if an error message was issued
-
visitMemberSelect
Case 1: Check for null dereferencing.- Specified by:
visitMemberSelect
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitMemberSelect
in classTreeScanner<Void,
Void>
-
visitEnhancedForLoop
Case 2: Check for implicit.iterator
call.- Specified by:
visitEnhancedForLoop
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitEnhancedForLoop
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitArrayAccess
Case 3: Check for array dereferencing.- Specified by:
visitArrayAccess
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitArrayAccess
in classTreeScanner<Void,
Void>
-
visitNewArray
- Specified by:
visitNewArray
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitNewArray
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkThrownExpression
Case 4: Check for thrown exception nullness.- Overrides:
checkThrownExpression
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
tree
- a ThrowTree to check
-
visitSynchronized
Case 5: Check for synchronizing locks.- Specified by:
visitSynchronized
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitSynchronized
in classTreeScanner<Void,
Void>
-
visitAssert
- Specified by:
visitAssert
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitAssert
in classTreeScanner<Void,
Void>
-
visitIf
- Specified by:
visitIf
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitIf
in classTreeScanner<Void,
Void>
-
visitInstanceOf
- Specified by:
visitInstanceOf
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitInstanceOf
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkForRedundantTests
Reports an error if a comparison of a @NonNull expression with the null literal is performed. Does nothing unless-Alint=redundantNullComparison
is passed on the command line.- Parameters:
tree
- a tree that might be a comparison of a @NonNull expression with the null literal
-
visitBinary
Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations.- Specified by:
visitBinary
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitBinary
in classTreeScanner<Void,
Void>
-
visitUnary
Case 7: unboxing case: primitive operation.- Specified by:
visitUnary
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitUnary
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitCompoundAssignment
Case 7: unboxing case: primitive operation.- Specified by:
visitCompoundAssignment
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitCompoundAssignment
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitTypeCast
Case 7: unboxing case: casting to a primitive.- Specified by:
visitTypeCast
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitTypeCast
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitMethod
Description copied from class:BaseTypeVisitor
Checks that the method obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)The override rule specifies that a method, m1, may override a method m2 only if:
- m1 return type is a subtype of m2
- m1 receiver type is a supertype of m2
- m1 parameters are supertypes of corresponding m2 parameters
- Specified by:
visitMethod
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitMethod
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitMethodInvocation
Description copied from class:BaseTypeVisitor
Performs a method invocation check.An invocation of a method, m, on the receiver, r is valid only if:
- passed arguments are subtypes of corresponding m parameters
- r is a subtype of m receiver type
- if m is generic, passed type arguments are subtypes of m type variables
- Specified by:
visitMethodInvocation
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitMethodInvocation
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
processClassTree
Description copied from class:BaseTypeVisitor
Type-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void)
.- Overrides:
processClassTree
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
classTree
- class to check
-
checkMethodInvocability
protected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree tree) Description copied from class:BaseTypeVisitor
Tests whether the method can be invoked using the receiver of the 'tree' 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. This behavior can be specialized by overriding skipReceiverSubtypeCheck.
- Overrides:
checkMethodInvocability
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
method
- the type of the invoked methodtree
- the method invocation tree
-
visitSwitch
- Specified by:
visitSwitch
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitSwitch
in classTreeScanner<Void,
Void>
-
visitSwitchExpression17
Description copied from class:BaseTypeVisitor
This method validates the type of the switch expression. It issues an error if the type of a value that the switch expression can result is not a subtype of the switch type.If a subclass overrides this method, it must call
super.scan(switchExpressionTree, null)
so that the blocks and statements in the cases are checked.- Overrides:
visitSwitchExpression17
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
switchExprTree
- aSwitchExpressionTree
-
visitForLoop
- Specified by:
visitForLoop
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitForLoop
in classTreeScanner<Void,
Void>
-
visitNewClass
Description copied from class:BaseTypeVisitor
Performs a new class invocation check.An invocation of a constructor, c, is valid only if:
- passed arguments are subtypes of corresponding c parameters
- if c is generic, passed type arguments are subtypes of c type variables
- Specified by:
visitNewClass
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitNewClass
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitWhileLoop
- Specified by:
visitWhileLoop
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitWhileLoop
in classTreeScanner<Void,
Void>
-
visitDoWhileLoop
- Specified by:
visitDoWhileLoop
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitDoWhileLoop
in classTreeScanner<Void,
Void>
-
visitConditionalExpression
Description copied from class:BaseTypeVisitor
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. However, let's add another failsafe guard and do the checks.- Specified by:
visitConditionalExpression
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitConditionalExpression
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkExceptionParameter
Description copied from class:BaseTypeVisitor
Issue error if the exception parameter is not a supertype of the annotation specified byBaseTypeVisitor.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()
.- Overrides:
checkExceptionParameter
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
tree
- a CatchTree to check
-
visitAnnotation
Description copied from class:BaseTypeVisitor
Ensure that the annotation arguments comply to their declarations. This needs some special casing, as annotation arguments form special trees.- Specified by:
visitAnnotation
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitAnnotation
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitAnnotatedType
Description copied from class:BaseTypeVisitor
Checks an annotated type. Invoked byBaseTypeVisitor.visitAnnotatedType(AnnotatedTypeTree, Void)
,BaseTypeVisitor.visitVariable(com.sun.source.tree.VariableTree, java.lang.Void)
, andBaseTypeVisitor.visitMethod(com.sun.source.tree.MethodTree, java.lang.Void)
. Exists to prevent code duplication among the three. Checking invisitVariable
andvisitMethod
is needed because there isn't an AnnotatedTypeTree within a variable declaration or for a method return type -- all the annotations are attached to the VariableTree or MethodTree, respectively.- Overrides:
visitAnnotatedType
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
- Parameters:
annoTrees
- annotations written before a variable/method declaration, if this type is from one; null otherwise. This might contain type annotations that the Java parser attached to the declaration rather than to the type.typeTree
- the type that any type annotations in annoTrees apply to
-
createTypeValidator
- Overrides:
createTypeValidator
in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-