Search in sources :

Example 31 with Expression

use of com.google.template.soy.jbcsrc.restricted.Expression 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)

Example 32 with Expression

use of com.google.template.soy.jbcsrc.restricted.Expression in project closure-templates by google.

the class BasicEscapeDirective method applyForJbcSrcStreaming.

/**
 * Default implementation for {@link Streamable}.
 *
 * <p>Subclasses can simply add {@code implements Streamable} if they have an implementation in
 * Sanitizers.<name>Streaming. If they don't, this method will throw while trying to find it.
 */
public final AppendableAndOptions applyForJbcSrcStreaming(JbcSrcPluginContext context, Expression delegateAppendable, List<SoyExpression> args) {
    MethodRef sanitizerMethod = javaStreamingSanitizer;
    if (sanitizerMethod == null) {
        // lazily allocated
        sanitizerMethod = MethodRef.create(Sanitizers.class, name.substring(1) + "Streaming", LoggingAdvisingAppendable.class).asNonNullable();
        javaStreamingSanitizer = sanitizerMethod;
    }
    Expression streamingSanitizersExpr = sanitizerMethod.invoke(delegateAppendable);
    if (isCloseable()) {
        return AppendableAndOptions.createCloseable(streamingSanitizersExpr);
    } else {
        return AppendableAndOptions.create(streamingSanitizersExpr);
    }
}
Also used : MethodRef(com.google.template.soy.jbcsrc.restricted.MethodRef) SoyExpression(com.google.template.soy.jbcsrc.restricted.SoyExpression) Expression(com.google.template.soy.jbcsrc.restricted.Expression)

Aggregations

Expression (com.google.template.soy.jbcsrc.restricted.Expression)32 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)26 Statement (com.google.template.soy.jbcsrc.restricted.Statement)15 Label (org.objectweb.asm.Label)15 CodeBuilder (com.google.template.soy.jbcsrc.restricted.CodeBuilder)8 ArrayList (java.util.ArrayList)8 Statement.returnExpression (com.google.template.soy.jbcsrc.restricted.Statement.returnExpression)5 Scope (com.google.template.soy.jbcsrc.TemplateVariableManager.Scope)4 Variable (com.google.template.soy.jbcsrc.TemplateVariableManager.Variable)4 LocalVariable (com.google.template.soy.jbcsrc.restricted.LocalVariable)4 AppendableAndOptions (com.google.template.soy.jbcsrc.restricted.SoyJbcSrcPrintDirective.Streamable.AppendableAndOptions)4 ImmutableList (com.google.common.collect.ImmutableList)2 ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)2 SoyClassWriter (com.google.template.soy.jbcsrc.internal.SoyClassWriter)2 FieldRef (com.google.template.soy.jbcsrc.restricted.FieldRef)2 TypeInfo (com.google.template.soy.jbcsrc.restricted.TypeInfo)2 RangeArgs (com.google.template.soy.shared.RangeArgs)2 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)2 ForNonemptyNode (com.google.template.soy.soytree.ForNonemptyNode)2 LinkedHashMap (java.util.LinkedHashMap)2