@Override
 public AstNode character(String c) {
   StringLiteral s = new StringLiteral();
   s.setQuoteCharacter('\'');
   s.setValue(c);
   return s;
 }
 @Override
 public AstNode string(String value) {
   StringLiteral expr = new StringLiteral();
   expr.setQuoteCharacter('"');
   expr.setValue(value);
   return expr;
 }
示例#3
0
 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());
 }
示例#4
0
  public boolean visit(AstNode node) {
    if (node instanceof AstRoot) return true;
    else {
      Tree t = buildTree(node);
      Tree p = trees.get(node.getParent());
      p.addChild(t);

      if (node instanceof Name) {
        Name name = (Name) node;
        t.setLabel(name.getIdentifier());
      } else if (node instanceof StringLiteral) {
        StringLiteral literal = (StringLiteral) node;
        t.setLabel(literal.getValue());
      } else if (node instanceof NumberLiteral) {
        NumberLiteral l = (NumberLiteral) node;
        t.setLabel(l.getValue());
      }

      return true;
    }
  }
示例#5
0
 public void testParseUnicodeFormatStringLiteral() {
   AstRoot root = parse("'A\u200DB'");
   ExpressionStatement st = (ExpressionStatement) root.getFirstChild();
   StringLiteral stringLit = (StringLiteral) st.getExpression();
   assertEquals("A\u200DB", stringLit.getValue());
 }