public void testLinenoTry() { AstRoot root = parse( "\ntry {\n" + " var x = 1;\n" + "} catch\n" + " (err)\n" + "{\n" + "} finally {\n" + " var y = 2;\n" + "}\n"); TryStatement tryStmt = (TryStatement) root.getFirstChild(); AstNode tryBlock = tryStmt.getTryBlock(); List<CatchClause> catchBlocks = tryStmt.getCatchClauses(); CatchClause catchClause = catchBlocks.get(0); Block catchVarBlock = catchClause.getBody(); Name catchVar = catchClause.getVarName(); AstNode finallyBlock = tryStmt.getFinallyBlock(); AstNode finallyStmt = (AstNode) finallyBlock.getFirstChild(); assertEquals(1, tryStmt.getLineno()); assertEquals(1, tryBlock.getLineno()); assertEquals(5, catchVarBlock.getLineno()); assertEquals(4, catchVar.getLineno()); assertEquals(3, catchClause.getLineno()); assertEquals(6, finallyBlock.getLineno()); assertEquals(7, finallyStmt.getLineno()); }
/* * @see ASTVisitor#visit(TryStatement) */ @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$ } } 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; }
/* * @see ASTVisitor#visit(CatchClause) */ @Override public boolean visit(CatchClause node) { this.fBuffer.append("catch ("); // $NON-NLS-1$ node.getException().accept(this); this.fBuffer.append(") "); // $NON-NLS-1$ node.getBody().accept(this); return false; }
public void visit(TryStmt n, Object arg) { n.getTryBlock().accept(this, arg); if (n.getCatchs() != null) { for (CatchClause c : n.getCatchs()) { c.accept(this, arg); } } if (n.getFinallyBlock() != null) { n.getFinallyBlock().accept(this, arg); } }
public boolean visit(CatchClause catchClause) throws Exception { ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo(); info.modifiers = Modifiers.AccPublic; SimpleReference var = catchClause.getVariable(); info.name = var.getName(); info.nameSourceEnd = var.sourceEnd() - 1; info.nameSourceStart = var.sourceStart(); info.declarationStart = catchClause.sourceStart(); fInfoStack.push(info); fRequestor.enterField(info); return true; }
@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); } }
public void testTryWithoutFinallyLocation() { AstNode root = parse("\ntry {\n" + " var x = 1;\n" + "} catch (ex) {\n" + " var y = 2;\n" + "}\n"); TryStatement tryStmt = (TryStatement) root.getFirstChild(); Scope tryBlock = (Scope) tryStmt.getTryBlock(); List<CatchClause> catchBlocks = tryStmt.getCatchClauses(); CatchClause catchClause = catchBlocks.get(0); AstNode catchStmt = catchClause.getBody(); AstNode exceptionVar = catchClause.getVarName(); AstNode varDecl = (AstNode) catchStmt.getFirstChild(); assertEquals(1, tryStmt.getLineno()); assertEquals(1, tryBlock.getLineno()); assertEquals(3, catchClause.getLineno()); assertEquals(3, catchStmt.getLineno()); assertEquals(3, exceptionVar.getLineno()); assertEquals(4, varDecl.getLineno()); }
@Override public Void visitCatchClause(CatchClause node) { visit("on ", node.getExceptionType()); if (node.getCatchKeyword() != null) { if (node.getExceptionType() != null) { writer.print(' '); } writer.print("catch ("); visit(node.getExceptionParameter()); visit(", ", node.getStackTraceParameter()); writer.print(") "); } else { writer.print(" "); } visit(node.getBody()); return null; }
public void visit(CatchClause n, Object arg) { n.getExcept().accept(this, arg); n.getCatchBlock().accept(this, arg); }
@Override public void visit(final CatchClause n, final A arg) { visitComment(n.getComment(), arg); n.getParam().accept(this, arg); n.getBody().accept(this, arg); }
public boolean endvisit(CatchClause catchClause) throws Exception { fRequestor.exitField(catchClause.sourceEnd() - 1); fInfoStack.pop(); return true; }