public class InitializationVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>,Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>> extends BaseTypeVisitor<Factory>
NullnessChecker
.BaseTypeVisitor.OverrideChecker
Modifier and Type | Field and Description |
---|---|
protected AnnotationFormatter |
annoFormatter
The annotation formatter.
|
protected List<VariableTree> |
initializedFields |
atypeFactory, checker, positions, TARGET, targetValueElement, typeValidator, unusedWhenElement, visitorState
elements, root, trees, treesWithSuppressWarnings, types
Constructor and Description |
---|
InitializationVisitor(BaseTypeChecker checker)
Creates a new InitializationVisitor.
|
Modifier and Type | Method and Description |
---|---|
protected 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 is not top.
|
protected boolean |
checkContract(JavaExpression expr,
AnnotationMirror necessaryAnnotation,
AnnotationMirror inferredAnnotation,
CFAbstractStore<?,?> store)
Returns true if and only if
inferredAnnotation is valid for a given expression to match
the necessaryAnnotation . |
protected void |
checkFieldsInitialized(Tree node,
boolean staticFields,
Store store,
List<? extends AnnotationMirror> receiverAnnotations)
Checks that all fields (all static fields if
staticFields 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 void |
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 node)
Type-check classTree.
|
void |
setRoot(CompilationUnitTree root)
Set the CompilationUnitTree to be used during any visits.
|
Void |
visitMethod(MethodTree node,
Void p)
Performs pseudo-assignment check: checks that the method obeys override and subtype rules to
all overridden methods.
|
Void |
visitTypeCast(TypeCastTree node,
Void p) |
Void |
visitVariable(VariableTree node,
Void p) |
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, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitNewArray, visitNewClass, visitReturn, visitThrow, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes
visit
getCurrentPath, scan
reduce, scan, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard
protected final AnnotationFormatter annoFormatter
protected final List<VariableTree> initializedFields
public InitializationVisitor(BaseTypeChecker checker)
checker
- the associated type-checkerpublic void setRoot(CompilationUnitTree root)
SourceVisitor
com.sun.source.util.TreePathScanner.scan(TreePath, P)
, the CompilationUnitTree of the TreePath
has to be equal to root
.setRoot
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected void checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, NewClassTree src)
BaseTypeVisitor
Issue a warning if the annotations on the constructor invocation is a subtype of the constructor result type. This is equivalent to down-casting.
checkConstructorInvocation
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement)
BaseTypeVisitor
BaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree)
.checkConstructorResult
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
constructorType
- AnnotatedExecutableType for the constructorconstructorElement
- element that declares the constructorprotected void checkThisOrSuperConstructorCall(MethodInvocationTree superCall, @CompilerMessageKey String errorKey)
BaseTypeVisitor
checkThisOrSuperConstructorCall
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
superCall
- the AST node for the constructor callerrorKey
- the error message key to use if the check failsprotected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
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" typespublic Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected boolean checkContract(JavaExpression expr, AnnotationMirror necessaryAnnotation, AnnotationMirror inferredAnnotation, CFAbstractStore<?,?> store)
BaseTypeVisitor
inferredAnnotation
is valid for a given expression to match
the necessaryAnnotation
.
By default, inferredAnnotation
must be a subtype of necessaryAnnotation
, but
subclasses might override this behavior.
checkContract
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
public void processClassTree(ClassTree node)
BaseTypeVisitor
BaseTypeVisitor.visitClass(ClassTree, Void)
.processClassTree
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
node
- class to checkpublic Void visitMethod(MethodTree node, Void p)
BaseTypeVisitor
The override rule specifies that a method, m1, may override a method m2 only if:
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected void checkFieldsInitialized(Tree node, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations)
staticFields
is true) are initialized in
the given store.node
- a ClassTree
if staticFields
is true; a MethodTree
for a
constructor if staticFields
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