use of com.github.javaparser.ast.stmt.CatchClause in project javaparser by javaparser.
the class JavaParserFacadeResolutionTest method solveMultiCatchType.
@Test
public void solveMultiCatchType() {
String code = "class A {\n" + " public void foo() {\n" + " try {\n" + " \n" + " } catch (IllegalStateException | IllegalArgumentException e) {\n" + " \n" + " }\n" + " }\n" + " }";
CompilationUnit cu = parseWithTypeSolver(code);
CatchClause catchClause = Navigator.findNodeOfGivenClass(cu, CatchClause.class);
Type jpType = catchClause.getParameter().getType();
ResolvedType jssType = jpType.resolve();
assertEquals(true, jssType instanceof ResolvedUnionType);
}
use of com.github.javaparser.ast.stmt.CatchClause in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(final TryStmt n, final Object 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(") ");
}
n.getTryBlock().accept(this, arg);
if (n.getCatchs() != null) {
for (final CatchClause c : n.getCatchs()) {
c.accept(this, arg);
}
}
if (n.getFinallyBlock() != null) {
printer.print(" finally ");
n.getFinallyBlock().accept(this, arg);
}
}
use of com.github.javaparser.ast.stmt.CatchClause in project javaparser by javaparser.
the class VoidVisitorAdapter method visit.
@Override
public void visit(final TryStmt n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getResources() != null) {
for (final VariableDeclarationExpr v : n.getResources()) {
v.accept(this, arg);
}
}
n.getTryBlock().accept(this, arg);
if (n.getCatchs() != null) {
for (final CatchClause c : n.getCatchs()) {
c.accept(this, arg);
}
}
if (n.getFinallyBlock() != null) {
n.getFinallyBlock().accept(this, arg);
}
}
Aggregations