Search in sources :

Example 6 with LegacyObjectMapType

use of com.google.template.soy.types.LegacyObjectMapType 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)

Example 7 with LegacyObjectMapType

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

the class AugmentMapFunction method computeForJbcSrc.

@Override
public SoyExpression computeForJbcSrc(JbcSrcPluginContext context, List<SoyExpression> args) {
    SoyExpression arg0 = args.get(0);
    SoyExpression arg1 = args.get(1);
    Expression first = arg0.checkedCast(SoyDict.class);
    Expression second = arg1.checkedCast(SoyDict.class);
    // TODO(lukes): this logic should move into the ResolveExpressionTypesVisitor
    LegacyObjectMapType mapType = LegacyObjectMapType.of(StringType.getInstance(), UnionType.of(getMapValueType(arg0.soyType()), getMapValueType(arg1.soyType())));
    return SoyExpression.forSoyValue(mapType, JbcSrcMethods.AUGMENT_MAP_FN.invoke(first, second));
}
Also used : SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression) LegacyObjectMapType(com.google.template.soy.types.LegacyObjectMapType)

Aggregations

LegacyObjectMapType (com.google.template.soy.types.LegacyObjectMapType)7 SoyType (com.google.template.soy.types.SoyType)4 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)3 MapType (com.google.template.soy.types.MapType)3 ListType (com.google.template.soy.types.ListType)2 RecordType (com.google.template.soy.types.RecordType)2 SoyProtoEnumType (com.google.template.soy.types.SoyProtoEnumType)2 UnknownType (com.google.template.soy.types.UnknownType)2 Test (org.junit.Test)2 Optional (com.google.common.base.Optional)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 SoyBackendKind (com.google.template.soy.base.SoyBackendKind)1 SanitizedContentKind (com.google.template.soy.base.internal.SanitizedContentKind)1 Expression (com.google.template.soy.jbcsrc.restricted.Expression)1 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)1 Generator (com.google.template.soy.jssrc.dsl.CodeChunk.Generator)1 SoyProtoType (com.google.template.soy.types.SoyProtoType)1 Kind (com.google.template.soy.types.SoyType.Kind)1