예제 #1
0
  public void testLinenoInfix() {
    AstRoot root =
        parse(
            "\nvar d = a\n"
                + "    + \n"
                + "    b;\n"
                + "var\n"
                + "    e =\n"
                + "    a +\n"
                + "    c;\n"
                + "var f = b\n"
                + "    / c;\n");

    VariableDeclaration stmt1 = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars1 = stmt1.getVariables();
    VariableInitializer var1 = vars1.get(0);
    Name firstVarName = (Name) var1.getTarget();
    InfixExpression var1Add = (InfixExpression) var1.getInitializer();

    VariableDeclaration stmt2 = (VariableDeclaration) stmt1.getNext();
    List<VariableInitializer> vars2 = stmt2.getVariables();
    VariableInitializer var2 = vars2.get(0);
    Name secondVarName = (Name) var2.getTarget();
    InfixExpression var2Add = (InfixExpression) var2.getInitializer();

    VariableDeclaration stmt3 = (VariableDeclaration) stmt2.getNext();
    List<VariableInitializer> vars3 = stmt3.getVariables();
    VariableInitializer var3 = vars3.get(0);
    Name thirdVarName = (Name) var3.getTarget();
    InfixExpression thirdVarDiv = (InfixExpression) var3.getInitializer();

    ReturnStatement returnStmt = (ReturnStatement) stmt3.getNext();

    assertEquals(1, var1.getLineno());
    assertEquals(1, firstVarName.getLineno());
    assertEquals(1, var1Add.getLineno());
    assertEquals(1, var1Add.getLeft().getLineno());
    assertEquals(3, var1Add.getRight().getLineno());

    // var directive with name on next line wrong --
    // should be 6.
    assertEquals(5, var2.getLineno());
    assertEquals(5, secondVarName.getLineno());
    assertEquals(6, var2Add.getLineno());
    assertEquals(6, var2Add.getLeft().getLineno());
    assertEquals(7, var2Add.getRight().getLineno());

    assertEquals(8, var3.getLineno());
    assertEquals(8, thirdVarName.getLineno());
    assertEquals(8, thirdVarDiv.getLineno());
    assertEquals(8, thirdVarDiv.getLeft().getLineno());
    assertEquals(9, thirdVarDiv.getRight().getLineno());
  }
예제 #2
0
  public void testLinenoVarDecl() {
    AstRoot root = parse("\nvar\n" + "    a =\n" + "    3\n");

    VariableDeclaration decl = (VariableDeclaration) root.getFirstChild();
    List<VariableInitializer> vars = decl.getVariables();
    VariableInitializer init = vars.get(0);
    AstNode declName = init.getTarget();
    AstNode expr = init.getInitializer();

    assertEquals(1, decl.getLineno());
    assertEquals(2, init.getLineno());
    assertEquals(2, declName.getLineno());
    assertEquals(3, expr.getLineno());
  }