use of com.google.template.soy.data.restricted.NullData in project closure-templates by google.
the class EvalVisitor method visitProtoInitNode.
@Override
protected SoyValue visitProtoInitNode(ProtoInitNode node) {
// The downcast is safe because if it was anything else, compilation would have already failed.
SoyProtoType soyProto = (SoyProtoType) node.getType();
ImmutableList<String> paramNames = node.getParamNames();
SoyProtoValueImpl.Builder builder = new SoyProtoValueImpl.Builder(soyProto.getDescriptor());
for (int i = 0; i < node.numChildren(); i++) {
SoyValue visit = visit(node.getChild(i));
// null means don't assign
if (visit instanceof NullData || visit instanceof UndefinedData) {
continue;
}
builder.setField(paramNames.get(i), visit);
}
return builder.build();
}
use of com.google.template.soy.data.restricted.NullData in project closure-templates by google.
the class InternalValueUtilsTest method testConvertPrimitiveExprToData.
@Test
public void testConvertPrimitiveExprToData() {
assertTrue(InternalValueUtils.convertPrimitiveExprToData(new NullNode(SourceLocation.UNKNOWN)) instanceof NullData);
assertTrue(InternalValueUtils.convertPrimitiveExprToData(new BooleanNode(true, SourceLocation.UNKNOWN)).booleanValue());
assertEquals(-1, InternalValueUtils.convertPrimitiveExprToData(new IntegerNode(-1, SourceLocation.UNKNOWN)).integerValue());
assertEquals(6.02e23, InternalValueUtils.convertPrimitiveExprToData(new FloatNode(6.02e23, SourceLocation.UNKNOWN)).floatValue(), 0.0);
assertEquals("foo", InternalValueUtils.convertPrimitiveExprToData(new StringNode("foo", QuoteStyle.SINGLE, SourceLocation.UNKNOWN)).stringValue());
}
Aggregations