use of com.google.template.soy.exprtree.VarDefn in project closure-templates by google.
the class SoyTreeUtilsTest method testClone.
@Test
public final void testClone() throws Exception {
SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(SOY_SOURCE_FOR_TESTING_CLONING).declaredSyntaxVersion(SyntaxVersion.V2_4).parse().fileSet();
SoyFileSetNode clone = soyTree.copy(new CopyState());
assertEquals(1, clone.numChildren());
assertEquals(clone.getChild(0).toSourceString(), soyTree.getChild(0).toSourceString());
// All the localvarnodes, there is one of each type
ForNonemptyNode forNonemptyNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(clone, ForNonemptyNode.class));
LetValueNode letValueNode = Iterables.getOnlyElement(SoyTreeUtils.getAllNodesOfType(clone, LetValueNode.class));
for (VarRefNode varRef : SoyTreeUtils.getAllNodesOfType(clone, VarRefNode.class)) {
VarDefn defn = varRef.getDefnDecl();
LocalVar local;
switch(varRef.getName()) {
case "local":
local = (LocalVar) defn;
assertSame(letValueNode, local.declaringNode());
assertSame(letValueNode.getVar(), local);
break;
case "item":
local = (LocalVar) defn;
assertSame(forNonemptyNode, local.declaringNode());
assertSame(forNonemptyNode.getVar(), defn);
break;
default:
}
}
}
use of com.google.template.soy.exprtree.VarDefn in project closure-templates by google.
the class EnhancedAbstractExprNodeVisitor method visitVarRefNode.
@Override
protected final T visitVarRefNode(VarRefNode node) {
VarDefn defn = node.getDefnDecl();
switch(defn.kind()) {
case LOCAL_VAR:
LocalVar local = (LocalVar) defn;
LocalVarNode declaringNode = local.declaringNode();
switch(declaringNode.getKind()) {
case FOR_NONEMPTY_NODE:
return visitForLoopVar(node, local);
case LET_CONTENT_NODE:
case LET_VALUE_NODE:
return visitLetNodeVar(node, local);
default:
throw new AssertionError("Unexpected local variable: " + local);
}
case PARAM:
return visitParam(node, (TemplateParam) defn);
case IJ_PARAM:
return visitIjParam(node, (InjectedParam) defn);
case UNDECLARED:
throw new RuntimeException("undeclared params are not supported by jbcsrc");
default:
throw new AssertionError();
}
}
Aggregations