예제 #1
0
  public void testLinenoMultilineEq() {
    AstRoot root =
        parse(
            "\nif\n"
                + "    (((a == \n"
                + "  3) && \n"
                + "  (b == 2)) || \n"
                + " (c == 1)) {\n"
                + "}\n");
    IfStatement ifStmt = (IfStatement) root.getFirstChild();
    InfixExpression orTest = (InfixExpression) ifStmt.getCondition();
    ParenthesizedExpression cTestParen = (ParenthesizedExpression) orTest.getRight();
    InfixExpression cTest = (InfixExpression) cTestParen.getExpression();
    ParenthesizedExpression andTestParen = (ParenthesizedExpression) orTest.getLeft();
    InfixExpression andTest = (InfixExpression) andTestParen.getExpression();
    AstNode aTest = andTest.getLeft();
    AstNode bTest = andTest.getRight();

    assertEquals(1, ifStmt.getLineno());
    assertEquals(2, orTest.getLineno());
    assertEquals(2, andTest.getLineno());
    assertEquals(2, aTest.getLineno());
    assertEquals(4, bTest.getLineno());
    assertEquals(5, cTest.getLineno());
    assertEquals(5, cTestParen.getLineno());
    assertEquals(2, andTestParen.getLineno());
  }
예제 #2
0
  public void testLinenoMultilineBitTest() {
    AstRoot root =
        parse(
            "\nif (\n"
                + "      ((a \n"
                + "        | 3 \n"
                + "       ) == \n"
                + "       (b \n"
                + "        & 2)) && \n"
                + "      ((a \n"
                + "         ^ 0xffff) \n"
                + "       != \n"
                + "       (c \n"
                + "        << 1))) {\n"
                + "}\n");

    IfStatement ifStmt = (IfStatement) root.getFirstChild();
    InfixExpression andTest = (InfixExpression) ifStmt.getCondition();
    ParenthesizedExpression bigLHSExpr = (ParenthesizedExpression) andTest.getLeft();
    ParenthesizedExpression bigRHSExpr = (ParenthesizedExpression) andTest.getRight();

    InfixExpression eqTest = (InfixExpression) bigLHSExpr.getExpression();
    InfixExpression notEqTest = (InfixExpression) bigRHSExpr.getExpression();

    ParenthesizedExpression test1Expr = (ParenthesizedExpression) eqTest.getLeft();
    ParenthesizedExpression test2Expr = (ParenthesizedExpression) eqTest.getRight();

    ParenthesizedExpression test3Expr = (ParenthesizedExpression) notEqTest.getLeft();
    ParenthesizedExpression test4Expr = (ParenthesizedExpression) notEqTest.getRight();

    InfixExpression bitOrTest = (InfixExpression) test1Expr.getExpression();
    InfixExpression bitAndTest = (InfixExpression) test2Expr.getExpression();
    InfixExpression bitXorTest = (InfixExpression) test3Expr.getExpression();
    InfixExpression bitShiftTest = (InfixExpression) test4Expr.getExpression();

    assertEquals(1, ifStmt.getLineno());

    assertEquals(2, bigLHSExpr.getLineno());
    assertEquals(7, bigRHSExpr.getLineno());
    assertEquals(2, eqTest.getLineno());
    assertEquals(7, notEqTest.getLineno());

    assertEquals(2, test1Expr.getLineno());
    assertEquals(5, test2Expr.getLineno());
    assertEquals(7, test3Expr.getLineno());
    assertEquals(10, test4Expr.getLineno());

    assertEquals(2, bitOrTest.getLineno());
    assertEquals(5, bitAndTest.getLineno());
    assertEquals(7, bitXorTest.getLineno());
    assertEquals(10, bitShiftTest.getLineno());
  }