Java Code Examples for com.github.javaparser.ast.stmt.TryStmt#setTryBlock()

The following examples show how to use com.github.javaparser.ast.stmt.TryStmt#setTryBlock() . 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: TryStmtMerger.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override public TryStmt doMerge(TryStmt first, TryStmt second) {
  TryStmt ts = new TryStmt();
  ts.setResources(mergeCollectionsInOrder(first.getResources(),second.getResources()));
  ts.setCatchs(mergeCollectionsInOrder(first.getCatchs(),second.getCatchs()));
  ts.setTryBlock(mergeSingle(first.getTryBlock(),second.getTryBlock()));
  ts.setFinallyBlock(mergeSingle(first.getFinallyBlock(),second.getFinallyBlock()));
  return ts;
}