Class MustCallVisitor
- All Implemented Interfaces:
- TreeVisitor<Void,- Void> 
- 
Nested Class SummaryNested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitorBaseTypeVisitor.OverrideChecker
- 
Field SummaryFields inherited from class org.checkerframework.common.basetype.BaseTypeVisitoratypeFactory, checker, DETERMINISTIC, IMPURE, methodTree, positions, PURE, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElementFields inherited from class org.checkerframework.framework.source.SourceVisitorelements, root, trees, treesWithSuppressWarnings, types
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcheckConstructorResult(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 booleancommonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @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 booleancommonAssignmentCheck(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 AnnotationMirrorSetChange the default for exception parameter lower bounds to bottom (the default), to prevent false positives.protected booleanisTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) Returns true if the cast is safe.booleanisValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree) Tests that the qualifiers present onuseTypeare valid qualifiers, given the qualifiers on the declaration of the type,declarationType.protected booleanskipReceiverSubtypeCheck(MethodInvocationTree tree, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver) Indicates whether to skip subtype checks on the receiver when checking method invocability.protected booleanvalidateType(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.visitAnnotation(AnnotationTree tree, Void p) Does not issue any warnings.visitAssignment(AssignmentTree tree, Void p) Performs two checks: subtyping and assignability checks, usingBaseTypeVisitor.commonAssignmentCheck(Tree, ExpressionTree, String, Object[]).visitReturn(ReturnTree tree, Void p) Checks that the type of the return expression is a subtype of the enclosing method required return type.Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitorcheckAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, 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, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitEnhancedForLoop, visitIdentifier, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitMethodInvocation, visitNewArray, visitNewClass, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, visitVariable, warnAboutIrrelevantJavaTypes, warnRedundantAnnotationsMethods inherited from class org.checkerframework.framework.source.SourceVisitorvisitMethods inherited from class com.sun.source.util.TreePathScannergetCurrentPath, scanMethods inherited from class com.sun.source.util.TreeScannerreduce, 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- 
MustCallVisitorCreates a new MustCallVisitor.- Parameters:
- checker- the type-checker associated with this visitor
 
 
- 
- 
Method Details- 
visitReturnDescription copied from class:BaseTypeVisitorChecks that the type of the return expression is a subtype of the enclosing method required return type. If not, it issues a "return" error.- Specified by:
- visitReturnin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitReturnin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
 
- 
visitAssignmentDescription copied from class:BaseTypeVisitorPerforms two checks: subtyping and assignability checks, usingBaseTypeVisitor.commonAssignmentCheck(Tree, ExpressionTree, String, Object[]).If the subtype check fails, it issues an "assignment" error. - Specified by:
- visitAssignmentin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitAssignmentin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
 
- 
validateTypeDescription copied from class:BaseTypeVisitorTests whether the type and corresponding type tree is a valid type, and emits an error if that is not the case (e.g. '@Mutable String'). If the tree is a method or constructor, tests the return type.- Overrides:
- validateTypein class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- tree- the type tree supplied by the user
- type- the type corresponding to tree
- Returns:
- true if the type is valid
 
- 
isValidUsepublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree) Description copied from class:BaseTypeVisitorTests that the qualifiers present onuseTypeare 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, useTypesimply needs to be a subtype ofdeclarationType. 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 asBaseTypeValidator.visitDeclared(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType, com.sun.source.tree.Tree)rather than this method.- Overrides:
- isValidUsein class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- declarationType- the type of the class (TypeElement)
- useType- the use of the class (instance type)
- tree- the tree where the type is used
- Returns:
- true if the useType is a valid use of elemType
 
- 
skipReceiverSubtypeCheckprotected boolean skipReceiverSubtypeCheck(MethodInvocationTree tree, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver) Description copied from class:BaseTypeVisitorIndicates whether to skip subtype checks on the receiver when checking method invocability. A visitor may, for example, allow a method to be invoked even if the receivers are siblings in a hierarchy, provided that some other condition (implemented by the visitor) is satisfied.- Overrides:
- skipReceiverSubtypeCheckin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- tree- the method invocation tree
- methodDefinitionReceiver- the ATM of the receiver of the method definition
- methodCallReceiver- the ATM of the receiver of the method call
- Returns:
- whether to skip subtype checks on the receiver
 
- 
commonAssignmentCheckprotected boolean commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @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.Mark (using the #commonAssignmentCheckOnResourceVariablefield of this class) any assignments where the LHS is a resource variable, so that close doesn't need to be considered. SeecommonAssignmentCheck(AnnotatedTypeMirror, AnnotatedTypeMirror, Tree, String, Object...)for the code that uses and removes the mark.- Overrides:
- commonAssignmentCheckin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- 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 fails
- extraArgs- arguments to the error message key, before "found" and "expected" types
- Returns:
- true if the check succeeds, false if an error message was issued
 
- 
commonAssignmentCheckprotected 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.Iff the LHS is a resource variable, then #commonAssignmentCheckOnResourceVariablewill be true. This method guarantees that#commonAssignmentCheckOnResourceVariablewill be false when it returns.- Overrides:
- commonAssignmentCheckin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- varType- the annotated type of the variable
- valueType- the annotated type of the value
- valueTree- the location to use when reporting the error message
- errorKey- the error message key to use if the check fails
- extraArgs- arguments to the error message key, before "found" and "expected" types
- Returns:
- true if the check succeeds, false if an error message was issued
 
- 
checkConstructorResultprotected 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. The Must Call Checker does not need this warning, because it expects the type of all constructors to beMustCall({})(by default) or some otherMustCalltype, 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. - Overrides:
- checkConstructorResultin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- constructorType- an AnnotatedExecutableType for the constructor
- constructorElement- element that declares the constructor
 
- 
getExceptionParameterLowerBoundAnnotationsChange the default for exception parameter lower bounds to bottom (the default), to prevent false positives. This is unsound; see the discussion on https://github.com/typetools/checker-framework/issues/3839.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. - Overrides:
- getExceptionParameterLowerBoundAnnotationsin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Returns:
- a set containing only the @MustCall({}) annotation
 
- 
visitAnnotationDoes not issue any warnings.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. - Specified by:
- visitAnnotationin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitAnnotationin class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
 
- 
isTypeCastSafeDescription copied from class:BaseTypeVisitorReturns true if the cast is safe.Only primary qualifiers are checked unless the command line option "checkCastElementType" is supplied. - Overrides:
- isTypeCastSafein class- BaseTypeVisitor<MustCallAnnotatedTypeFactory>
- Parameters:
- castType- annotated type of the cast
- exprType- annotated type of the casted expression
- Returns:
- true if the type cast is safe, false otherwise
 
 
-