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, warnRedundantAnnotationsFields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types -
Constructor Summary
ConstructorsConstructorDescriptionNullnessNoInitVisitor(BaseTypeChecker checker) Create a new NullnessVisitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.protected voidIssue error if the exception parameter is not a supertype of the annotation specified byBaseTypeVisitor.getExceptionParameterLowerBoundAnnotations(), which is top by default.protected voidReports an error if a comparison of a @NonNull expression with the null literal is performed.protected voidcheckMethodInvocability(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 voidcheckThisOrSuperConstructorCall(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 voidCase 4: Check for thrown exception nullness.protected booleancommonAssignmentCheck(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 booleancommonAssignmentCheck(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 booleancommonAssignmentCheck(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 TypeValidatorbooleanisValidUse(AnnotatedTypeMirror.AnnotatedPrimitiveType type, Tree tree) Tests that the qualifiers present on the primitive type are valid.voidprocessClassTree(ClassTree classTree) Type-check classTree.voidprocessMethodTree(String className, MethodTree tree) Type-check methodTree.voidvisitAnnotatedType(@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.visitDoWhileLoop(DoWhileLoopTree tree, Void p) visitEnhancedForLoop(EnhancedForLoopTree tree, Void p) Case 2: Check for implicit.iteratorcall.visitForLoop(ForLoopTree tree, Void p) visitInstanceOf(InstanceOfTree tree, Void p) visitMemberSelect(MemberSelectTree tree, Void p) Case 1: Check for null dereferencing.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) voidvisitSwitchExpression17(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, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurityAnnotations, 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, visitMethod, visitReturn, visitThrow, visitTypeParameter, visitVariable, warnAboutIrrelevantJavaTypes, warnInvalidPolymorphicQualifier, warnInvalidPolymorphicQualifier, warnRedundantAnnotationsMethods inherited from class org.checkerframework.framework.source.SourceVisitor
visitMethods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scanMethods 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:BaseTypeVisitorConstructs 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:
createTypeFactoryin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Returns:
- the appropriate type factory
-
isValidUse
Description copied from class:BaseTypeVisitorTests that the qualifiers present on the primitive type are valid.- Overrides:
isValidUsein 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:BaseTypeVisitorIssue 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:
checkConstructorResultin 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:BaseTypeVisitorChecks 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:
checkThisOrSuperConstructorCallin 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:BaseTypeVisitorChecks 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:
commonAssignmentCheckin 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:BaseTypeVisitorChecks 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:
commonAssignmentCheckin 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:BaseTypeVisitorChecks 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:
commonAssignmentCheckin 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:
visitMemberSelectin interfaceTreeVisitor<Void,Void> - Overrides:
visitMemberSelectin classTreeScanner<Void,Void>
-
visitEnhancedForLoop
Case 2: Check for implicit.iteratorcall.- Specified by:
visitEnhancedForLoopin interfaceTreeVisitor<Void,Void> - Overrides:
visitEnhancedForLoopin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitArrayAccess
Case 3: Check for array dereferencing.- Specified by:
visitArrayAccessin interfaceTreeVisitor<Void,Void> - Overrides:
visitArrayAccessin classTreeScanner<Void,Void>
-
visitNewArray
- Specified by:
visitNewArrayin interfaceTreeVisitor<Void,Void> - Overrides:
visitNewArrayin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkThrownExpression
Case 4: Check for thrown exception nullness.- Overrides:
checkThrownExpressionin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
tree- a ThrowTree to check
-
visitSynchronized
Case 5: Check for synchronizing locks.- Specified by:
visitSynchronizedin interfaceTreeVisitor<Void,Void> - Overrides:
visitSynchronizedin classTreeScanner<Void,Void>
-
visitAssert
- Specified by:
visitAssertin interfaceTreeVisitor<Void,Void> - Overrides:
visitAssertin classTreeScanner<Void,Void>
-
visitIf
- Specified by:
visitIfin interfaceTreeVisitor<Void,Void> - Overrides:
visitIfin classTreeScanner<Void,Void>
-
visitInstanceOf
- Specified by:
visitInstanceOfin interfaceTreeVisitor<Void,Void> - Overrides:
visitInstanceOfin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkForRedundantTests
Reports an error if a comparison of a @NonNull expression with the null literal is performed. Does nothing unless-Alint=redundantNullComparisonis 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:
visitBinaryin interfaceTreeVisitor<Void,Void> - Overrides:
visitBinaryin classTreeScanner<Void,Void>
-
visitUnary
Case 7: unboxing case: primitive operation.- Specified by:
visitUnaryin interfaceTreeVisitor<Void,Void> - Overrides:
visitUnaryin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitCompoundAssignment
Case 7: unboxing case: primitive operation.- Specified by:
visitCompoundAssignmentin interfaceTreeVisitor<Void,Void> - Overrides:
visitCompoundAssignmentin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitTypeCast
Case 7: unboxing case: casting to a primitive.- Specified by:
visitTypeCastin interfaceTreeVisitor<Void,Void> - Overrides:
visitTypeCastin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
processMethodTree
Description copied from class:BaseTypeVisitorType-check methodTree. Subclasses should override this method instead ofBaseTypeVisitor.visitMethod(MethodTree, Void).- Overrides:
processMethodTreein classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
className- the class that contains the method, for diagnostics onlytree- the method to type-check
-
visitMethodInvocation
Description copied from class:BaseTypeVisitorPerforms 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:
visitMethodInvocationin interfaceTreeVisitor<Void,Void> - Overrides:
visitMethodInvocationin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
processClassTree
Description copied from class:BaseTypeVisitorType-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void).- Overrides:
processClassTreein classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
classTree- class to check
-
checkMethodInvocability
protected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree tree) Description copied from class:BaseTypeVisitorTests 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:
checkMethodInvocabilityin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
method- the type of the invoked methodtree- the method invocation tree
-
visitSwitch
- Specified by:
visitSwitchin interfaceTreeVisitor<Void,Void> - Overrides:
visitSwitchin classTreeScanner<Void,Void>
-
visitSwitchExpression17
Description copied from class:BaseTypeVisitorThis 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:
visitSwitchExpression17in classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
switchExprTree- aSwitchExpressionTree
-
visitForLoop
- Specified by:
visitForLoopin interfaceTreeVisitor<Void,Void> - Overrides:
visitForLoopin classTreeScanner<Void,Void>
-
visitNewClass
Description copied from class:BaseTypeVisitorPerforms 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:
visitNewClassin interfaceTreeVisitor<Void,Void> - Overrides:
visitNewClassin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitWhileLoop
- Specified by:
visitWhileLoopin interfaceTreeVisitor<Void,Void> - Overrides:
visitWhileLoopin classTreeScanner<Void,Void>
-
visitDoWhileLoop
- Specified by:
visitDoWhileLoopin interfaceTreeVisitor<Void,Void> - Overrides:
visitDoWhileLoopin classTreeScanner<Void,Void>
-
visitConditionalExpression
- Specified by:
visitConditionalExpressionin interfaceTreeVisitor<Void,Void> - Overrides:
visitConditionalExpressionin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
checkExceptionParameter
Description copied from class:BaseTypeVisitorIssue 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:
checkExceptionParameterin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>- Parameters:
tree- a CatchTree to check
-
visitAnnotation
Description copied from class:BaseTypeVisitorEnsure that the annotation arguments comply to their declarations. This needs some special casing, as annotation arguments form special trees.- Specified by:
visitAnnotationin interfaceTreeVisitor<Void,Void> - Overrides:
visitAnnotationin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-
visitAnnotatedType
Description copied from class:BaseTypeVisitorChecks 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 invisitVariableandvisitMethodis 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:
visitAnnotatedTypein 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:
createTypeValidatorin classBaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
-