JCBlock block = tryStatement.getBlock(); if (!expressionStatement((t, s) -> t.equals(tree)) .matches(getLast(block.getStatements()), state)) { if (tryStatement.getCatches().size() != 1) { JCCatch catchTree = Iterables.getOnlyElement(tryStatement.getCatches()); if (catchTree.getParameter().getType().getKind() == Kind.UNION_TYPE) { } else { startPosition = block.getStartPosition(); endPosition = getLast(tryStatement.getBlock().getStatements()).getStartPosition(); tryStatement.getStartPosition(), startPosition, String.format( .prefixWith(tryStatement, state.getSourceForNode(catchTree.getParameter())) .replace( tryStatement.getStartPosition(), startPosition, String.format(
@Override public void visitTry(JCTry tree) { if (tree.getResources().isEmpty()) { super.visitTry(tree); return; print("try ("); boolean first = true; for (JCTree resource : tree.getResources()) { if (!first) { print(";"); for (JCCatch catchStmt : tree.getCatches()) { printStat(catchStmt); if (tree.getFinallyBlock() != null) { print(" finally "); printStat(tree.getFinallyBlock());
localPointer = diffTree(oldT.body, newT.body, bodyPos); copyTo(localPointer, localPointer = bodyPos[1]); PositionEstimator est = EstimatorFactory.catches(oldT.getCatches(), newT.getCatches(), oldT.finalizer != null, diffContext); localPointer = diffList(oldT.catchers, newT.catchers, localPointer, est, Measure.DEFAULT, printer);
JCBlock block = tryStatement.getBlock(); if (!expressionStatement((t, s) -> t.equals(tree)) .matches(getLast(block.getStatements()), state)) { if (tryStatement.getCatches().size() != 1) { JCCatch catchTree = Iterables.getOnlyElement(tryStatement.getCatches()); if (catchTree.getParameter().getType().getKind() == Kind.UNION_TYPE) { } else { startPosition = block.getStartPosition(); endPosition = getLast(tryStatement.getBlock().getStatements()).getStartPosition(); tryStatement.getStartPosition(), startPosition, String.format( .prefixWith(tryStatement, state.getSourceForNode(catchTree.getParameter())) .replace( tryStatement.getStartPosition(), startPosition, String.format(
make_at(tree.pos()); twrVars = twrVars.dup(); JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body,
make_at(tree.pos()); twrVars = twrVars.dup(); JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body,
@Override public void visitTry(JCTry tree) { if (tree.getResources().isEmpty()) { super.visitTry(tree); return; print("try ("); boolean first = true; for (JCTree resource : tree.getResources()) { if (!first) { print(";"); for (JCCatch catchStmt : tree.getCatches()) { printStat(catchStmt); if (tree.getFinallyBlock() != null) { print(" finally "); printStat(tree.getFinallyBlock());
@Override public void visitTry(JCTry tree) { print("try"); if (!tree.getResources().isEmpty()) { print(" ("); //XXX: space should be according to the code style! for (Iterator<? extends JCTree> it = tree.getResources().iterator(); it.hasNext();) { JCTree r = it.next(); //XXX: disabling copying of original text, as the ending ';' needs to be removed in some cases. oldTrees.remove(r); printPrecedingComments(r, false); printExpr(r, 0); printTrailingComments(r, false); if (it.hasNext()) print(";"); } print(") "); //XXX: space should be according to the code style! } printBlock(tree.body, cs.getOtherBracePlacement(), cs.spaceBeforeTryLeftBrace()); for (List < JCCatch > l = tree.catchers; l.nonEmpty(); l = l.tail) printStat(l.head); if (tree.finalizer != null) { printFinallyBlock(tree.finalizer); } }
private static void analyzeTry(SourceContext context, JCTree.JCTry tryExpr) throws IOException { JCTree.JCBlock block = tryExpr.getBlock(); List<JCTree> resources = tryExpr.getResources(); List<JCTree.JCCatch> catches = tryExpr.getCatches(); JCTree.JCBlock lyBlock = tryExpr.getFinallyBlock(); if (nonNull(resources)) { for (JCTree resource : resources) { analyzeParsedTree(context, resource); } } analyzeParsedTree(context, block); if (nonNull(catches)) { for (JCTree.JCCatch jcCatch : catches) { JCTree.JCVariableDecl parameter = jcCatch.getParameter(); analyzeParsedTree(context, parameter); JCTree.JCBlock catchBlock = jcCatch.getBlock(); analyzeParsedTree(context, catchBlock); } } analyzeParsedTree(context, lyBlock); }
private static JCTry enclosingTry(VisitorState state) { Tree prev = null; for (Tree parent : state.getPath()) { switch (parent.getKind()) { case METHOD: case LAMBDA_EXPRESSION: return null; case TRY: JCTry tryStatement = (JCTry) parent; return tryStatement.getBlock().equals(prev) ? tryStatement : null; default: // fall out } prev = parent; } return null; } }
private static Optional<JCCatch> catchesType( JCTry tryStatement, Type assertionErrorType, VisitorState state) { return tryStatement.getCatches().stream() .filter( catchTree -> { Type type = ASTHelpers.getType(catchTree.getParameter()); return (type.isUnion() ? Streams.stream(((UnionClassType) type).getAlternativeTypes()) : Stream.of(type)) .anyMatch(caught -> isSubtype(assertionErrorType, caught, state)); }) .findFirst(); }
public JCTry Try(List<JCTree> resources, JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { JCTry tree = new JCTry(resources, body, catchers, finalizer); tree.pos = pos; return tree; }
public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { JCTry tree = new JCTry(body, catchers, finalizer); tree.pos = pos; return tree; }
@Override public void visitTry(JCTry node) { Try t = new Try(); t.rawBody(toTree(node.getBlock())); t.rawFinally(toTree(node.getFinallyBlock())); fillList(node.getCatches(), t.rawCatches()); set(node, t); }
public JCTry Try(List<JCTree> resources, JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { JCTry tree = new JCTry(resources, body, catchers, finalizer); tree.pos = pos; return tree; }
public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { JCTry tree = new JCTry(body, catchers, finalizer); tree.pos = pos; return tree; }
@Override public void visitTry(JCTry node) { Try t = new Try(); t.rawBody(toTree(node.getBlock())); t.rawFinally(toTree(node.getFinallyBlock())); fillList(node.getCatches(), t.rawCatches()); set(node, t); }
@Override public void visitTry(JCTry node) { Try t = new Try(); t.rawBody(toTree(node.getBlock())); t.rawFinally(toTree(node.getFinallyBlock())); fillList(node.getCatches(), t.rawCatches()); set(node, t); }
} else if (currentNode instanceof JCTry) { JCTry tryNode = (JCTry) currentNode; collectExecutionPaths(tryNode.getBlock(), allExecutionPaths, currentPaths, activeBreaks); JCStatement[] catchForks = (JCStatement[]) tryNode.getCatches().stream().map(catchExp -> catchExp.body) .collect(toList()).toArray(new JCStatement[0]); if (tryNode.getFinallyBlock() != null) { collectExecutionPaths(tryNode.getFinallyBlock(), allExecutionPaths, currentPathForksList, activeBreaks);
private static JCTry enclosingTry(VisitorState state) { Tree prev = null; for (Tree parent : state.getPath()) { switch (parent.getKind()) { case METHOD: case LAMBDA_EXPRESSION: return null; case TRY: JCTry tryStatement = (JCTry) parent; return tryStatement.getBlock().equals(prev) ? tryStatement : null; default: // fall out } prev = parent; } return null; } }