Class ValueVisitor
- All Implemented Interfaces:
TreeVisitor<Void,
Void>
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
BaseTypeVisitor.OverrideChecker
-
Field Summary
Fields inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
assumePureGetters, atypeFactory, checker, DETERMINISTIC, IMPURE, methodTree, positions, PURE, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement
Fields inherited from class org.checkerframework.framework.source.SourceVisitor
elements, root, trees, treesWithSuppressWarnings, types
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 boolean
commonAssignmentCheck
(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) ValueVisitor overrides this method so that it does not have to check variables annotated with theIntRangeFromPositive
annotation, theIntRangeFromNonNegative
annotation, or theIntRangeFromGTENegativeOne
annotation.protected boolean
commonAssignmentCheck
(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @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.protected ValueAnnotatedTypeFactory
Constructs an instance of the appropriate type factory for the implemented type system.protected boolean
isTypeCastSafe
(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) Returns true if the cast is safe.boolean
validateType
(Tree tree, AnnotatedTypeMirror type) Overridden to issue errors at the appropriate place if anIntRange
orArrayLenRange
annotation hasfrom > to
.visitAnnotation
(AnnotationTree tree, Void p) Warns about malformed constant-value annotations.visitMethod
(MethodTree tree, Void p) Checks that the method or constructor obeys override and subtype rules to all overridden methods.visitTypeCast
(TypeCastTree tree, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitor
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkConstructorResult, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurityAnnotations, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isValidUse, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldPerformContractInference, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethodInvocation, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes, warnInvalidPolymorphicQualifier, warnInvalidPolymorphicQualifier, warnRedundantAnnotations
Methods inherited from class org.checkerframework.framework.source.SourceVisitor
visit
Methods inherited from class com.sun.source.util.TreePathScanner
getCurrentPath, scan
Methods 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
-
Constructor Details
-
ValueVisitor
-
-
Method Details
-
commonAssignmentCheck
protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) ValueVisitor overrides this method so that it does not have to check variables annotated with theIntRangeFromPositive
annotation, theIntRangeFromNonNegative
annotation, or theIntRangeFromGTENegativeOne
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-writtenorg.checkerframework.checker.index.qual.Positive
, explicitly-writtenorg.checkerframework.checker.index.qual.NonNegative
, and explicitly-writtenorg.checkerframework.checker.index.qual.GTENegativeOne
annotations, which must be checked by the Lower Bound Checker.- Overrides:
commonAssignmentCheck
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Parameters:
varType
- the annotated type of 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- Returns:
- true if the check succeeds, false if an error message was issued
-
commonAssignmentCheck
@FormatMethod protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitor
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.- Overrides:
commonAssignmentCheck
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Parameters:
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 key to use if the check failsextraArgs
- arguments to the error message key, before "found" and "expected" types- Returns:
- true if the check succeeds, false if an error message was issued
-
checkOverride
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
. See the documentation oncommonAssignmentCheck
.A separate override is necessary because checkOverride doesn't actually use the commonAssignmentCheck.
- Overrides:
checkOverride
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Parameters:
overriderTree
- declaration tree of overriding methodoverrider
- type of the overriding methodoverridingType
- type of overriding classoverridden
- type of overridden methodoverriddenType
- type of overridden class- Returns:
- true if the override is allowed
- See Also:
-
createTypeFactory
Description copied from class:BaseTypeVisitor
Constructs an instance of the appropriate type factory for the implemented type system.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.
- Overrides:
createTypeFactory
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Returns:
- the appropriate type factory
-
visitAnnotation
Warns about malformed constant-value annotations.Issues an error if any @IntRange annotation has its 'from' value greater than 'to' value.
Issues an error if any constant-value annotation has no arguments.
Issues a warning if any constant-value annotation has > MAX_VALUES arguments.
Issues a warning if any @ArrayLen/@ArrayLenRange annotations contain a negative array length.
Issues a warning if any @MatchesRegex or @DoesNotMatchRegex annotation contains an invalid regular expression.
- Specified by:
visitAnnotation
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitAnnotation
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
-
visitTypeCast
- Specified by:
visitTypeCast
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitTypeCast
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
-
isTypeCastSafe
Description copied from class:BaseTypeVisitor
Returns true if the cast is safe.Only primary qualifiers are checked unless the command line option "checkCastElementType" is supplied.
- Overrides:
isTypeCastSafe
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Parameters:
castType
- annotated type of the castexprType
- annotated type of the casted expression- Returns:
- true if the type cast is safe, false otherwise
-
validateType
Overridden to issue errors at the appropriate place if anIntRange
orArrayLenRange
annotation hasfrom > to
.from > to
either indicates a user error when writing an annotation or an error in the checker's implementation, asfrom
should always be<= to
. Note that additional checks are performed invisitAnnotation(AnnotationTree, Void)
.- Overrides:
validateType
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
- Parameters:
tree
- the type tree supplied by the usertype
- the type corresponding to tree- Returns:
- true if the type is valid
- See Also:
-
visitMethod
Description copied from class:BaseTypeVisitor
Checks that the method or constructor 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:
visitMethod
in interfaceTreeVisitor<Void,
Void> - Overrides:
visitMethod
in classBaseTypeVisitor<ValueAnnotatedTypeFactory>
-