Class InitializationVisitor
- All Implemented Interfaces:
TreeVisitor<Void,Void>
NullnessChecker.-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.FoundRequired, BaseTypeVisitor.OverrideChecker -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanThe value of the assumeInitialized option.protected TreeThe assignment/variable/method invocation tree currently being checked.protected final List<VariableTree> List of fields in the current compilation unit that have been initialized.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, unusedWhenElementFields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types -
Constructor Summary
ConstructorsConstructorDescriptionInitializationVisitor(BaseTypeChecker checker) Create an InitializationVisitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, NewClassTree src) Check that the (explicit) annotations on a new class tree are comparable to the result type of the constructor.protected 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 voidcheckFieldsInitialized(Tree tree, boolean staticFields, InitializationStore initExitStore, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFieldsis true) are initialized at the end of a given constructor or static class initializer.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 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 InitializationAnnotatedTypeFactoryConstructs an instance of the appropriate type factory for the implemented type system.voidprocessClassTree(ClassTree tree) Type-check classTree.voidsetRoot(CompilationUnitTree root) Set the CompilationUnitTree to be used during any visits.voidEntry point for a type processor: the TreePath leaf is a top-level type tree within root.visitAssignment(AssignmentTree node, Void p) Performs two checks: subtyping and assignability checks, usingBaseTypeVisitor.commonAssignmentCheck(Tree, ExpressionTree, String, Object[]).visitMethod(MethodTree tree, Void p) Checks that the method obeys override and subtype rules to all overridden methods.Performs a method invocation check.visitVariable(VariableTree tree, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkContract, checkDefaultConstructor, checkEnclosingExpr, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createQualAllowedLocations, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, reportCommonAssignmentError, reportMethodInvocabilityError, reportPurityErrors, scan, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTargetLocation, validateType, validateTypeOf, validateVariablesTargetLocation, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes, warnRedundantAnnotationsMethods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scanMethods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnyPattern, visitArrayAccess, visitArrayType, visitAssert, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitStringTemplate, visitSwitch, visitSwitchExpression, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
-
Field Details
-
initializedFields
List of fields in the current compilation unit that have been initialized. -
assumeInitialized
protected final boolean assumeInitializedThe value of the assumeInitialized option. -
commonAssignmentTree
The assignment/variable/method invocation tree currently being checked.In the case that the right-hand side is an object, this is used by
BaseTypeVisitor.reportCommonAssignmentError(AnnotatedTypeMirror, AnnotatedTypeMirror, Tree, String, Object...)to get the correct store value for the right-hand side's fields and checker whether they are initialized according to the target checker.
-
-
Constructor Details
-
InitializationVisitor
Create an InitializationVisitor.- Parameters:
checker- the initialization checker
-
-
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<InitializationAnnotatedTypeFactory>- Returns:
- the appropriate type factory
-
visit
Description copied from class:SourceVisitorEntry point for a type processor: the TreePath leaf is a top-level type tree within root.- Overrides:
visitin classSourceVisitor<Void,Void>
-
setRoot
Description copied from class:SourceVisitorSet the CompilationUnitTree to be used during any visits. For any later calls ofcom.sun.source.util.TreePathScanner.scan(TreePath, P), the CompilationUnitTree of the TreePath has to be equal toroot.- Overrides:
setRootin classBaseTypeVisitor<InitializationAnnotatedTypeFactory>
-
checkConstructorInvocation
protected void checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, NewClassTree src) Description copied from class:BaseTypeVisitorCheck that the (explicit) annotations on a new class tree are comparable to the result type of the constructor. Issue an error if not.Issue a warning if the annotations on the constructor invocation is a subtype of the constructor result type. This is equivalent to down-casting.
For type checking of the enclosing expression of inner type instantiations, see
BaseTypeVisitor.checkEnclosingExpr(NewClassTree, AnnotatedExecutableType)- Overrides:
checkConstructorInvocationin classBaseTypeVisitor<InitializationAnnotatedTypeFactory>- Parameters:
dt- the AnnotatedDeclaredType of the constructor invocationconstructor- the AnnotatedExecutableType of the constructor declarationsrc- the NewClassTree
-
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<InitializationAnnotatedTypeFactory>- 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<InitializationAnnotatedTypeFactory>- 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<InitializationAnnotatedTypeFactory>- 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
-
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<InitializationAnnotatedTypeFactory>- Parameters:
node- a CatchTree to check
-
processClassTree
Description copied from class:BaseTypeVisitorType-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void).- Overrides:
processClassTreein classBaseTypeVisitor<InitializationAnnotatedTypeFactory>- Parameters:
tree- class to check
-
visitMethod
Description copied from class:BaseTypeVisitorChecks 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:
visitMethodin interfaceTreeVisitor<Void,Void> - Overrides:
visitMethodin classBaseTypeVisitor<InitializationAnnotatedTypeFactory>
-
visitVariable
- Specified by:
visitVariablein interfaceTreeVisitor<Void,Void> - Overrides:
visitVariablein classBaseTypeVisitor<InitializationAnnotatedTypeFactory>
-
visitAssignment
Description copied from class:BaseTypeVisitorPerforms two checks: subtyping and assignability checks, usingBaseTypeVisitor.commonAssignmentCheck(Tree, ExpressionTree, String, Object[]).If the subtype check fails, it issues an "assignment.type.incompatible" error.
- Specified by:
visitAssignmentin interfaceTreeVisitor<Void,Void> - Overrides:
visitAssignmentin classBaseTypeVisitor<InitializationAnnotatedTypeFactory>
-
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<InitializationAnnotatedTypeFactory>
-
checkFieldsInitialized
protected void checkFieldsInitialized(Tree tree, boolean staticFields, InitializationStore initExitStore, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFieldsis true) are initialized at the end of a given constructor or static class initializer.- Parameters:
tree- aClassTreeifstaticFieldsis true; aMethodTreefor a constructor ifstaticFieldsis false. This is where errors are reported, if they are not reported at the fields themselvesstaticFields- whether to check static fields or instance fieldsinitExitStore- the initialization exit store for the constructor or static initializerreceiverAnnotations- the annotations on the receiver
-