Search in sources :

Example 1 with NullData

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();
}
Also used : NullData(com.google.template.soy.data.restricted.NullData) UndefinedData(com.google.template.soy.data.restricted.UndefinedData) SoyValue(com.google.template.soy.data.SoyValue) SoyProtoType(com.google.template.soy.types.SoyProtoType) SoyProtoValueImpl(com.google.template.soy.data.SoyProtoValueImpl)

Example 2 with NullData

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());
}
Also used : NullData(com.google.template.soy.data.restricted.NullData) IntegerNode(com.google.template.soy.exprtree.IntegerNode) FloatNode(com.google.template.soy.exprtree.FloatNode) StringNode(com.google.template.soy.exprtree.StringNode) BooleanNode(com.google.template.soy.exprtree.BooleanNode) NullNode(com.google.template.soy.exprtree.NullNode) Test(org.junit.Test)

Aggregations

NullData (com.google.template.soy.data.restricted.NullData)2 SoyProtoValueImpl (com.google.template.soy.data.SoyProtoValueImpl)1 SoyValue (com.google.template.soy.data.SoyValue)1 UndefinedData (com.google.template.soy.data.restricted.UndefinedData)1 BooleanNode (com.google.template.soy.exprtree.BooleanNode)1 FloatNode (com.google.template.soy.exprtree.FloatNode)1 IntegerNode (com.google.template.soy.exprtree.IntegerNode)1 NullNode (com.google.template.soy.exprtree.NullNode)1 StringNode (com.google.template.soy.exprtree.StringNode)1 SoyProtoType (com.google.template.soy.types.SoyProtoType)1 Test (org.junit.Test)1