@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; }
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 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; } }
public void testParseUnicodeFormatStringLiteral() { AstRoot root = parse("'A\u200DB'"); ExpressionStatement st = (ExpressionStatement) root.getFirstChild(); StringLiteral stringLit = (StringLiteral) st.getExpression(); assertEquals("A\u200DB", stringLit.getValue()); }