Class LockVisitor
- All Implemented Interfaces:
- TreeVisitor<Void,- Void> 
- See the Checker Framework Manual:
- Lock Checker
- 
Nested Class SummaryNested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitorBaseTypeVisitor.OverrideChecker
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final PatternA pattern for spotting self receiverFields inherited from class org.checkerframework.common.basetype.BaseTypeVisitorassumePureGetters, atypeFactory, checker, DETERMINISTIC, IMPURE, methodTree, positions, PURE, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeHierarchy, typeValidator, unusedWhenElement, warnRedundantAnnotationsFields inherited from class org.checkerframework.framework.source.SourceVisitorelements, root, trees, treesWithSuppressWarnings, types
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidcheckConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Issue a warning if the result type of the constructor declaration is not top.protected booleancheckOverride(MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethodType, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType) Ensures that subclass methods are annotated with a stronger or equally strong side effect annotation than the parent class method.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.Constructs an instance of the appropriate type factory for the implemented type system.protected AnnotationMirrorSetReturns a set of AnnotationMirrors that is a lower bound for exception parameters.booleanisValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree) Skips the call to super and returns true.voidprocessMethodTree(String className, MethodTree tree) Issues an error if a method (explicitly or implicitly) annotated with @MayReleaseLocks has a formal parameter or receiver (explicitly or implicitly) annotated with @GuardSatisfied.protected booleanskipReceiverSubtypeCheck(MethodInvocationTree methodInvocationTree, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver) When visiting a method call, if the receiver formal parameter has type @GuardSatisfied and the receiver actual parameter has type @GuardedBy(...), this method verifies that the guard is satisfied, and it returns true, indicating that the receiver subtype check should be skipped.visitAnnotation(AnnotationTree tree, Void p) Ensure that the annotation arguments comply to their declarations.visitArrayAccess(ArrayAccessTree tree, Void p) visitBinary(BinaryTree binaryTree, Void p) Performs assignability check.visitIdentifier(IdentifierTree tree, Void p) visitMemberSelect(MemberSelectTree tree, Void p) visitMethodInvocation(MethodInvocationTree methodInvocationTree, Void p) When visiting a method invocation, issue an error if the side effect annotation on the called method causes the side effect guarantee of the enclosing method to be violated.visitSynchronized(SynchronizedTree tree, Void p) When visiting a synchronized block, issue an error if the expression has a type that implements the java.util.concurrent.locks.Lock interface.visitVariable(VariableTree tree, Void p) Methods inherited from class org.checkerframework.common.basetype.BaseTypeVisitorcheckAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurityAnnotations, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, contractExpressionAndType, createOverrideChecker, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldPerformContractInference, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitConditionalExpression, visitEnhancedForLoop, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitMethod, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypes, warnInvalidPolymorphicQualifier, warnInvalidPolymorphicQualifier, 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, visitArrayType, visitAssert, visitBindingPattern, visitBlock, visitBreak, visitCase, visitContinue, visitDefaultCaseLabel, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitGuardedPattern, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitParenthesizedPattern, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitSwitchExpression, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcard, visitYield
- 
Field Details- 
SELF_RECEIVER_PATTERNA pattern for spotting self receiver
 
- 
- 
Constructor Details- 
LockVisitorConstructs aLockVisitor.- Parameters:
- checker- the type checker to use
 
 
- 
- 
Method Details- 
visitVariable- Specified by:
- visitVariablein interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitVariablein class- BaseTypeVisitor<LockAnnotatedTypeFactory>
 
- 
createTypeFactoryDescription copied from class:BaseTypeVisitorConstructs 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:
- createTypeFactoryin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Returns:
- the appropriate type factory
 
- 
processMethodTreeIssues an error if a method (explicitly or implicitly) annotated with @MayReleaseLocks has a formal parameter or receiver (explicitly or implicitly) annotated with @GuardSatisfied. Also issues an error if a synchronized method has a @LockingFree, @SideEffectFree, or @Pure annotation.- Overrides:
- processMethodTreein class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Parameters:
- tree- the MethodTree of the method definition to visit
- className- the class that contains the method, for diagnostics only
 
- 
skipReceiverSubtypeCheckprotected boolean skipReceiverSubtypeCheck(MethodInvocationTree methodInvocationTree, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver) When visiting a method call, if the receiver formal parameter has type @GuardSatisfied and the receiver actual parameter has type @GuardedBy(...), this method verifies that the guard is satisfied, and it returns true, indicating that the receiver subtype check should be skipped. If the receiver actual parameter has type @GuardSatisfied, this method simply returns true without performing any other actions. The method returns false otherwise.- Overrides:
- skipReceiverSubtypeCheckin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Parameters:
- methodInvocationTree- the MethodInvocationTree of the method being called
- methodDefinitionReceiver- the ATM of the formal receiver parameter of the method being called
- methodCallReceiver- the ATM of the receiver argument of the method call
- Returns:
- whether the caller can skip the receiver subtype check
 
