Search in sources :

Example 26 with SoyType

use of com.google.template.soy.types.SoyType in project closure-templates by google.

the class LegacyObjectMapToMapFunction method computeForJbcSrc.

@Override
public SoyExpression computeForJbcSrc(JbcSrcPluginContext context, List<SoyExpression> args) {
    SoyExpression soyExpression = Iterables.getOnlyElement(args);
    SoyType originalType = soyExpression.soyRuntimeType().soyType();
    MapType newType;
    if (originalType instanceof LegacyObjectMapType) {
        newType = MapType.of(((LegacyObjectMapType) originalType).getKeyType(), ((LegacyObjectMapType) originalType).getValueType());
    } else if (originalType instanceof UnknownType) {
        newType = MapType.of(UnknownType.getInstance(), UnknownType.getInstance());
    } else {
        throw new IllegalArgumentException("legacyObjectMapToMap() expects input to be LEGACY_OBJECT_MAP, get " + originalType.getKind());
    }
    return SoyExpression.forMap(newType, JbcSrcMethods.LEGACY_OBJECT_MAP_TO_MAP.invoke(soyExpression.box().checkedCast(SoyDict.class)));
}
Also used : UnknownType(com.google.template.soy.types.UnknownType) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) SoyType(com.google.template.soy.types.SoyType) LegacyObjectMapType(com.google.template.soy.types.LegacyObjectMapType) LegacyObjectMapType(com.google.template.soy.types.LegacyObjectMapType) MapType(com.google.template.soy.types.MapType)

Aggregations

SoyType (com.google.template.soy.types.SoyType)26 MapType (com.google.template.soy.types.MapType)5 ExprNode (com.google.template.soy.exprtree.ExprNode)4 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)4 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)4 LegacyObjectMapType (com.google.template.soy.types.LegacyObjectMapType)4 ListType (com.google.template.soy.types.ListType)4 LinkedHashMap (java.util.LinkedHashMap)4 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ParentExprNode (com.google.template.soy.exprtree.ExprNode.ParentExprNode)3 TemplateParam (com.google.template.soy.soytree.defn.TemplateParam)3 SoyProtoEnumType (com.google.template.soy.types.SoyProtoEnumType)3 SoyProtoType (com.google.template.soy.types.SoyProtoType)3 UnionType (com.google.template.soy.types.UnionType)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FunctionNode (com.google.template.soy.exprtree.FunctionNode)2 VarRefNode (com.google.template.soy.exprtree.VarRefNode)2 RecordType (com.google.template.soy.types.RecordType)2