List of usage examples for org.eclipse.jdt.core.dom TryStatement getFinally
public Block getFinally()
null if this try statement has no finally block. From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(TryStatement node) { this.fBuffer.append("try ");//$NON-NLS-1$ if (node.getAST().apiLevel() >= JLS4) { if (!node.resources().isEmpty()) { this.fBuffer.append("(");//$NON-NLS-1$ for (Iterator<VariableDeclarationExpression> it = node.resources().iterator(); it.hasNext();) { VariableDeclarationExpression var = it.next(); var.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ }/* w w w. ja v a2 s. com*/ } this.fBuffer.append(") ");//$NON-NLS-1$ } } node.getBody().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ for (Iterator<CatchClause> it = node.catchClauses().iterator(); it.hasNext();) { CatchClause cc = it.next(); cc.accept(this); } if (node.getFinally() != null) { this.fBuffer.append("finally ");//$NON-NLS-1$ node.getFinally().accept(this); } return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(TryStatement node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.TRY); statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (Object c : node.catchClauses()) ((CatchClause) c).accept(this); if (node.getFinally() != null) node.getFinally().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s);/*w ww . ja v a 2s.co m*/ if (node.resources() != null) for (Object v : node.resources()) { ((VariableDeclarationExpression) v).accept(this); b.addInitializations(expressions.pop()); } list.add(b.build()); return false; }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(TryStatement node) { if (this.mtbStack.isEmpty()) { return true; }/* w ww. ja va 2s . co m*/ String bodyStr = node.getBody() != null ? node.getBody().toString() : ""; bodyStr = edit_str(bodyStr); StringBuilder catchClauses = new StringBuilder(); for (Object o : node.catchClauses()) { if (catchClauses.length() > 0) { catchClauses.append(","); } CatchClause c = (CatchClause) o; catchClauses.append(getQualifiedName(c.getException().getType().resolveBinding())); catchClauses.append(":"); if (c.getBody() != null) { catchClauses.append(edit_str(c.getBody().toString())); } } String finallyStr = node.getFinally() != null ? node.getFinally().toString() : ""; finallyStr = edit_str(finallyStr); IMethodBinding mtb = (IMethodBinding) this.mtbStack.peek(); String methodStr = getQualifiedName(mtb); this.facts.add(Fact.makeTryCatchFact(bodyStr, catchClauses.toString(), finallyStr, methodStr)); return true; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w ww . j a v a 2 s . c o m*/ public boolean visit(TryStatement node) { pushNode(node, ""); Statement stmt = node.getBody(); pushNode(stmt, ""); stmt.accept(this); popNode(); visitListAsNode(EntityType.CATCH_CLAUSES, node.catchClauses()); stmt = node.getFinally(); if (stmt != null) { // @Inria pushNode(stmt, ""); stmt.accept(this); popNode(); } return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(TryStatement node) { printIndent();/*from w ww .ja va 2s .c o m*/ this.buffer.append("try ");//$NON-NLS-1$ node.getBody().accept(this); this.buffer.append(" ");//$NON-NLS-1$ for (Iterator it = node.catchClauses().iterator(); it.hasNext();) { CatchClause cc = (CatchClause) it.next(); cc.accept(this); } if (node.getFinally() != null) { this.buffer.append(" finally ");//$NON-NLS-1$ node.getFinally().accept(this); } return false; }
From source file:com.bsiag.eclipse.jdt.java.formatter.LineBreaksPreparator.java
License:Open Source License
@Override public boolean visit(TryStatement node) { if (node.getFinally() != null && this.options.insert_new_line_before_finally_in_try_statement) { this.tm.firstTokenBefore(node.getFinally(), TokenNamefinally).breakBefore(); }//w w w . j av a2 s.c o m return true; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.TryStatement node) { List<CatchClause> catchClauses = Lists.newArrayList(); for (Iterator<?> I = node.catchClauses().iterator(); I.hasNext();) { org.eclipse.jdt.core.dom.CatchClause javaCatch = (org.eclipse.jdt.core.dom.CatchClause) I.next(); catchClauses.add((CatchClause) translate(javaCatch)); }//from ww w. j av a 2 s . c o m return done(tryStatement((Block) translate(node.getBody()), catchClauses, (Block) translate(node.getFinally()))); }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(TryStatement node) { buffer.append("@try "); node.getBody().accept(this); buffer.append(' '); for (Iterator<?> it = node.catchClauses().iterator(); it.hasNext();) { CatchClause cc = (CatchClause) it.next(); cc.accept(this); }// w w w .jav a 2s . co m if (node.getFinally() != null) { buffer.append(" @finally "); node.getFinally().accept(this); } return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(TryStatement node) { sb.printIndent();// w w w . j av a 2s . co m sb.print("try "); List<VariableDeclarationExpression> resources = node.getResources(); if (!resources.isEmpty()) { sb.print('('); for (Iterator<VariableDeclarationExpression> it = resources.iterator(); it.hasNext();) { it.next().accept(this); if (it.hasNext()) { sb.print(';'); } } sb.print(')'); } node.getBody().accept(this); sb.print(' '); for (Iterator<CatchClause> it = node.getCatchClauses().iterator(); it.hasNext();) { it.next().accept(this); } if (node.getFinally() != null) { sb.print(" finally "); node.getFinally().accept(this); } return false; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link TryStatement}s. */ @Override/* ww w .j a va 2 s . com*/ public boolean visit(TryStatement node) { sync(node); builder.open(ZERO); token("try"); builder.space(); if (!node.resources().isEmpty()) { token("("); builder.open(plusFour); boolean first = true; for (VariableDeclarationExpression resource : (List<VariableDeclarationExpression>) node.resources()) { if (!first) { token(";"); builder.forcedBreak(); } visit(resource); first = false; } // TODO(cushon): emit a space after the optional trailing semi-colon builder.guessToken(";"); token(")"); builder.close(); builder.space(); } // An empty try-with-resources body can collapse to "{}" if there are no trailing catch or // finally blocks. boolean trailingClauses = !node.catchClauses().isEmpty() || node.getFinally() != null; visitBlock(node.getBody(), CollapseEmptyOrNot.valueOf(!trailingClauses), AllowLeadingBlankLine.YES, AllowTrailingBlankLine.valueOf(trailingClauses)); for (int i = 0; i < node.catchClauses().size(); i++) { CatchClause catchClause = (CatchClause) node.catchClauses().get(i); trailingClauses = i < node.catchClauses().size() - 1 || node.getFinally() != null; visitCatchClause(catchClause, AllowTrailingBlankLine.valueOf(trailingClauses)); } if (node.getFinally() != null) { builder.space(); token("finally"); builder.space(); visitBlock(node.getFinally(), CollapseEmptyOrNot.NO, AllowLeadingBlankLine.YES, AllowTrailingBlankLine.NO); } builder.close(); return false; }