public class LockVisitor extends BaseTypeVisitor<LockAnnotatedTypeFactory>
Modifier and Type | Field and Description |
---|---|
protected static Pattern |
selfReceiverPattern |
atypeFactory, checker, contractsUtils, positions, typeValidator, visitorState
elements, root, trees, types
Constructor and Description |
---|
LockVisitor(BaseTypeChecker checker) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkOverride(MethodTree overriderTree,
AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType,
AnnotatedTypeMirror.AnnotatedExecutableType overridden,
AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType,
Void p)
Ensures that subclass methods are annotated with a stronger or equally strong side effect
annotation than the parent class method.
|
protected void |
commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType,
Tree valueTree,
@CompilerMessageKey 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.
|
LockAnnotatedTypeFactory |
createTypeFactory()
Constructs an instance of the appropriate type factory for the implemented type system.
|
protected Set<? extends AnnotationMirror> |
getExceptionParameterLowerBoundAnnotations()
Returns a set of AnnotationMirrors that is a lower bound for exception parameters.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType,
Tree tree)
Skips the call to super and returns true.
|
void |
processClassTree(ClassTree node)
Disallows annotations from the @GuardedBy hierarchy on class declarations (other
than @GuardedBy({}).
|
protected 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.
|
Void |
visitAnnotation(AnnotationTree tree,
Void p)
Ensure that the annotation arguments comply to their declarations.
|
Void |
visitArrayAccess(ArrayAccessTree tree,
Void p) |
Void |
visitBinary(BinaryTree binaryTree,
Void p) |
Void |
visitCompoundAssignment(CompoundAssignmentTree node,
Void p)
Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree) . |
Void |
visitIdentifier(IdentifierTree tree,
Void p) |
Void |
visitMemberSelect(MemberSelectTree tree,
Void p) |
Void |
visitMethod(MethodTree node,
Void p)
Issues an error if a method (explicitly or implicitly) annotated with @MayReleaseLocks has a
formal parameter or receiver (explicitly or implicitly) annotated with @GuardSatisfied.
|
Void |
visitMethodInvocation(MethodInvocationTree node,
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.
|
Void |
visitSynchronized(SynchronizedTree node,
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.
|
Void |
visitVariable(VariableTree node,
Void p) |
checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkPostcondition, checkPreconditions, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, commonAssignmentCheck, commonAssignmentCheck, createTypeValidator, enclosingMemberSelect, enclosingStatement, getThrowUpperBoundAnnotations, getTypeFactory, isAccessAllowed, isAssignable, isValidUse, isValidUse, isVectorCopyInto, reportPurityErrors, scan, setRoot, shouldSkipUses, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitConditionalExpression, visitEnhancedForLoop, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitNewArray, visitNewClass, visitParameterizedType, visitReturn, visitThrow, visitTypeCast, visitTypeParameter, visitUnary
visit
getCurrentPath, scan
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitTry, visitUnionType, visitWhileLoop, visitWildcard
protected static final Pattern selfReceiverPattern
public LockVisitor(BaseTypeChecker checker)
public Void visitVariable(VariableTree node, Void p)
visitVariable
in interface TreeVisitor<Void,Void>
visitVariable
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public LockAnnotatedTypeFactory 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<LockAnnotatedTypeFactory>
public Void visitMethod(MethodTree node, Void p)
visitMethod
in interface TreeVisitor<Void,Void>
visitMethod
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- the MethodTree of the method definition to visitprotected boolean skipReceiverSubtypeCheck(MethodInvocationTree methodInvocationTree, AnnotatedTypeMirror methodDefinitionReceiver, AnnotatedTypeMirror methodCallReceiver)
skipReceiverSubtypeCheck
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
methodInvocationTree
- the MethodInvocationTree of the method being calledmethodDefinitionReceiver
- the ATM of the formal receiver parameter of the method being
calledmethodCallReceiver
- the ATM of the receiver argument of the method callprotected Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotations()
BaseTypeVisitor
Note: by default this method is called by getThrowUpperBoundAnnotations(), so that this annotation is enforced.
(Default is top)
getExceptionParameterLowerBoundAnnotations
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
protected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey)
BaseTypeVisitor
commonAssignmentCheck
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
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
)public Void visitMemberSelect(MemberSelectTree tree, Void p)
visitMemberSelect
in interface TreeVisitor<Void,Void>
visitMemberSelect
in class TreeScanner<Void,Void>
protected boolean checkOverride(MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, Void p)
checkOverride
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
overriderTree
- declaration tree of overriding methodenclosingType
- type of overriding classoverridden
- type of overridden methodoverriddenType
- type of overridden classpublic Void visitArrayAccess(ArrayAccessTree tree, Void p)
visitArrayAccess
in interface TreeVisitor<Void,Void>
visitArrayAccess
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, Tree tree)
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 @GuardedBy
hierarchy. Hence, this method returns
true for annotations in the @GuardedBy
hierarchy.
Also returns true for annotations in the @LockPossiblyHeld
hierarchy since the
default for that hierarchy is the top type and annotations from that hierarchy cannot be
explicitly written in code.
isValidUse
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
declarationType
- the type of the class (TypeElement)useType
- the use of the class (instance type)tree
- the tree where the type is usedpublic Void visitMethodInvocation(MethodInvocationTree node, Void p)
visitMethodInvocation
in interface TreeVisitor<Void,Void>
visitMethodInvocation
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- the MethodInvocationTree of the method call being visitedpublic Void visitSynchronized(SynchronizedTree node, Void p)
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.
visitSynchronized
in interface TreeVisitor<Void,Void>
visitSynchronized
in class TreeScanner<Void,Void>
node
- the SynchronizedTree for the synchronized block being visitedpublic Void visitAnnotation(AnnotationTree tree, Void p)
BaseTypeVisitor
visitAnnotation
in interface TreeVisitor<Void,Void>
visitAnnotation
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public Void visitIdentifier(IdentifierTree tree, Void p)
visitIdentifier
in interface TreeVisitor<Void,Void>
visitIdentifier
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public void processClassTree(ClassTree node)
processClassTree
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- class to checkpublic Void visitBinary(BinaryTree binaryTree, Void p)
visitBinary
in interface TreeVisitor<Void,Void>
visitBinary
in class TreeScanner<Void,Void>
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
BaseTypeVisitor
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree)
.visitCompoundAssignment
in interface TreeVisitor<Void,Void>
visitCompoundAssignment
in class BaseTypeVisitor<LockAnnotatedTypeFactory>