public class InitializationVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>,Value extends CFAbstractValue<Value>,Store extends InitializationStore<Value,Store>> extends BaseTypeVisitor<Factory>
NullnessChecker
. Also supports
rawness as a type-system for tracking initialization, though FBC is
preferred.Modifier and Type | Field and Description |
---|---|
protected AnnotationFormatter |
annoFormatter |
protected List<VariableTree> |
initializedFields |
atypeFactory, checker, contractsUtils, positions, typeValidator, visitorState
elements, root, trees, types
Constructor and Description |
---|
InitializationVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt,
AnnotatedTypeMirror.AnnotatedExecutableType constructor,
Tree src) |
protected boolean |
checkContract(FlowExpressions.Receiver 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 blockNode,
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 |
commonAssignmentCheck(Tree varTree,
ExpressionTree valueExp,
@CompilerMessageKey String errorKey)
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.
|
Set<AnnotationMirror> |
getExplicitReturnTypeAnnotations(MethodTree node) |
void |
setRoot(CompilationUnitTree root) |
Void |
visitBlock(BlockTree node,
Void p) |
Void |
visitClass(ClassTree node,
Void p) |
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, checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostconditions, checkConditionalPostconditionsConsistency, checkDefaultConstructor, checkExceptionParameter, checkFlowExprParameters, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostconditions, checkPostconditionsConsistency, checkPreconditions, checkPreconditions, checkPreconditionsConsistency, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, commonAssignmentCheck, commonAssignmentCheck, createTypeFactory, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isValidUse, isValidUse, isVectorCopyInto, reportPurityErrors, scan, shouldSkipUses, skipContractCheck, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotation, visitArrayAccess, visitAssignment, visitCatch, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitThrow, visitTypeParameter, visitUnary
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitWhileLoop, visitWildcard
protected final AnnotationFormatter annoFormatter
protected final List<VariableTree> initializedFields
public InitializationVisitor(BaseTypeChecker checker)
public void setRoot(CompilationUnitTree root)
setRoot
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected boolean checkConstructorInvocation(AnnotatedTypeMirror.AnnotatedDeclaredType dt, AnnotatedTypeMirror.AnnotatedExecutableType constructor, Tree src)
checkConstructorInvocation
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
varTree
- the AST node for the variablevalueExp
- the AST node for the valueerrorKey
- the error message to use if the check fails (must be a
compiler message key, see CompilerMessageKey
)public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected boolean checkContract(FlowExpressions.Receiver 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 visitBlock(BlockTree node, Void p)
visitBlock
in interface TreeVisitor<Void,Void>
visitBlock
in class TreeScanner<Void,Void>
public Void visitClass(ClassTree node, Void p)
visitClass
in interface TreeVisitor<Void,Void>
visitClass
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
public Void visitMethod(MethodTree node, Void p)
BaseTypeVisitor
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class BaseTypeVisitor<Factory extends InitializationAnnotatedTypeFactory<Value,Store,?,?>>
protected void checkFieldsInitialized(Tree blockNode, boolean staticFields, Store store, List<? extends AnnotationMirror> receiverAnnotations)
staticFields
is
true) are initialized in the given store.public Set<AnnotationMirror> getExplicitReturnTypeAnnotations(MethodTree node)