- 
getExceptionParameterLowerBoundAnnotationsDescription copied from class:BaseTypeVisitorReturns a set of AnnotationMirrors that is a lower bound for exception parameters.This implementation returns top; subclasses can change this behavior. Note: by default this method is called by BaseTypeVisitor.getThrowUpperBoundAnnotations(), so that this annotation is enforced.- Overrides:
- getExceptionParameterLowerBoundAnnotationsin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Returns:
- set of annotation mirrors, one per hierarchy, that form a lower bound of annotations that can be written on an exception parameter
 
- 
checkConstructorResultprotected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement) Description copied from class:BaseTypeVisitorIssue a warning if the result type of the constructor declaration is not top. If it is a supertype of the class, then a conflicting.annos error will also be issued byBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree).- Overrides:
- checkConstructorResultin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Parameters:
- constructorType- the AnnotatedExecutableType for the constructor
- constructorElement- the element that declares the constructor
 
- 
commonAssignmentCheckprotected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitorChecks 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:
- commonAssignmentCheckin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- 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
 
- 
visitMemberSelect- Specified by:
- visitMemberSelectin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitMemberSelectin class- TreeScanner<Void,- Void> 
 
- 
checkOverrideprotected boolean checkOverride(MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethodType, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType) Ensures that subclass methods are annotated with a stronger or equally strong side effect annotation than the parent class method.- Overrides:
- checkOverridein class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Parameters:
- overriderTree- declaration tree of overriding method
- enclosingType- type of overriding class
- overriddenMethodType- type of overridden method
- overriddenType- type of overridden class
- Returns:
- true if the override is allowed
- See Also:
 
- 
visitArrayAccess- Specified by:
- visitArrayAccessin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitArrayAccessin class- TreeScanner<Void,- Void> 
 
- 
isValidUsepublic boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree) Skips the call to super and returns true.GuardedBy({})is the default type on class declarations, which is a subtype of the top annotation@GuardedByUnknown. However, it is valid to declare an instance of a class with any annotation from the@GuardedByhierarchy. Hence, this method returns true for annotations in the@GuardedByhierarchy.Also returns true for annotations in the @LockPossiblyHeldhierarchy since the default for that hierarchy is the top type and annotations from that hierarchy cannot be explicitly written in code.- Overrides:
- isValidUsein class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- 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
 
- 
visitMethodInvocationWhen visiting a method invocation, issue an error if the side effect annotation on the called method causes the side effect guarantee of the enclosing method to be violated. For example, a method annotated with @ReleasesNoLocks may not call a method annotated with @MayReleaseLocks. Also check that matching @GuardSatisfied(index) on a method's formal receiver/parameters matches those in corresponding locations on the method call site.- Specified by:
- visitMethodInvocationin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitMethodInvocationin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
- Parameters:
- methodInvocationTree- the MethodInvocationTree of the method call being visited
 
- 
visitSynchronizedWhen visiting a synchronized block, issue an error if the expression has a type that implements the java.util.concurrent.locks.Lock interface. This prevents explicit locks from being accidentally used as built-in (monitor) locks. This is important because the Lock Checker does not have a mechanism to separately keep track of the explicit lock and the monitor lock of an expression that implements the Lock interface (i.e. there is a @LockHeld annotation used in dataflow, but there are not distinct @MonitorLockHeld and @ExplicitLockHeld annotations). It is assumed that both kinds of locks will never be held for any expression that implements Lock.Additionally, a synchronized block may not be present in a method that has a @LockingFree guarantee or stronger. An error is issued in this case. - Specified by:
- visitSynchronizedin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitSynchronizedin class- TreeScanner<Void,- Void> 
- Parameters:
- tree- the SynchronizedTree for the synchronized block being visited
 
- 
visitAnnotationDescription copied from class:BaseTypeVisitorEnsure that the annotation arguments comply to their declarations. This needs some special casing, as annotation arguments form special trees.- Specified by:
- visitAnnotationin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitAnnotationin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
 
- 
visitIdentifier- Specified by:
- visitIdentifierin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitIdentifierin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
 
- 
visitBinary- Specified by:
- visitBinaryin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitBinaryin class- TreeScanner<Void,- Void> 
 
- 
visitCompoundAssignmentDescription copied from class:BaseTypeVisitorPerforms assignability check.- Specified by:
- visitCompoundAssignmentin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitCompoundAssignmentin class- BaseTypeVisitor<LockAnnotatedTypeFactory>
 
 
-