List of usage examples for org.eclipse.jdt.core.dom TryStatement getBody
public Block getBody()
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$ }//from w ww . j a v a 2s. c om } 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);// ww w . j a va 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:br.uff.ic.gems.resources.ast.Visitor.java
@Override public boolean visit(TryStatement node) { int beginLine = cu.getLineNumber(node.getStartPosition()); int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength()); int beginColumn = cu.getColumnNumber(node.getStartPosition()); int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength()); Block body = node.getBody(); if (body != null) { int beginLineBody = cu.getLineNumber(body.getStartPosition()); int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength()); int beginColumnBody = cu.getColumnNumber(body.getStartPosition()); int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength()); languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null)); } else {/* w ww.j a v a2 s .co m*/ languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn)); } return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.emptycode.EmptyFinallyBlockQuickFix.java
License:Open Source License
/** * Removes the finally block. Additionally removes the try if there are no catch blocks while keeping the try block * statements./* w w w. j a va 2 s.c o m*/ */ @Override protected boolean apply(final TryStatement node) { boolean success = true; if (node.catchClauses().isEmpty()) { @SuppressWarnings("unchecked") final List<Statement> statements = node.getBody().statements(); if (replace(node, copy(statements))) { node.delete(); } else { success = false; } } else { node.setFinally(null); } return success; }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(TryStatement node) { if (this.mtbStack.isEmpty()) { return true; }/* w w w.j a va 2 s . c om*/ 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//from ww w .j av a 2 s . c om 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();/*w w w . j a v a 2 s . 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.SpacePreparator.java
License:Open Source License
@Override public boolean visit(TryStatement node) { List<VariableDeclarationExpression> resources = node.resources(); if (!resources.isEmpty()) { handleToken(node, TokenNameLPAREN, this.options.insert_space_before_opening_paren_in_try, this.options.insert_space_after_opening_paren_in_try); handleTokenBefore(node.getBody(), TokenNameRPAREN, this.options.insert_space_before_closing_paren_in_try, false); for (int i = 1; i < resources.size(); i++) { handleTokenBefore(resources.get(i), TokenNameSEMICOLON, this.options.insert_space_before_semicolon_in_try_resources, this.options.insert_space_after_semicolon_in_try_resources); }/*w w w . ja v a 2 s . com*/ // there can be a semicolon after the last resource int index = this.tm.firstIndexAfter(resources.get(resources.size() - 1), -1); while (index < this.tm.size()) { Token token = this.tm.get(index++); if (token.tokenType == TokenNameSEMICOLON) { handleToken(token, this.options.insert_space_before_semicolon_in_try_resources, false); } else if (token.tokenType == TokenNameRPAREN) { break; } } } 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 w ww. j a v 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); }//from ww w . j ava 2s . c o m if (node.getFinally() != null) { buffer.append(" @finally "); node.getFinally().accept(this); } return false; }