Search in sources :

Example 1 with CopyState

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);
}
Also used : SourceLocation(com.google.template.soy.base.SourceLocation) IntegerNode(com.google.template.soy.exprtree.IntegerNode) FunctionNode(com.google.template.soy.exprtree.FunctionNode) CopyState(com.google.template.soy.basetree.CopyState) PrintNode(com.google.template.soy.soytree.PrintNode) NullNode(com.google.template.soy.exprtree.NullNode) HtmlOpenTagNode(com.google.template.soy.soytree.HtmlOpenTagNode)

Example 2 with CopyState

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());
    }
}
Also used : CopyState(com.google.template.soy.basetree.CopyState) Test(org.junit.Test)

Example 3 with CopyState

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());
}
Also used : CopyState(com.google.template.soy.basetree.CopyState) SoyFileNode(com.google.template.soy.soytree.SoyFileNode)

Example 4 with CopyState

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());
}
Also used : CopyState(com.google.template.soy.basetree.CopyState) IncrementingIdGenerator(com.google.template.soy.base.internal.IncrementingIdGenerator) SoyFileNode(com.google.template.soy.soytree.SoyFileNode)

Example 5 with CopyState

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)");
}
Also used : NegativeOpNode(com.google.template.soy.exprtree.OperatorNodes.NegativeOpNode) MinusOpNode(com.google.template.soy.exprtree.OperatorNodes.MinusOpNode) CopyState(com.google.template.soy.basetree.CopyState) Test(org.junit.Test)

Aggregations

CopyState (com.google.template.soy.basetree.CopyState)9 Test (org.junit.Test)5 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)1 SourceLocation (com.google.template.soy.base.SourceLocation)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 FunctionNode (com.google.template.soy.exprtree.FunctionNode)1 IntegerNode (com.google.template.soy.exprtree.IntegerNode)1 NullNode (com.google.template.soy.exprtree.NullNode)1 ConditionalOpNode (com.google.template.soy.exprtree.OperatorNodes.ConditionalOpNode)1 MinusOpNode (com.google.template.soy.exprtree.OperatorNodes.MinusOpNode)1 NegativeOpNode (com.google.template.soy.exprtree.OperatorNodes.NegativeOpNode)1 NotEqualOpNode (com.google.template.soy.exprtree.OperatorNodes.NotEqualOpNode)1 NotOpNode (com.google.template.soy.exprtree.OperatorNodes.NotOpNode)1 TimesOpNode (com.google.template.soy.exprtree.OperatorNodes.TimesOpNode)1 VarDefn (com.google.template.soy.exprtree.VarDefn)1 VarRefNode (com.google.template.soy.exprtree.VarRefNode)1 JsSrcMain (com.google.template.soy.jssrc.internal.JsSrcMain)1 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)1 SoyMsgBundleHandler (com.google.template.soy.msgs.SoyMsgBundleHandler)1