@Override public UTry visitTry(TryTree tree, Void v) { @SuppressWarnings({"unchecked", "rawtypes"}) List<UTree<?>> resources = cast(templateTrees(tree.getResources()), (Class<UTree<?>>) (Class) UTree.class); UBlock block = visitBlock(tree.getBlock(), null); ImmutableList.Builder<UCatch> catchesBuilder = ImmutableList.builder(); for (CatchTree catchTree : tree.getCatches()) { catchesBuilder.add(visitCatch(catchTree, null)); } UBlock finallyBlock = (tree.getFinallyBlock() == null) ? null : visitBlock(tree.getFinallyBlock(), null); return UTry.create(resources, block, catchesBuilder.build(), finallyBlock); }
@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; }
@Override @Nullable public Choice<Unifier> visitTry(TryTree node, @Nullable Unifier unifier) { return unifyList(unifier, getResources(), node.getResources()) .thenChoose(unifications(getBlock(), node.getBlock())) .thenChoose(unifications(getCatches(), node.getCatches())) .thenChoose(unifications(getFinallyBlock(), node.getFinallyBlock())); } }
TryTree tryTree = (TryTree) curr; boolean inResources = false; for (Tree resource : tryTree.getResources()) { if (resource.equals(prev)) { inResources = true; for (Tree resource : tryTree.getResources()) { if (resource.equals(prev)) { break; addAllIfVariable(tryTree.getResources(), result);
@Override public Choice<State<JCTry>> visitTry(final TryTree node, State<?> state) { return chooseSubtrees( state, s -> unify(node.getResources(), s), s -> unifyStatement(node.getBlock(), s), s -> unify(node.getCatches(), s), s -> unifyStatement(node.getFinallyBlock(), s), (resources, block, catches, finallyBlock) -> maker() .Try( resources, (JCBlock) block, List.convert(JCCatch.class, catches), (JCBlock) finallyBlock)); }
@Override public Void visitTry(TryTree node, Void p) { try { return super.visitTry(node, p); } finally { oldTrees.removeAll(node.getResources()); } }
@Override public String visitTry(TryTree node, Void v) { StringBuilder out = new StringBuilder(); List<? extends Tree> resources = node.getResources(); BlockTree block = node.getBlock(); List<? extends CatchTree> catches = node.getCatches();
private TryTree modifyTryCatch(TryTree traj, int index, CatchTree kec, Operation op) { TryTree copy = Try( traj.getResources(), traj.getBlock(), c(traj.getCatches(), index, kec, op), traj.getFinallyBlock() ); return copy; }
@Override public UTry visitTry(TryTree tree, Void v) { @SuppressWarnings({"unchecked", "rawtypes"}) List<UTree<?>> resources = cast(templateTrees(tree.getResources()), (Class<UTree<?>>) (Class) UTree.class); UBlock block = visitBlock(tree.getBlock(), null); ImmutableList.Builder<UCatch> catchesBuilder = ImmutableList.builder(); for (CatchTree catchTree : tree.getCatches()) { catchesBuilder.add(visitCatch(catchTree, null)); } UBlock finallyBlock = (tree.getFinallyBlock() == null) ? null : visitBlock(tree.getFinallyBlock(), null); return UTry.create(resources, block, catchesBuilder.build(), finallyBlock); }
Types types = info.getTypes(); Elements elements = info.getElements(); for (Tree res : node.getResources()) { TypeMirror resType = trees.getTypeMirror(new TreePath(getCurrentPath(), res)); if (resType != null && resType.getKind() == TypeKind.DECLARED) {
protected final TryTree rewriteChildren(TryTree tree) { List<? extends Tree> resources = translate(tree.getResources()); BlockTree body = (BlockTree)translate(tree.getBlock()); List<? extends CatchTree> catches = translateStable(tree.getCatches()); BlockTree finalizer = (BlockTree)translate(tree.getFinallyBlock()); if (body!=tree.getBlock() || !catches.equals(tree.getCatches()) || finalizer!=tree.getFinallyBlock() || !resources.equals(tree.getResources())) { TryTree n = make.Try(resources, body, catches, finalizer); model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); tree = n; } return tree; }
@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; }
public R visitTry(TryTree node, P p) { R r = scan(node.getResources(), p); r = scanAndReduce(node.getBlock(), p, r); r = scanAndReduce(node.getCatches(), p, r); r = scanAndReduce(node.getFinallyBlock(), p, r); return r; }
public R visitTry(TryTree node, P p) { R r = scan(node.getResources(), p); r = scanAndReduce(node.getBlock(), p, r); r = scanAndReduce(node.getCatches(), p, r); r = scanAndReduce(node.getFinallyBlock(), p, r); return r; }
public Boolean visitTry(TryTree node, TreePath p) { if (p == null) { super.visitTry(node, p); return false; } TryTree at = (TryTree) p.getLeaf(); if (!checkLists(node.getResources(), at.getResources(), p)) { return false; } if (!scan(node.getBlock(), at.getBlock(), p)) { return false; } if (!checkLists(node.getCatches(), at.getCatches(), p)) { return false; } return scan(node.getFinallyBlock(), at.getFinallyBlock(), p); }
@Override @Nullable public Choice<Unifier> visitTry(TryTree node, @Nullable Unifier unifier) { return unifyList(unifier, getResources(), node.getResources()) .thenChoose(unifications(getBlock(), node.getBlock())) .thenChoose(unifications(getCatches(), node.getCatches())) .thenChoose(unifications(getFinallyBlock(), node.getFinallyBlock())); } }
@Override public Tree visitTry(TryTree tree, Void p) { TryTree n = make.Try(tree.getResources(), tree.getBlock(), tree.getCatches(), tree.getFinallyBlock()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
addKeyword(env, CATCH_KEYWORD, null, true); addKeyword(env, FINALLY_KEYWORD, null, true); if (((TryTree) last).getCatches().isEmpty() && ((TryTree) last).getResources().isEmpty()) { return;
@Override public Choice<State<JCTry>> visitTry(final TryTree node, State<?> state) { return chooseSubtrees( state, s -> unify(node.getResources(), s), s -> unifyStatement(node.getBlock(), s), s -> unify(node.getCatches(), s), s -> unifyStatement(node.getFinallyBlock(), s), (resources, block, catches, finallyBlock) -> maker() .Try( resources, (JCBlock) block, List.convert(JCCatch.class, catches), (JCBlock) finallyBlock)); }
@Override public Boolean visitTry(TryTree node, Void p) { accept(TRY); List<? extends Tree> res = node.getResources(); if (res != null && !res.isEmpty()) { boolean old = continuationIndent;