use of com.google.template.soy.basetree.CopyState in project closure-templates by google.
the class VeLogInstrumentationVisitor method visitVeLogNode.
/**
* Adds data-soylog attribute to the top-level DOM node in this {velog} block.
*/
@Override
protected void visitVeLogNode(VeLogNode node) {
// VeLogValidationPass enforces that the first child is a open tag. We can safely cast it here.
HtmlOpenTagNode tag = (HtmlOpenTagNode) node.getChild(0);
SourceLocation insertionLocation = tag.getSourceLocation().getEndPoint().offset(0, tag.isSelfClosing() ? -2 : -1).asLocation(tag.getSourceLocation().getFilePath());
FunctionNode funcNode = new FunctionNode(VeLogFunction.INSTANCE, insertionLocation);
funcNode.addChild(new IntegerNode(node.getLoggingId(), insertionLocation));
funcNode.addChild(node.getConfigExpression() == null ? new NullNode(insertionLocation) : node.getConfigExpression().copy(new CopyState()));
if (node.getLogonlyExpression() != null) {
funcNode.addChild(node.getLogonlyExpression().copy(new CopyState()));
}
PrintNode attributeNode = new PrintNode(nodeIdGen.genId(), insertionLocation, /* isImplicit= */
true, /* expr= */
funcNode, /* attributes= */
ImmutableList.of(), ErrorReporter.exploding());
tag.addChild(attributeNode);
visitChildren(node);
}
use of com.google.template.soy.basetree.CopyState in project closure-templates by google.
the class SoyTreeUtilsTest method testMsgHtmlTagNode.
@Test
public final void testMsgHtmlTagNode() throws Exception {
SoyFileNode soyFile = SoyFileSetParserBuilder.forFileContents(SOY_SOURCE_FOR_TESTING_CLONING).parse().fileSet().getChild(0);
List<MsgHtmlTagNode> msgHtmlTagNodes = SoyTreeUtils.getAllNodesOfType(soyFile, MsgHtmlTagNode.class);
for (MsgHtmlTagNode origMsgHtmlTagNode : msgHtmlTagNodes) {
MsgHtmlTagNode clonedMsgHtmlTagNode = origMsgHtmlTagNode.copy(new CopyState());
assertEquals(clonedMsgHtmlTagNode.numChildren(), origMsgHtmlTagNode.numChildren());
assertEquals(clonedMsgHtmlTagNode.getId(), origMsgHtmlTagNode.getId());
assertEquals(clonedMsgHtmlTagNode.getLcTagName(), origMsgHtmlTagNode.getLcTagName());
}
}
use of com.google.template.soy.basetree.CopyState in project closure-templates by google.
the class HtmlRewritePassTest method assertThatASTString.
private static StringSubject assertThatASTString(TemplateNode node) {
SoyFileNode parent = node.getParent().copy(new CopyState());
new CombineConsecutiveRawTextNodesPass().run(parent);
return assertThat(SoyTreeUtils.buildAstString(parent.getChild(0), 0, new StringBuilder()).toString());
}
use of com.google.template.soy.basetree.CopyState in project closure-templates by google.
the class HtmlRewritePassTest method assertThatSourceString.
private static StringSubject assertThatSourceString(TemplateNode node) {
SoyFileNode parent = node.getParent().copy(new CopyState());
new DesugarHtmlNodesPass().run(parent, new IncrementingIdGenerator());
StringBuilder sb = new StringBuilder();
parent.getChild(0).appendSourceStringForChildren(sb);
return assertThat(sb.toString());
}
use of com.google.template.soy.basetree.CopyState in project closure-templates by google.
the class AbstractOperatorNodeTest method testToSourceString1.
@Test
public void testToSourceString1() {
// Test expression: $x - -$x - (-($x - $x) - $x)
//
// The expression tree looks like this:
// [MinusOpNode] n0
// [MinusOpNode] n1
// [VarRefNode] $x
// [NegativeOpNode] n3
// [VarRefNode] $x
// [MinusOpNode] n2
// [NegativeOpNode] n4
// [MinusOpNode] n5
// [VarRefNode] $x
// [VarRefNode] $x
// [VarRefNode] $x
// Root n0.
MinusOpNode n0 = new MinusOpNode(X);
// Children of n0.
MinusOpNode n1 = new MinusOpNode(X);
MinusOpNode n2 = new MinusOpNode(X);
n0.addChild(n1);
n0.addChild(n2);
// Children of n1.
NegativeOpNode n3 = new NegativeOpNode(X);
n1.addChild(x);
n1.addChild(n3);
// Child of n3.
n3.addChild(x.copy(new CopyState()));
// Children of n2.
NegativeOpNode n4 = new NegativeOpNode(X);
n2.addChild(n4);
n2.addChild(x.copy(new CopyState()));
// Child of n4.
MinusOpNode n5 = new MinusOpNode(X);
n4.addChild(n5);
// Children of n5.
n5.addChild(x.copy(new CopyState()));
n5.addChild(x.copy(new CopyState()));
assertThat(n0.toSourceString()).isEqualTo("$x - -$x - (-($x - $x) - $x)");
}
Aggregations