Exemplo n.º 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());
  }
Exemplo n.º 2
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());
  }
Exemplo n.º 3
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());
  }