当前位置: 首页>>代码示例>>Java>>正文


Java TryTree.getResources方法代码示例

本文整理汇总了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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:HeldLockAnalyzer.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:ConvertToARM.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:70,代码来源:JavaInputAstVisitor.java

示例4: getResources

import com.sun.source.tree.TryTree; //导入方法依赖的package包/类
@Override
public List<? extends Tree> getResources(TryTree tree) {
    return tree.getResources();
}
 
开发者ID:provegard,项目名称:yield4j,代码行数:5,代码来源:Ge7JavacUtils.java


注:本文中的com.sun.source.tree.TryTree.getResources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。