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>
- 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
FieldsModifier and TypeFieldDescriptionprotected final AnnotationFormatterThe annotation formatter.protected final List<com.sun.source.tree.VariableTree>Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
atypeFactory, checker, DETERMINISTIC, methodTree, positions, PURE, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElementFields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types -
Constructor Summary
ConstructorsConstructorDescriptionInitializationVisitor(BaseTypeChecker checker) Creates a new InitializationVisitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, com.sun.source.tree.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 is not top.protected booleancheckContract(JavaExpression expr, AnnotationMirror necessaryAnnotation, AnnotationMirror inferredAnnotation, CFAbstractStore<?, ?> store) Returns true if and only ifinferredAnnotationis valid for a given expression to match thenecessaryAnnotation.protected voidcheckFieldsInitialized(com.sun.source.tree.Tree node, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFieldsis true) are initialized in the given store.protected voidcheckThisOrSuperConstructorCall(com.sun.source.tree.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 voidcommonAssignmentCheck(com.sun.source.tree.Tree varTree, com.sun.source.tree.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.voidprocessClassTree(com.sun.source.tree.ClassTree node) Type-check classTree.voidsetRoot(com.sun.source.tree.CompilationUnitTree root) Set the CompilationUnitTree to be used during any visits.visitMethod(com.sun.source.tree.MethodTree node, Void p) Checks that the method obeys override and subtype rules to all overridden methods.visitTypeCast(com.sun.source.tree.TypeCastTree node, Void p) visitVariable(com.sun.source.tree.VariableTree node, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, isValidUse, reportMethodInvocabilityError, reportPurityErrors, scan, 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, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypesMethods 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, 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
-
-
Constructor Details
-
InitializationVisitor
Creates a new InitializationVisitor.- Parameters:
checker- the associated type-checker
-
-
Method Details
-
setRoot
public void setRoot(com.sun.source.tree.CompilationUnitTree root) 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<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
checkConstructorInvocation
protected void checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, com.sun.source.tree.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.
- Overrides:
checkConstructorInvocationin classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
checkConstructorResult
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Description copied from class:BaseTypeVisitorIssue a warning if the result type of the constructor 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:
checkConstructorResultin classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>> - Parameters:
constructorType- AnnotatedExecutableType for the constructorconstructorElement- element that declares the constructor
-
checkThisOrSuperConstructorCall
protected void checkThisOrSuperConstructorCall(com.sun.source.tree.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<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 void commonAssignmentCheck(com.sun.source.tree.Tree varTree, com.sun.source.tree.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<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
-
visitVariable
- Specified by:
visitVariablein interfacecom.sun.source.tree.TreeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>, Value extends CFAbstractValue<Value>> - Overrides:
visitVariablein classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
checkContract
protected boolean checkContract(JavaExpression expr, AnnotationMirror necessaryAnnotation, AnnotationMirror inferredAnnotation, CFAbstractStore<?, ?> store) Description copied from class:BaseTypeVisitorReturns true if and only ifinferredAnnotationis valid for a given expression to match thenecessaryAnnotation.By default,
inferredAnnotationmust be a subtype ofnecessaryAnnotation, but subclasses might override this behavior.- Overrides:
checkContractin classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
visitTypeCast
- Specified by:
visitTypeCastin interfacecom.sun.source.tree.TreeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>, Value extends CFAbstractValue<Value>> - Overrides:
visitTypeCastin classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
processClassTree
public void processClassTree(com.sun.source.tree.ClassTree node) Description copied from class:BaseTypeVisitorType-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void).- Overrides:
processClassTreein classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>> - Parameters:
node- 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 interfacecom.sun.source.tree.TreeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>, Value extends CFAbstractValue<Value>> - Overrides:
visitMethodin classBaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store, ?, ?>>
-
checkFieldsInitialized
protected void checkFieldsInitialized(com.sun.source.tree.Tree node, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations) Checks that all fields (all static fields ifstaticFieldsis true) are initialized in the given store.- Parameters:
node- 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 fieldsstore- the storereceiverAnnotations- the annotations on the receiver
-