public class LockVisitor extends BaseTypeVisitor<LockAnnotatedTypeFactory>
BaseTypeVisitor.OverrideChecker| Modifier and Type | Field and Description |
|---|---|
protected static Pattern |
SELF_RECEIVER_PATTERN
A pattern for spotting self receiver
|
atypeFactory, checker, DETERMINISTIC, inferPurity, methodTree, positions, PURE, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElementelements, root, trees, treesWithSuppressWarnings, types| Constructor and Description |
|---|
LockVisitor(BaseTypeChecker checker)
Constructs a
LockVisitor. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType,
ExecutableElement constructorElement)
Issue a warning if the result type of the constructor is not top.
|
protected 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.
|
protected void |
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.
|
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.
|
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.
|
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, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkConstructorInvocation, checkContract, checkDefaultConstructor, checkExceptionParameter, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodInvocability, checkMethodReferenceAsOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkThisOrSuperConstructorCall, checkThrownExpression, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheck, commonAssignmentCheck, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactoryPublic, createTypeValidator, enclosingMemberSelect, enclosingStatement, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, processClassTree, reportMethodInvocabilityError, reportPurityErrors, scan, setRoot, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitConditionalExpression, visitEnhancedForLoop, visitInstanceOf, visitLambdaExpression, visitMemberReference, visitNewArray, visitNewClass, visitReturn, visitSwitchExpression17, visitThrow, visitTypeCast, visitTypeParameter, visitUnary, warnAboutIrrelevantJavaTypesvisitgetCurrentPath, scanreduce, scan, visitArrayType, visitAssert, visitBlock, visitBreak, visitCase, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIf, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitSwitch, visitTry, visitUnionType, visitUses, visitWhileLoop, visitWildcardprotected static final Pattern SELF_RECEIVER_PATTERN
public LockVisitor(BaseTypeChecker checker)
LockVisitor.checker - the type checker to use.public Void visitVariable(VariableTree node, Void p)
visitVariable in interface TreeVisitor<Void,Void>visitVariable in class BaseTypeVisitor<LockAnnotatedTypeFactory>public LockAnnotatedTypeFactory createTypeFactory()
BaseTypeVisitorThe 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()
BaseTypeVisitorThis implementation returns top; subclasses can change this behavior.
Note: by default this method is called by BaseTypeVisitor.getThrowUpperBoundAnnotations(), so that
this annotation is enforced.
getExceptionParameterLowerBoundAnnotations in class BaseTypeVisitor<LockAnnotatedTypeFactory>protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement)
BaseTypeVisitorBaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree).checkConstructorResult in class BaseTypeVisitor<LockAnnotatedTypeFactory>constructorType - AnnotatedExecutableType for the constructorconstructorElement - element that declares the constructorprotected void commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs)
BaseTypeVisitorcommonAssignmentCheck 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 key to use if the check failsextraArgs - arguments to the error message key, before "found" and "expected" typespublic 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 overriddenMethodType, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType)
checkOverride in class BaseTypeVisitor<LockAnnotatedTypeFactory>overriderTree - declaration tree of overriding methodenclosingType - type of overriding classoverriddenMethodType - type of overridden methodoverriddenType - type of overridden classBaseTypeVisitor.checkOverride(MethodTree, AnnotatedTypeMirror.AnnotatedExecutableType,
AnnotatedTypeMirror.AnnotatedDeclaredType, AnnotatedTypeMirror.AnnotatedExecutableType,
AnnotatedTypeMirror.AnnotatedDeclaredType)public Void visitArrayAccess(ArrayAccessTree tree, Void p)
visitArrayAccess in interface TreeVisitor<Void,Void>visitArrayAccess in class TreeScanner<Void,Void>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)
BaseTypeVisitorvisitAnnotation 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 visitBinary(BinaryTree binaryTree, Void p)
visitBinary in interface TreeVisitor<Void,Void>visitBinary in class TreeScanner<Void,Void>public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p)
BaseTypeVisitorvisitCompoundAssignment in interface TreeVisitor<Void,Void>visitCompoundAssignment in class BaseTypeVisitor<LockAnnotatedTypeFactory>