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)));
}
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));
}
Aggregations