List of usage examples for org.eclipse.jdt.core.dom TryStatement catchClauses
ASTNode.NodeList catchClauses
To view the source code for org.eclipse.jdt.core.dom TryStatement catchClauses.
Click Source Link
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 .j ava 2 s .c o m*/ } 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);//from w ww. j a v a2 s .c o 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:ca.uvic.chisel.diver.sequencediagrams.sc.java.model.JavaMessage.java
License:Open Source License
/** * Returns true if this message was passed within a try block that catches the given * type.//from w ww. ja v a2 s . co m * @param type * @return */ public boolean catches(IType type) { if (tries == null) { return false; } for (TryStatement statement : tries) { for (Object o : statement.catchClauses()) { CatchClause catcher = (CatchClause) o; ITypeBinding binding = catcher.getException().getType().resolveBinding(); if (binding != null) { IType caughtType = (IType) binding.getJavaElement(); if (caughtType != null) { try { ITypeHierarchy hierarchy = caughtType.newSupertypeHierarchy(new NullProgressMonitor()); if (caughtType.equals(type) || hierarchy.contains(type)) { return true; } } catch (JavaModelException e) { } } } } } return false; }
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./*from w ww . ja va 2s . 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; }// www .j a va 2 s . 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// www . ja va 2 s .com 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();// ww w . jav a2 s . c om 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.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 w w.j av a 2s .com 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 w w w . ja va2 s . co m*/ if (node.getFinally() != null) { buffer.append(" @finally "); node.getFinally().accept(this); } return false; }
From source file:com.google.devtools.j2objc.util.ASTUtil.java
License:Apache License
@SuppressWarnings("unchecked") public static List<CatchClause> getCatchClauses(TryStatement node) { return node.catchClauses(); }