本文整理汇总了Java中com.sun.source.tree.TryTree.getResources方法的典型用法代码示例。如果您正苦于以下问题:Java TryTree.getResources方法的具体用法?Java TryTree.getResources怎么用?Java TryTree.getResources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.TryTree
的用法示例。
在下文中一共展示了TryTree.getResources方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Void visitTry(TryTree tree, HeldLockSet locks) {
scan(tree.getResources(), locks);
List<? extends Tree> resources = tree.getResources();
scan(resources, locks);
// Cheesy try/finally heuristic: assume that all locks released in the finally
// are held for the entirety of the try and catch statements.
Collection<GuardedByExpression> releasedLocks =
ReleasedLockFinder.find(tree.getFinallyBlock(), visitorState);
if (resources.isEmpty()) {
scan(tree.getBlock(), locks.plusAll(releasedLocks));
} else {
// We don't know what to do with the try-with-resources block.
// TODO(cushon) - recognize common try-with-resources patterns. Currently there is no
// standard implementation of an AutoCloseable lock resource to detect.
}
scan(tree.getCatches(), locks.plusAll(releasedLocks));
scan(tree.getFinallyBlock(), locks);
return null;
}
示例2: findNestedARM
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
private static TryTree findNestedARM(
final Collection<? extends StatementTree> stms,
final StatementTree var) {
int state = var != null ? 0 : 1;
for (StatementTree stm : stms) {
if (stm == var) {
state = 1;
}
if (state == 1) {
if (stm.getKind() == Kind.TRY) {
final TryTree tryTree = (TryTree)stm;
if (tryTree.getResources() != null && !tryTree.getResources().isEmpty()) {
return tryTree;
} else {
final Iterator<? extends StatementTree> blkStms = tryTree.getBlock().getStatements().iterator();
if (blkStms.hasNext()) {
StatementTree bstm = blkStms.next();
if (bstm.getKind() == Kind.TRY) {
return (TryTree)bstm;
}
if (bstm.getKind() == Kind.EXPRESSION_STATEMENT && blkStms.hasNext()) {
bstm = blkStms.next();
if (bstm.getKind() == Kind.TRY) {
return (TryTree)bstm;
}
}
}
}
}
if (stm != var) {
break;
}
}
}
return null;
}
示例3: visitTry
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public Void visitTry(TryTree node, Void unused) {
sync(node);
builder.open(ZERO);
token("try");
builder.space();
if (!node.getResources().isEmpty()) {
token("(");
builder.open(node.getResources().size() > 1 ? plusFour : ZERO);
boolean first = true;
for (Tree resource : node.getResources()) {
if (!first) {
builder.forcedBreak();
}
VariableTree variableTree = (VariableTree) resource;
declareOne(
DeclarationKind.PARAMETER,
fieldAnnotationDirection(variableTree.getModifiers()),
Optional.of(variableTree.getModifiers()),
variableTree.getType(),
VarArgsOrNot.NO,
ImmutableList.<AnnotationTree>of(),
variableTree.getName(),
"",
"=",
Optional.fromNullable(variableTree.getInitializer()),
Optional.<String>absent(),
Optional.<ExpressionTree>absent(),
Optional.<TypeWithDims>absent());
if (builder.peekToken().equals(Optional.of(";"))) {
token(";");
builder.space();
}
first = false;
}
if (builder.peekToken().equals(Optional.of(";"))) {
token(";");
builder.space();
}
token(")");
builder.close();
builder.space();
}
// An empty try-with-resources body can collapse to "{}" if there are no trailing catch or
// finally blocks.
boolean trailingClauses = !node.getCatches().isEmpty() || node.getFinallyBlock() != null;
visitBlock(
node.getBlock(),
CollapseEmptyOrNot.valueOf(!trailingClauses),
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.valueOf(trailingClauses));
for (int i = 0; i < node.getCatches().size(); i++) {
CatchTree catchClause = node.getCatches().get(i);
trailingClauses = i < node.getCatches().size() - 1 || node.getFinallyBlock() != null;
visitCatchClause(catchClause, AllowTrailingBlankLine.valueOf(trailingClauses));
}
if (node.getFinallyBlock() != null) {
builder.space();
token("finally");
builder.space();
visitBlock(
node.getFinallyBlock(),
CollapseEmptyOrNot.NO,
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.NO);
}
builder.close();
return null;
}
示例4: getResources
import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public List<? extends Tree> getResources(TryTree tree) {
return tree.getResources();
}