コード例 #1
0
  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());
  }
コード例 #2
0
 @Override
 public AstNode tryStatement(
     AstNode tryBlock, Iterable<AstNode> catchClauses, AstNode finallyBlock) {
   TryStatement t = new TryStatement();
   t.setTryBlock(tryBlock);
   for (AstNode c : catchClauses) {
     t.addCatchClause((CatchClause) c);
   }
   t.setFinallyBlock(finallyBlock);
   return t;
 }
コード例 #3
0
  public void testTryWithoutCatchLocation() {
    AstNode root =
        parse("\ntry {\n" + "  var x = 1;\n" + "} finally {\n" + "  var y = 2;\n" + "}\n");

    TryStatement tryStmt = (TryStatement) root.getFirstChild();
    AstNode tryBlock = tryStmt.getTryBlock();
    List<CatchClause> catchBlocks = tryStmt.getCatchClauses();
    Scope finallyBlock = (Scope) tryStmt.getFinallyBlock();
    AstNode finallyStmt = (AstNode) finallyBlock.getFirstChild();

    assertEquals(1, tryStmt.getLineno());
    assertEquals(1, tryBlock.getLineno());
    assertEquals(3, finallyBlock.getLineno());
    assertEquals(4, finallyStmt.getLineno());
  }
コード例 #4
0
  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());
  }