public class LockVisitor extends BaseTypeVisitor<LockAnnotatedTypeFactory>
BaseTypeVisitor.OverrideChecker
Modifier and Type | Field and Description |
---|---|
protected static java.util.regex.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(com.sun.source.tree.MethodTree overriderTree,
AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType,
AnnotatedTypeMirror.AnnotatedExecutableType overridden,
AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType)
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,
com.sun.source.tree.Tree valueTree,
@CompilerMessageKey java.lang.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 java.util.Set<? extends javax.lang.model.element.AnnotationMirror> |
getExceptionParameterLowerBoundAnnotations()
Returns a set of AnnotationMirrors that is a lower bound for exception parameters.
|
boolean |
isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType,
AnnotatedTypeMirror.AnnotatedDeclaredType useType,
com.sun.source.tree.Tree tree)
Skips the call to super and returns true.
|
void |
processClassTree(com.sun.source.tree.ClassTree node)
Disallows annotations from the @GuardedBy hierarchy on class declarations (other
than @GuardedBy({}).
|
protected boolean |
skipReceiverSubtypeCheck(com.sun.source.tree.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.
|
java.lang.Void |
visitAnnotation(com.sun.source.tree.AnnotationTree tree,
java.lang.Void p)
Ensure that the annotation arguments comply to their declarations.
|
java.lang.Void |
visitArrayAccess(com.sun.source.tree.ArrayAccessTree tree,
java.lang.Void p) |
java.lang.Void |
visitBinary(com.sun.source.tree.BinaryTree binaryTree,
java.lang.Void p) |
java.lang.Void |
visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node,
java.lang.Void p)
Performs assignability check using
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree) . |
java.lang.Void |
visitIdentifier(com.sun.source.tree.IdentifierTree tree,
java.lang.Void p) |
java.lang.Void |
visitMemberSelect(com.sun.source.tree.MemberSelectTree tree,
java.lang.Void p) |
java.lang.Void |
visitMethod(com.sun.source.tree.MethodTree node,
java.lang.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.
|
java.lang.Void |
visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node,
java.lang.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.
|
java.lang.Void |
visitSynchronized(com.sun.source.tree.SynchronizedTree node,
java.lang.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.
|
java.lang.Void |
visitVariable(com.sun.source.tree.VariableTree node,
java.lang.Void p) |
checkAccess, checkArguments, checkArrayInitialization, checkAssignability, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkFieldInvariantDeclarations, checkForAnnotatedJdk, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, createOverrideChecker, 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, visitTry, visitTypeCast, visitTypeParameter, visitUnary
visit
reduce, scan, visitAnnotatedType, visitArrayType, visitAssert, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitOther, visitParenthesized, visitPrimitiveType, visitSwitch, visitUnionType, visitWhileLoop, visitWildcard
public LockVisitor(BaseTypeChecker checker)
public java.lang.Void visitVariable(com.sun.source.tree.VariableTree node, java.lang.Void p)
visitVariable
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.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 java.lang.Void visitMethod(com.sun.source.tree.MethodTree node, java.lang.Void p)
visitMethod
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMethod
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- the MethodTree of the method definition to visitprotected boolean skipReceiverSubtypeCheck(com.sun.source.tree.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 java.util.Set<? extends javax.lang.model.element.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, com.sun.source.tree.Tree valueTree, @CompilerMessageKey java.lang.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 java.lang.Void visitMemberSelect(com.sun.source.tree.MemberSelectTree tree, java.lang.Void p)
visitMemberSelect
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMemberSelect
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
protected boolean checkOverride(com.sun.source.tree.MethodTree overriderTree, AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType)
checkOverride
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
overriderTree
- declaration tree of overriding methodenclosingType
- type of overriding classoverridden
- type of overridden methodoverriddenType
- type of overridden classBaseTypeVisitor.checkOverride(MethodTree, AnnotatedTypeMirror.AnnotatedExecutableType,
AnnotatedTypeMirror.AnnotatedDeclaredType, AnnotatedTypeMirror.AnnotatedExecutableType,
AnnotatedTypeMirror.AnnotatedDeclaredType)
public java.lang.Void visitArrayAccess(com.sun.source.tree.ArrayAccessTree tree, java.lang.Void p)
visitArrayAccess
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitArrayAccess
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public boolean isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType declarationType, AnnotatedTypeMirror.AnnotatedDeclaredType useType, com.sun.source.tree.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 java.lang.Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, java.lang.Void p)
visitMethodInvocation
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitMethodInvocation
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- the MethodInvocationTree of the method call being visitedpublic java.lang.Void visitSynchronized(com.sun.source.tree.SynchronizedTree node, java.lang.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 com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitSynchronized
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
node
- the SynchronizedTree for the synchronized block being visitedpublic java.lang.Void visitAnnotation(com.sun.source.tree.AnnotationTree tree, java.lang.Void p)
BaseTypeVisitor
visitAnnotation
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitAnnotation
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public java.lang.Void visitIdentifier(com.sun.source.tree.IdentifierTree tree, java.lang.Void p)
visitIdentifier
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitIdentifier
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
public void processClassTree(com.sun.source.tree.ClassTree node)
processClassTree
in class BaseTypeVisitor<LockAnnotatedTypeFactory>
node
- class to checkpublic java.lang.Void visitBinary(com.sun.source.tree.BinaryTree binaryTree, java.lang.Void p)
visitBinary
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitBinary
in class com.sun.source.util.TreeScanner<java.lang.Void,java.lang.Void>
public java.lang.Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node, java.lang.Void p)
BaseTypeVisitor
BaseTypeVisitor.checkAssignability(AnnotatedTypeMirror, Tree)
.visitCompoundAssignment
in interface com.sun.source.tree.TreeVisitor<java.lang.Void,java.lang.Void>
visitCompoundAssignment
in class BaseTypeVisitor<LockAnnotatedTypeFactory>