public class MustCallVisitor extends BaseTypeVisitor<MustCallAnnotatedTypeFactory>
BaseTypeVisitor.OverrideChecker
atypeFactory, checker, DETERMINISTIC, inferPurity, methodTree, positions, PURE, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElement
elements, root, trees, treesWithSuppressWarnings, types
Constructor and Description |
---|
MustCallVisitor(BaseTypeChecker checker)
Creates a new MustCallVisitor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType,
ExecutableElement constructorElement)
This method typically issues a warning if the result type of the constructor is not top,
because in top-default type systems that indicates a potential problem.
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@CompilerMessageKey String errorKey,
Object... extraArgs)
Iff the LHS is a resource variable, then
#commonAssignmentCheckOnResourceVariable will
be true. |
protected void |
commonAssignmentCheck(Tree varTree,
ExpressionTree valueExp,
@CompilerMessageKey String errorKey,
Object... extraArgs)
Mark (using the
#commonAssignmentCheckOnResourceVariable field of this class) any
assignments where the LHS is a resource variable, so that close doesn't need to be considered. |
protected Set<? extends AnnotationMirror> |
getExceptionParameterLowerBoundAnnotations()
Change the default for exception parameter lower bounds to bottom (the default), to prevent
false positives.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType,
Tree tree)
Tests that the qualifiers present on
useType are valid qualifiers, given the qualifiers
on the declaration of the type, declarationType . |
protected boolean |
skipReceiverSubtypeCheck(MethodInvocationTree node,
AnnotatedTypeMirror methodDefinitionReceiver,
AnnotatedTypeMirror methodCallReceiver)
Indicates whether to skip subtype checks on the receiver when checking method invocability.
|
protected boolean |
validateType(Tree tree,
AnnotatedTypeMirror type)
Tests whether the type and corresponding type tree is a valid type, and emits an error if that
is not the case (e.g.
|
Void |
visitAnnotation(AnnotationTree node,
Void p)
Does not issue any warnings.
|
Void |
visitReturn(ReturnTree node,
Void p)
Checks that the type of the return expression is a subtype of the enclosing method required
return type.
|
checkAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactory, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes
visit
getCurrentPath, scan
reduce, scan, visitArrayAccess, 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
public MustCallVisitor(BaseTypeChecker checker)
checker
- the type-checker associated with this visitorpublic Void visitReturn(ReturnTree node, Void p)
BaseTypeVisitor
visitReturn
in interface TreeVisitor<Void,Void>
visitReturn
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
protected boolean validateType(Tree tree, AnnotatedTypeMirror type)
BaseTypeVisitor
validateType
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
tree
- the type tree supplied by the usertype
- the type corresponding to treepublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree)
BaseTypeVisitor
useType
are valid qualifiers, given the qualifiers
on the declaration of the type, declarationType
.
The check is shallow, as it does not descend into generic or array types (i.e. only
performing the validity check on the raw type or outermost array dimension). BaseTypeVisitor.validateTypeOf(Tree)
would call this for each type argument or array dimension
separately.
In most cases, useType
simply needs to be a subtype of declarationType
. If a
type system makes exceptions to this rule, its implementation should override this method.
This method is not called if BaseTypeValidator.shouldCheckTopLevelDeclaredOrPrimitiveType(AnnotatedTypeMirror, Tree)
returns false -- by default, it is not called on the top level for locals and expressions. To
enforce a type validity property everywhere, override methods such as BaseTypeValidator.visitDeclared(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType, com.sun.source.tree.Tree)
rather than this method.
isValidUse
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
declarationType
- the type of the class (TypeElement)useType
- the use of the class (instance type)tree
- the tree where the type is usedprotected boolean skipReceiverSubtypeCheck(MethodInvocationTree node, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver)
BaseTypeVisitor
skipReceiverSubtypeCheck
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
node
- the method invocation nodemethodDefinitionReceiver
- the ATM of the receiver of the method definitionmethodCallReceiver
- the ATM of the receiver of the method callprotected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs)
#commonAssignmentCheckOnResourceVariable
field of this class) any
assignments where the LHS is a resource variable, so that close doesn't need to be considered.
See commonAssignmentCheck(AnnotatedTypeMirror, AnnotatedTypeMirror, Tree, String,
Object...)
for the code that uses and removes the mark.commonAssignmentCheck
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
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" typesprotected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs)
#commonAssignmentCheckOnResourceVariable
will
be true. This method guarantees that #commonAssignmentCheckOnResourceVariable
will be
false when it returns.commonAssignmentCheck
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
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" typesprotected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement)
MustCall({})
(by default) or some other MustCall
type, not the top type.
Instead, this method checks that the result type of a constructor is a supertype of the declared type on the class, if one exists.
checkConstructorResult
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
constructorType
- AnnotatedExecutableType for the constructorconstructorElement
- element that declares the constructorprotected Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotations()
TODO: change checking of throws clauses to require that the thrown exception is @MustCall({}). This would probably eliminate most of the same false positives, without adding undue false positives.
getExceptionParameterLowerBoundAnnotations
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>
public Void visitAnnotation(AnnotationTree node, Void p)
This implementation prevents recursing into annotation arguments. Annotation arguments are literals, which don't have must-call obligations.
Annotation arguments are treated as return locations for the purposes of defaulting, rather than parameter locations. This causes them to default incorrectly when the annotation is defined in bytecode. See https://github.com/typetools/checker-framework/issues/3178 for an explanation of why this is necessary to avoid false positives.
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class BaseTypeVisitor<MustCallAnnotatedTypeFactory>