com.github.javaparser.ast.stmt.CatchClause Java Examples

The following examples show how to use com.github.javaparser.ast.stmt.CatchClause. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryEndpointGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private BlockStmt wrapBodyAddingExceptionLogging(BlockStmt body, String nameURL) {
    TryStmt ts = new TryStmt();
    ts.setTryBlock(body);
    CatchClause cc = new CatchClause();
    String exceptionName = "e";
    cc.setParameter(new Parameter().setName(exceptionName).setType(Exception.class));
    BlockStmt cb = new BlockStmt();
    cb.addStatement(parseStatement(
            String.format(
                    "SystemMetricsCollector.registerException(\"%s\", %s.getStackTrace()[0].toString());",
                    nameURL,
                    exceptionName)
    ));
    cb.addStatement(new ThrowStmt(new NameExpr(exceptionName)));
    cc.setBody(cb);
    ts.setCatchClauses(new NodeList<>(cc));
    return new BlockStmt(new NodeList<>(ts));
}
 
Example #2
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void visit(final TryStmt n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print("try ");
    if (!n.getResources().isEmpty()) {
        printer.print("(");
        Iterator<VariableDeclarationExpr> resources = n.getResources().iterator();
        boolean first = true;
        while (resources.hasNext()) {
            visit(resources.next(), arg);
            if (resources.hasNext()) {
                printer.print(";");
                printer.println();
                if (first) {
                    printer.indent();
                }
            }
            first = false;
        }
        if (n.getResources().size() > 1) {
            printer.unindent();
        }
        printer.print(") ");
    }
    if (n.getTryBlock().isPresent()) {
        n.getTryBlock().get().accept(this, arg);
    }
    for (final CatchClause c : n.getCatchClauses()) {
        c.accept(this, arg);
    }
    if (n.getFinallyBlock().isPresent()) {
        printer.print(" finally ");
        n.getFinallyBlock().get().accept(this, arg);
    }
}
 
Example #3
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void visit(final CatchClause n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print(" catch (");
    n.getParameter().accept(this, arg);
    printer.print(") ");
    n.getBody().accept(this, arg);
}
 
Example #4
Source File: ExceptionCatchingThrowing.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(CatchClause n, Void arg) {
    super.visit(n, arg);

    if (currentMethod != null) {
        exceptionCount++;
    }
}
 
Example #5
Source File: CatchClauseMerger.java    From dolphin with Apache License 2.0 4 votes vote down vote up
@Override public CatchClause doMerge(CatchClause first, CatchClause second) {
  CatchClause cc = new CatchClause();
  cc.setCatchBlock(mergeSingle(first.getCatchBlock(),second.getCatchBlock()));
  cc.setExcept(mergeSingle(first.getExcept(),second.getExcept()));
  return cc;
}
 
Example #6
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(CatchClause n, Void arg) {
    out.println("CatchClause: " + (extended ? n : n.getParameter()));
    super.visit(n, arg);
}
 
Example #7
Source File: CatchClauseMerger.java    From dolphin with Apache License 2.0 3 votes vote down vote up
@Override public boolean doIsEquals(CatchClause first, CatchClause second) {

    if(!isEqualsUseMerger(first.getExcept(),second.getExcept())) return false;
    if(!isEqualsUseMerger(first.getCatchBlock(),second.getCatchBlock())) return false;

    return true;
  }