Class InitializationVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>,Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>>
java.lang.Object
com.sun.source.util.TreeScanner<R,P>
com.sun.source.util.TreePathScanner<R,P>
org.checkerframework.framework.source.SourceVisitor<Void,Void>
org.checkerframework.common.basetype.BaseTypeVisitor<Factory>
org.checkerframework.checker.initialization.InitializationVisitor<Factory,Value,Store>
- All Implemented Interfaces:
TreeVisitor<Void,
Void>
- Direct Known Subclasses:
NullnessVisitor
public class InitializationVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>,Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>>
extends BaseTypeVisitor<Factory>
The visitor for the freedom-before-commitment type-system. The freedom-before-commitment
type-system and this class are abstract and need to be combined with another type-system whose
safe initialization should be tracked. For an example, see the
NullnessChecker
.-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.OverrideChecker
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AnnotationFormatter
The annotation formatter.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, IMPURE, methodTree, positions, PURE, 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
ConstructorDescriptionInitializationVisitor
(BaseTypeChecker checker) Creates a new InitializationVisitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkConstructorInvocation
(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 void
checkConstructorResult
(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.protected boolean
checkContract
(JavaExpression expr, AnnotationMirror necessaryAnnotation, AnnotationMirror inferredAnnotation, CFAbstractStore<?, ?> store) Returns true if and only ifinferredAnnotation
is valid for a given expression to match thenecessaryAnnotation
.protected void
checkFieldsInitialized
(Tree tree, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFields
is true) are initialized in the given store.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 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.void
processClassTree
(ClassTree tree) Type-check classTree.void
setRoot
(CompilationUnitTree root) Set the CompilationUnitTree to be used during any visits.visitMethod
(MethodTree tree, Void p) Checks that the method or constructor obeys override and subtype rules to all overridden methods.visitVariable
(VariableTree tree, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurityAnnotations, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, reportMethodInvocabilityError, reportPurityErrors, scan, shouldPerformContractInference, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes, warnInvalidPolymorphicQualifier, warnInvalidPolymorphicQualifier, 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, visitArrayAccess, visitArrayType, visitAssert, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitContinue, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitGuardedPattern, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitParenthesizedPattern, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSwitchExpression, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
-
Field Details
-
annoFormatter
The annotation formatter. -
initializedFields
List of fields in the current compilation unit that have been initialized.
-
-
Constructor Details
-
InitializationVisitor
Creates a new InitializationVisitor.- Parameters:
checker
- the associated type-checker
-
-
Method Details
-
setRoot
Description copied from class:SourceVisitor
Set 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:
setRoot
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>>
-
checkConstructorInvocation
protected void checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, NewClassTree src) Description copied from class:BaseTypeVisitor
Check 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.
- Overrides:
checkConstructorInvocation
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>>
-
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 conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.- Overrides:
checkConstructorResult
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>> - 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<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>> - 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<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>> - 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
-
visitVariable
- Specified by:
visitVariable
in interfaceTreeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>, Value extends CFAbstractValue<Value>> - Overrides:
visitVariable
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>>
-
checkContract
protected boolean checkContract(JavaExpression expr, AnnotationMirror necessaryAnnotation, AnnotationMirror inferredAnnotation, CFAbstractStore<?, ?> store) Description copied from class:BaseTypeVisitor
Returns true if and only ifinferredAnnotation
is valid for a given expression to match thenecessaryAnnotation
.By default,
inferredAnnotation
must be a subtype ofnecessaryAnnotation
, but subclasses might override this behavior.- Overrides:
checkContract
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>>
-
processClassTree
Description copied from class:BaseTypeVisitor
Type-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void)
.- Overrides:
processClassTree
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>> - Parameters:
tree
- class to check
-
visitMethod
Description copied from class:BaseTypeVisitor
Checks that the method or constructor 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<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>, Value extends CFAbstractValue<Value>> - Overrides:
visitMethod
in classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,
Store, ?, ?>>
-
checkFieldsInitialized
protected void checkFieldsInitialized(Tree tree, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFields
is true) are initialized in the given store.- Parameters:
tree
- aClassTree
ifstaticFields
is true; aMethodTree
for a constructor ifstaticFields
is false. This is where errors are reported, if they are not reported at the fields themselvesstaticFields
- whether to check static fields or instance fieldsstore
- the storereceiverAnnotations
- the annotations on the receiver
-