public class ValueVisitor extends BaseTypeVisitor<ValueAnnotatedTypeFactory>
BaseTypeVisitor.OverrideChecker
atypeFactory, checker, contractsUtils, positions, TARGET, targetValueElement, typeValidator, visitorState
elements, root, trees, treesWithSuppressWarnings, types
Constructor and Description |
---|
ValueVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkOverride(MethodTree overriderTree,
AnnotatedTypeMirror.AnnotatedExecutableType overrider,
AnnotatedTypeMirror.AnnotatedDeclaredType overridingType,
AnnotatedTypeMirror.AnnotatedExecutableType overridden,
AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType)
Return types for methods that are annotated with
@IntRangeFromX annotations need to
be replaced with @UnknownVal . |
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@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.
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
ExpressionTree valueExp,
@CompilerMessageKey String errorKey)
ValueVisitor overrides this method so that it does not have to check variables annotated with
the
IntRangeFromPositive annotation, the IntRangeFromNonNegative annotation,
or the IntRangeFromGTENegativeOne annotation. |
protected ValueAnnotatedTypeFactory |
createTypeFactory()
Constructs an instance of the appropriate type factory for the implemented type system.
|
boolean |
validateType(Tree tree,
AnnotatedTypeMirror type)
Overridden to issue errors at the appropriate place if an
IntRange or ArrayLenRange annotation has from > to . |
Void |
visitAnnotation(AnnotationTree node,
Void p)
Warns about malformed constant-value annotations.
|
Void |
visitTypeCast(TypeCastTree node,
Void p) |
checkAccess, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkConstructorResult, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExtendsImplements, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isTypeCastSafe, isValidUse, isValidUse, isValidUse, processClassTree, reportPurityErrors, scan, setRoot, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTypeOf, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitReturn, visitThrow, visitTypeParameter, visitUnary, visitVariable
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitTry, visitUnionType, visitWhileLoop, visitWildcard
public ValueVisitor(BaseTypeChecker checker)
protected void commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey)
IntRangeFromPositive
annotation, the IntRangeFromNonNegative
annotation,
or the IntRangeFromGTENegativeOne
annotation. This annotation is only introduced by
the Index Checker's lower bound annotations. It is safe to defer checking of these values to
the Index Checker because this is only introduced for explicitly-written org.checkerframework.checker.index.qual.Positive
, explicitly-written org.checkerframework.checker.index.qual.NonNegative
, and explicitly-written org.checkerframework.checker.index.qual.GTENegativeOne
annotations, which must be checked by
the Lower Bound Checker.commonAssignmentCheck
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
varType
- the annotated type of the lvalue (usually a variable)valueExp
- the AST node for the rvalue (the new value)errorKey
- the error message to use if the check fails (must be a compiler message key,protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
varType
- the annotated type of the variablevalueType
- the annotated type of the valuevalueTree
- the location to use when reporting the error messageerrorKey
- the error message to use if the check fails (must be a compiler message key,
see CompilerMessageKey
)protected boolean checkOverride(MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror.AnnotatedDeclaredType overridingType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType)
@IntRangeFromX
annotations need to
be replaced with @UnknownVal
. See the documentation on commonAssignmentCheck
.
A separate override is necessary because checkOverride doesn't actually use the commonAssignmentCheck.
checkOverride
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
overriderTree
- declaration tree of overriding methodoverrider
- type of the overriding methodoverridingType
- type of overriding classoverridden
- type of overridden methodoverriddenType
- type of overridden classBaseTypeVisitor.checkOverride(MethodTree, AnnotatedTypeMirror.AnnotatedDeclaredType,
AnnotatedTypeMirror.AnnotatedExecutableType, AnnotatedTypeMirror.AnnotatedDeclaredType)
protected ValueAnnotatedTypeFactory createTypeFactory()
BaseTypeVisitor
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.
createTypeFactory
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
public Void visitAnnotation(AnnotationTree node, Void p)
Issues an error if any @IntRange annotation has its 'from' value greater than 'to' value.
Issues a warning if any constant-value annotation has > MAX_VALUES arguments.
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
public Void visitTypeCast(TypeCastTree node, Void p)
visitTypeCast
in interface TreeVisitor<Void,Void>
visitTypeCast
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
public boolean validateType(Tree tree, AnnotatedTypeMirror type)
IntRange
or ArrayLenRange
annotation has from > to
. from > to
either indicates a user
error when writing an annotation or an error in the checker's implementation, as from
should always be <= to
.validateType
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
tree
- the type tree supplied by the usertype
- the type corresponding to tree