Search in sources :

Example 16 with ExprRootNode

use of com.google.template.soy.exprtree.ExprRootNode in project closure-templates by google.

the class PreevalVisitorTest method preeval.

// -----------------------------------------------------------------------------------------------
// Helpers.
/**
 * Evaluates the given expression and returns the result.
 *
 * @param expression The expression to preevaluate.
 * @return The expression result.
 */
private static SoyValue preeval(String expression, String... params) {
    String header = "";
    for (String param : params) {
        header += "{@param " + param + " : ?}\n";
    }
    PrintNode code = (PrintNode) SoyFileSetParserBuilder.forTemplateContents(header + "{" + expression + "}").parse().fileSet().getChild(0).getChild(0).getChild(0);
    ExprRootNode expr = code.getExpr();
    Environment env = TestingEnvironment.createForTest(SoyValueConverterUtility.newDict("boo", 8), ImmutableMap.<String, SoyValueProvider>of());
    return new PreevalVisitor(env).exec(expr);
}
Also used : TestingEnvironment(com.google.template.soy.sharedpasses.render.TestingEnvironment) Environment(com.google.template.soy.sharedpasses.render.Environment) PrintNode(com.google.template.soy.soytree.PrintNode) ExprRootNode(com.google.template.soy.exprtree.ExprRootNode)

Aggregations

ExprRootNode (com.google.template.soy.exprtree.ExprRootNode)16 SoyDataException (com.google.template.soy.data.SoyDataException)3 SoyPrintDirective (com.google.template.soy.shared.restricted.SoyPrintDirective)3 PrintDirectiveNode (com.google.template.soy.soytree.PrintDirectiveNode)3 ArrayList (java.util.ArrayList)3 SoyValue (com.google.template.soy.data.SoyValue)2 StringNode (com.google.template.soy.exprtree.StringNode)2 Expression (com.google.template.soy.jbcsrc.restricted.Expression)2 SoyExpression (com.google.template.soy.jbcsrc.restricted.SoyExpression)2 Statement (com.google.template.soy.jbcsrc.restricted.Statement)2 CodeChunk (com.google.template.soy.jssrc.dsl.CodeChunk)2 SoyJsSrcPrintDirective (com.google.template.soy.jssrc.restricted.SoyJsSrcPrintDirective)2 PyExpr (com.google.template.soy.pysrc.restricted.PyExpr)2 CaseOrDefaultNode (com.google.template.soy.soytree.CaseOrDefaultNode)2 Label (org.objectweb.asm.Label)2 Identifier (com.google.template.soy.base.internal.Identifier)1 IntegerData (com.google.template.soy.data.restricted.IntegerData)1 UndefinedData (com.google.template.soy.data.restricted.UndefinedData)1 Checkpoint (com.google.template.soy.error.ErrorReporter.Checkpoint)1 ExprNode (com.google.template.soy.exprtree.ExprNode)1