Search in sources :

Example 1 with UnknownType

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

the class MapToLegacyObjectMapFunction method computeForJbcSrc.

@Override
public SoyExpression computeForJbcSrc(JbcSrcPluginContext context, List<SoyExpression> args) {
    SoyExpression soyExpression = Iterables.getOnlyElement(args);
    SoyType originalType = soyExpression.soyRuntimeType().soyType();
    LegacyObjectMapType newType;
    if (originalType instanceof MapType) {
        newType = LegacyObjectMapType.of(((MapType) originalType).getKeyType(), ((MapType) originalType).getValueType());
    } else if (originalType instanceof UnknownType) {
        newType = LegacyObjectMapType.of(UnknownType.getInstance(), UnknownType.getInstance());
    } else {
        throw new IllegalArgumentException("mapToLegacyObjectMap() expects input to be MAP, get " + originalType.getKind());
    }
    return SoyExpression.forLegacyObjectMap(newType, JbcSrcMethods.MAP_TO_LEGACY_OBJECT_MAP.invoke(soyExpression.box().checkedCast(SoyMap.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 2 with UnknownType

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

SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)2 LegacyObjectMapType (com.google.template.soy.types.LegacyObjectMapType)2 MapType (com.google.template.soy.types.MapType)2 SoyType (com.google.template.soy.types.SoyType)2 UnknownType (com.google.template.soy.types.UnknownType)2