use of org.mozilla.javascript.ast.XmlFragment in project HL4A by HL4A.
the class IRFactory method transformXmlLiteral.
private Node transformXmlLiteral(XmlLiteral node) {
// a literal like <foo>{bar}</foo> is rewritten as
// new XML("<foo>" + bar + "</foo>");
Node pnXML = new Node(Token.NEW, node.getLineno());
List<XmlFragment> frags = node.getFragments();
XmlString first = (XmlString) frags.get(0);
boolean anon = first.getXml().trim().startsWith("<>");
pnXML.addChildToBack(createName(anon ? "XMLList" : "XML"));
Node pn = null;
for (XmlFragment frag : frags) {
if (frag instanceof XmlString) {
String xml = ((XmlString) frag).getXml();
decompiler.addName(xml);
if (pn == null) {
pn = createString(xml);
} else {
pn = createBinary(Token.ADD, pn, createString(xml));
}
} else {
XmlExpression xexpr = (XmlExpression) frag;
boolean isXmlAttr = xexpr.isXmlAttribute();
Node expr;
decompiler.addToken(Token.LC);
if (xexpr.getExpression() instanceof EmptyExpression) {
expr = createString("");
} else {
expr = transform(xexpr.getExpression());
}
decompiler.addToken(Token.RC);
if (isXmlAttr) {
// Need to put the result in double quotes
expr = createUnary(Token.ESCXMLATTR, expr);
Node prepend = createBinary(Token.ADD, createString("\""), expr);
expr = createBinary(Token.ADD, prepend, createString("\""));
} else {
expr = createUnary(Token.ESCXMLTEXT, expr);
}
pn = createBinary(Token.ADD, pn, expr);
}
}
pnXML.addChildToBack(pn);
return pnXML;
}
Aggregations