本文整理汇总了Java中com.sun.source.tree.SynchronizedTree类的典型用法代码示例。如果您正苦于以下问题:Java SynchronizedTree类的具体用法?Java SynchronizedTree怎么用?Java SynchronizedTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SynchronizedTree类属于com.sun.source.tree包,在下文中一共展示了SynchronizedTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
/** 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);
}
};
}
示例2: matchSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@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;
}
示例3: matchSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Description matchSynchronized(SynchronizedTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(stripParentheses(tree.getExpression()));
if (!(symbol instanceof VarSymbol)) {
return NO_MATCH;
}
// TODO(cushon): check that the receiver doesn't contain mutable state.
// Currently 'this.locks[i].mu' is accepted if 'mu' is final but 'locks' is non-final.
VarSymbol varSymbol = (VarSymbol) symbol;
if (varSymbol.isLocal() || varSymbol.isStatic() || (varSymbol.flags() & Flags.FINAL) != 0) {
return NO_MATCH;
}
if (ASTHelpers.hasAnnotation(varSymbol, LazyInit.class, state)) {
return NO_MATCH;
}
Name ownerName = varSymbol.owner.enclClass().getQualifiedName();
if (Stream.of("java.io.Writer", "java.io.Reader").anyMatch(ownerName::contentEquals)) {
// These classes contain a non-final 'lock' variable available to subclasses, and we can't
// make these locks final.
return NO_MATCH;
}
return describeMatch(tree.getExpression());
}
示例4: inSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
/**
* 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);
if (methodTree != null
&& methodTree.getModifiers().getFlags().contains(Modifier.SYNCHRONIZED)) {
return true;
}
return false;
}
};
}
示例5: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Tree visitSynchronized(SynchronizedTree tree, Void p) {
SynchronizedTree n = make.Synchronized(tree.getExpression(), tree.getBlock());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例6: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
public Boolean visitSynchronized(SynchronizedTree node, TreePath p) {
if (p == null) {
super.visitSynchronized(node, p);
return false;
}
SynchronizedTree at = (SynchronizedTree) p.getLeaf();
if (!scan(node.getExpression(), at.getExpression(), p)) {
return false;
}
return scan(node.getBlock(), at.getBlock(), p);
}
示例7: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Void visitSynchronized(SynchronizedTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitSynchronized(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例8: run
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@TriggerTreeKind(Kind.SYNCHRONIZED)
public static ErrorDescription run(HintContext ctx) {
ExpressionTree expression = ((SynchronizedTree) ctx.getPath().getLeaf()).getExpression();
Element e = ctx.getInfo().getTrees().getElement(new TreePath(ctx.getPath(), expression));
if (e == null || e.getKind() != ElementKind.FIELD || e.getModifiers().contains(Modifier.FINAL)) {
return null;
}
String displayName = NbBundle.getMessage(SyncOnNonFinal.class, "ERR_SynchronizationOnNonFinalField");
return ErrorDescriptionFactory.forTree(ctx, expression, displayName);
}
示例9: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public List<Tree> visitSynchronized(SynchronizedTree node, ExpressionScanner.ExpressionsInfo p) {
List<Tree> result = null;
if (acceptsTree(node)) {
result = scan(node.getExpression(), p);
}
return reduce(result, scan(node.getBlock(), p));
}
示例10: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Void visitSynchronized(SynchronizedTree node, Void unused) {
sync(node);
token("synchronized");
builder.space();
token("(");
builder.open(plusFour);
builder.breakOp();
scan(skipParen(node.getExpression()), null);
builder.close();
token(")");
builder.space();
scan(node.getBlock(), null);
return null;
}
示例11: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Void visitSynchronized(SynchronizedTree tree, VisitorState visitorState) {
VisitorState state = visitorState.withPath(getCurrentPath());
for (SynchronizedTreeMatcher matcher : synchronizedMatchers) {
if (!isSuppressed(matcher, state)) {
try {
reportMatch(matcher.matchSynchronized(tree, state), tree, state);
} catch (Throwable t) {
handleError(matcher, t);
}
}
}
return super.visitSynchronized(tree, state);
}
示例12: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Choice<State<JCSynchronized>> visitSynchronized(
final SynchronizedTree node, State<?> state) {
return chooseSubtrees(
state,
s -> unifyExpression(node.getExpression(), s),
s -> unifyStatement(node.getBlock(), s),
(expr, block) -> maker().Synchronized(expr, (JCBlock) block));
}
示例13: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public Void visitSynchronized(SynchronizedTree tree, HeldLockSet locks) {
// The synchronized expression is held in the body of the synchronized statement:
Optional<GuardedByExpression> lockExpression =
GuardedByBinder.bindExpression((JCExpression) tree.getExpression(), visitorState);
scan(tree.getBlock(), lockExpression.isPresent() ? locks.plus(lockExpression.get()) : locks);
return null;
}
示例14: findDCL
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
/**
* 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);
}
示例15: visitSynchronized
import com.sun.source.tree.SynchronizedTree; //导入依赖的package包/类
@Override
public PurityResult visitSynchronized(SynchronizedTree node,
PurityResult p) {
PurityResult r = scan(node.getExpression(), p);
r = scan(node.getBlock(), r);
return r;
}