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

The following examples show how to use com.github.javaparser.ast.stmt.ThrowStmt. 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: RuleUnitContainerGenerator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private MethodDeclaration genericFactoryById() {
    ClassOrInterfaceType returnType = new ClassOrInterfaceType(null, RuleUnit.class.getCanonicalName())
            .setTypeArguments(new WildcardType());

    SwitchStmt switchStmt = new SwitchStmt();
    switchStmt.setSelector(new NameExpr("fqcn"));

    for (RuleUnitGenerator ruleUnit : ruleUnits) {
        SwitchEntry switchEntry = new SwitchEntry();
        switchEntry.getLabels().add(new StringLiteralExpr(ruleUnit.getRuleUnitDescription().getCanonicalName()));
        ObjectCreationExpr ruleUnitConstructor = new ObjectCreationExpr()
                .setType(ruleUnit.targetCanonicalName())
                .addArgument("application");
        switchEntry.getStatements().add(new ReturnStmt(ruleUnitConstructor));
        switchStmt.getEntries().add(switchEntry);
    }

    SwitchEntry defaultEntry = new SwitchEntry();
    defaultEntry.getStatements().add(new ThrowStmt(new ObjectCreationExpr().setType(UnsupportedOperationException.class.getCanonicalName())));
    switchStmt.getEntries().add(defaultEntry);

    return new MethodDeclaration()
            .addModifier(Modifier.Keyword.PROTECTED)
            .setType(returnType)
            .setName("create")
            .addParameter(String.class, "fqcn")
            .setBody(new BlockStmt().addStatement(switchStmt));
}
 
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 ThrowStmt n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print("throw ");
    n.getExpression().accept(this, arg);
    printer.print(";");
}
 
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(ThrowStmt n, Void arg) {
    super.visit(n, arg);

    if (currentMethod != null) {
        exceptionCount++;
    }
}
 
Example #5
Source File: ThrowStmtMerger.java    From dolphin with Apache License 2.0 4 votes vote down vote up
@Override public ThrowStmt doMerge(ThrowStmt first, ThrowStmt second) {
  ThrowStmt ts = new ThrowStmt();
  ts.setExpr(mergeSingle(first.getExpr(),second.getExpr()));
  return ts;
}
 
Example #6
Source File: ThrowStmtMerger.java    From dolphin with Apache License 2.0 4 votes vote down vote up
@Override public boolean doIsEquals(ThrowStmt first, ThrowStmt second) {
  if(!isEqualsUseMerger(first.getExpr(),second.getExpr())) return false;
  return true;
}
 
Example #7
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ThrowStmt n, Void arg) {
    out.println("ThrowStmt: " + (extended ? n : n.getExpression()));
    super.visit(n, arg);
}