use of com.google.template.soy.data.restricted.IntegerData in project closure-templates by google.
the class RenderVisitor method visitCallDelegateNode.
@Override
protected void visitCallDelegateNode(CallDelegateNode node) {
ExprRootNode variantExpr = node.getDelCalleeVariantExpr();
String variant;
if (variantExpr == null) {
variant = "";
} else {
try {
SoyValue variantData = eval(variantExpr, node);
if (variantData instanceof IntegerData) {
// An integer constant is being used as variant. Use the value string representation as
// variant.
variant = String.valueOf(variantData.longValue());
} else {
// Variant is either a StringData or a SanitizedContent. Use the value as a string. If
// the value is not a string, and exception will be thrown.
variant = variantData.stringValue();
}
} catch (SoyDataException e) {
throw RenderException.createWithSource(String.format("Variant expression \"%s\" doesn't evaluate to a valid type " + "(Only string and integer are supported).", variantExpr.toSourceString()), e, node);
}
}
DelTemplateKey delegateKey = DelTemplateKey.create(node.getDelCalleeName(), variant);
TemplateDelegateNode callee;
try {
callee = templateRegistry.selectDelTemplate(delegateKey, activeDelPackageSelector);
} catch (IllegalArgumentException e) {
throw RenderException.createWithSource(e.getMessage(), e, node);
}
if (callee != null) {
visitCallNodeHelper(node, callee);
} else if (node.allowEmptyDefault()) {
// no active delegate implementation, so the call output is empty string
return;
} else {
throw RenderException.createWithSource("Found no active impl for delegate call to \"" + node.getDelCalleeName() + (variant.isEmpty() ? "" : ":" + variant) + "\" (and delcall does not set allowemptydefault=\"true\").", node);
}
}
use of com.google.template.soy.data.restricted.IntegerData in project closure-templates by google.
the class StrSubFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
SoyValue arg2 = args.size() == 3 ? args.get(2) : null;
Preconditions.checkArgument(arg0 instanceof StringData || arg0 instanceof SanitizedContent, "First argument to strSub() function is not StringData or SanitizedContent: %s", arg0);
Preconditions.checkArgument(arg1 instanceof IntegerData, "Second argument to strSub() function is not IntegerData: %s", arg1);
if (arg2 != null) {
Preconditions.checkArgument(arg2 instanceof IntegerData, "Third argument to strSub() function is not IntegerData: %s", arg2);
}
String strArg0 = arg0.coerceToString();
int intArg1 = arg1.integerValue();
if (arg2 != null) {
return StringData.forValue(strArg0.substring(intArg1, arg2.integerValue()));
} else {
return StringData.forValue(strArg0.substring(intArg1));
}
}
Aggregations