use of com.sun.source.tree.SynchronizedTree in project error-prone by google.
the class StaticGuardedByInstance method matchSynchronized.
@Override
public Description matchSynchronized(SynchronizedTree tree, VisitorState state) {
Symbol lock = ASTHelpers.getSymbol(stripParentheses(tree.getExpression()));
if (!(lock instanceof VarSymbol)) {
return Description.NO_MATCH;
}
if (lock.isStatic()) {
return Description.NO_MATCH;
}
Multimap<VarSymbol, Tree> writes = WriteVisitor.scan(tree.getBlock());
for (Entry<VarSymbol, Tree> write : writes.entries()) {
if (!write.getKey().isStatic()) {
continue;
}
state.reportMatch(buildDescription(write.getValue()).setMessage(String.format(MESSAGE, lock)).build());
}
return Description.NO_MATCH;
}
use of com.sun.source.tree.SynchronizedTree in project error-prone by google.
the class Matchers method inSynchronized.
/**
* Matches if this Tree is enclosed by either a synchronized block or a synchronized method.
*/
public static final <T extends Tree> Matcher<T> inSynchronized() {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
SynchronizedTree synchronizedTree = ASTHelpers.findEnclosingNode(state.getPath(), SynchronizedTree.class);
if (synchronizedTree != null) {
return true;
}
MethodTree methodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
return methodTree != null && methodTree.getModifiers().getFlags().contains(Modifier.SYNCHRONIZED);
}
};
}
use of com.sun.source.tree.SynchronizedTree in project error-prone by google.
the class DoubleCheckedLocking method findDCL.
/**
* Matches an instance of DCL. The canonical pattern is:
*
* <pre>{@code
* if ($X == null) {
* synchronized (...) {
* if ($X == null) {
* ...
* }
* ...
* }
* }
* }</pre>
*
* Gaps before the synchronized or inner 'if' statement are ignored, and the operands in the
* null-checks are accepted in either order.
*/
@Nullable
static DCLInfo findDCL(IfTree outerIf) {
// TODO(cushon): Optional.ifPresent...
ExpressionTree outerIfTest = getNullCheckedExpression(outerIf.getCondition());
if (outerIfTest == null) {
return null;
}
SynchronizedTree synchTree = getChild(outerIf.getThenStatement(), SynchronizedTree.class);
if (synchTree == null) {
return null;
}
IfTree innerIf = getChild(synchTree.getBlock(), IfTree.class);
if (innerIf == null) {
return null;
}
ExpressionTree innerIfTest = getNullCheckedExpression(innerIf.getCondition());
if (innerIfTest == null) {
return null;
}
Symbol outerSym = ASTHelpers.getSymbol(outerIfTest);
if (!Objects.equals(outerSym, ASTHelpers.getSymbol(innerIfTest))) {
return null;
}
if (!(outerSym instanceof VarSymbol)) {
return null;
}
VarSymbol var = (VarSymbol) outerSym;
return DCLInfo.create(outerIf, synchTree, innerIf, var);
}
Aggregations