use of com.github.javaparser.ast.stmt.TryStmt in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitTry.
@Override
public Void visitTry(TryTree javacTree, Node javaParserNode) {
TryStmt node = castNode(TryStmt.class, javaParserNode, javacTree);
processTry(javacTree, node);
Iterator<? extends Tree> javacResources = javacTree.getResources().iterator();
for (Expression resource : node.getResources()) {
if (resource.isVariableDeclarationExpr()) {
for (VariableDeclarator declarator : resource.asVariableDeclarationExpr().getVariables()) {
assert javacResources.hasNext();
javacResources.next().accept(this, declarator);
}
} else {
assert javacResources.hasNext();
javacResources.next().accept(this, resource);
}
}
javacTree.getBlock().accept(this, node.getTryBlock());
visitLists(javacTree.getCatches(), node.getCatchClauses());
visitOptional(javacTree.getFinallyBlock(), node.getFinallyBlock());
return null;
}
use of com.github.javaparser.ast.stmt.TryStmt in project checker-framework by typetools.
the class DoubleJavaParserVisitor method visit.
@Override
public void visit(final TryStmt node1, final Node other) {
TryStmt node2 = (TryStmt) other;
defaultAction(node1, node2);
visitLists(node1.getCatchClauses(), node2.getCatchClauses());
node1.getFinallyBlock().ifPresent(l -> l.accept(this, node2.getFinallyBlock().get()));
visitLists(node1.getResources(), node2.getResources());
node1.getTryBlock().accept(this, node2.getTryBlock());
}
use of com.github.javaparser.ast.stmt.TryStmt in project drools by kiegroup.
the class FunctionGenerator method toFunction.
public static MethodDeclaration toFunction(FunctionDescr desc) {
List<Parameter> parameters = new ArrayList<>();
List<String> parameterTypes = desc.getParameterTypes();
for (int i = 0; i < parameterTypes.size(); i++) {
String type = parameterTypes.get(i);
String name = desc.getParameterNames().get(i);
parameters.add(new Parameter(toClassOrInterfaceType(type), name));
}
NodeList<Modifier> modifiers = NodeList.nodeList(Modifier.publicModifier(), Modifier.staticModifier());
MethodDeclaration methodDeclaration = new MethodDeclaration(modifiers, desc.getName(), toClassOrInterfaceType(desc.getReturnType()), nodeList(parameters));
BlockStmt block = DrlxParseUtil.parseBlock("try {} catch (Exception e) { throw new RuntimeException(e); }");
TryStmt tryStmt = (TryStmt) block.getStatement(0);
tryStmt.setTryBlock(DrlxParseUtil.parseBlock(desc.getBody()));
methodDeclaration.setBody(block);
return methodDeclaration;
}
Aggregations