public class ValueVisitor extends BaseTypeVisitor<ValueAnnotatedTypeFactory>
Visitor for the Constant Value type-system
BaseTypeVisitor.OverrideChecker
atypeFactory, checker, contractsUtils, positions, typeValidator, visitorState
elements, root, trees, types
Constructor and Description |
---|
ValueVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkOverride(com.sun.source.tree.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,
com.sun.source.tree.Tree valueTree,
@CompilerMessageKey java.lang.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,
com.sun.source.tree.ExpressionTree valueExp,
@CompilerMessageKey java.lang.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.
|
java.lang.Void |
visitAnnotation(com.sun.source.tree.AnnotationTree node,
java.lang.Void p)
Warns about malformed constant-value annotations.
|
java.lang.Void |
visitTypeCast(com.sun.source.tree.TypeCastTree node,
java.lang.Void p) |
checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, createOverrideChecker, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isValidUse, isValidUse, isVectorCopyInto, processClassTree, reportPurityErrors, scan, setRoot, shouldSkipUses, skipReceiverSubtypeCheck, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitArrayAccess, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitThrow, visitTry, visitTypeParameter, visitUnary, visitVariable
visit
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBinary, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitMemberSelect, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitSynchronized, visitUnionType, visitWhileLoop, visitWildcard
public ValueVisitor(BaseTypeChecker checker)
protected void commonAssignmentCheck(AnnotatedTypeMirror varType, com.sun.source.tree.ExpressionTree valueExp, @CompilerMessageKey java.lang.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 Positive
, explicitly-written NonNegative
, and explicitly-written 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, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.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(com.sun.source.tree.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 java.lang.Void visitAnnotation(com.sun.source.tree.AnnotationTree node, java.lang.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 com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitAnnotation
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
public java.lang.Void visitTypeCast(com.sun.source.tree.TypeCastTree node, java.lang.Void p)
visitTypeCast
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitTypeCast
in class BaseTypeVisitor<ValueAnnotatedTypeFactory>