use of com.google.template.soy.jbcsrc.restricted.SoyExpression in project closure-templates by google.
the class SoyNodeCompiler method visitIfNode.
@Override
protected Statement visitIfNode(IfNode node) {
List<IfBlock> ifs = new ArrayList<>();
Optional<Statement> elseBlock = Optional.absent();
for (SoyNode child : node.getChildren()) {
if (child instanceof IfCondNode) {
IfCondNode icn = (IfCondNode) child;
SoyExpression cond = exprCompiler.compile(icn.getExpr()).coerceToBoolean();
Statement block = visitChildrenInNewScope(icn);
ifs.add(IfBlock.create(cond, block));
} else {
IfElseNode ien = (IfElseNode) child;
elseBlock = Optional.of(visitChildrenInNewScope(ien));
}
}
return ControlFlow.ifElseChain(ifs, elseBlock);
}
use of com.google.template.soy.jbcsrc.restricted.SoyExpression 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)));
}
use of com.google.template.soy.jbcsrc.restricted.SoyExpression in project closure-templates by google.
the class MinFunction method computeForJbcSrc.
@Override
public SoyExpression computeForJbcSrc(JbcSrcPluginContext context, List<SoyExpression> args) {
SoyExpression left = args.get(0);
SoyExpression right = args.get(1);
if (left.assignableToNullableInt() && right.assignableToNullableInt()) {
return SoyExpression.forInt(JbcSrcMethods.MATH_MIN_LONG.invoke(left.unboxAs(long.class), right.unboxAs(long.class)));
} else if (left.assignableToNullableFloat() && right.assignableToNullableFloat()) {
return SoyExpression.forFloat(JbcSrcMethods.MATH_MIN_DOUBLE.invoke(left.unboxAs(double.class), right.unboxAs(double.class)));
} else {
return SoyExpression.forSoyValue(NUMBER_TYPE, JbcSrcMethods.MIN_FN.invoke(left.box(), right.box()));
}
}
use of com.google.template.soy.jbcsrc.restricted.SoyExpression 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.jbcsrc.restricted.SoyExpression 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