public void testJSDocAttachment4() {
   AstRoot root = parse("(function() {/** should not be attached */})()");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   FunctionCall fc = (FunctionCall) st.getExpression();
   ParenthesizedExpression pe = (ParenthesizedExpression) fc.getTarget();
   assertNull(pe.getJsDoc());
 }
 public void testJSDocAttachment13() {
   AstRoot root = parse("({/** attach me */ get 'foo'() {}});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   StringLiteral stringLit = (StringLiteral) lit.getElements().get(0).getLeft();
   assertNotNull(stringLit.getJsDoc());
 }
 public void testJSDocAttachment10() {
   AstRoot root = parse("({foo: /** attach me */ (bar)});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   ParenthesizedExpression parens = (ParenthesizedExpression) lit.getElements().get(0).getRight();
   assertNotNull(parens.getJsDoc());
 }
 public void testJSDocAttachment9() {
   AstRoot root = parse("({/** attach me */ foo: 2});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   Name objLitKey = (Name) lit.getElements().get(0).getLeft();
   assertNotNull(objLitKey.getJsDoc());
 }
 public void testJSDocAttachment6() {
   AstRoot root = parse("({1: /** don't attach me */ 2, 3: 4});");
   assertNotNull(root.getComments());
   assertEquals(1, root.getComments().size());
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   ParenthesizedExpression pt = (ParenthesizedExpression) st.getExpression();
   ObjectLiteral lit = (ObjectLiteral) pt.getExpression();
   for (ObjectProperty el : lit.getElements()) {
     assertNull(el.getLeft().getJsDoc());
     assertNull(el.getRight().getJsDoc());
   }
 }
  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());
  }
 @Override
 public AstNode paren(AstNode expr) {
   ParenthesizedExpression paren = new ParenthesizedExpression();
   paren.setExpression(expr);
   return paren;
 }
  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());
  }