Search in sources :

Example 96 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.

the class WithTests method testInlineWithImpliedThis.

public void testInlineWithImpliedThis() {
    Base b = new Base();
    ExpressionCompiler expr = new ExpressionCompiler(".{ data = 'foo' }");
    CompiledExpression compiled = expr.compile();
    executeExpression(compiled, b);
    assertEquals(b.data, "foo");
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) Base(org.mvel2.tests.core.res.Base) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 97 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.

the class WithTests method testExecuteCoercionTwice2.

public void testExecuteCoercionTwice2() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo", new Foo());
    vars.put("$value", new Long(5));
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);
    ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };", ctx);
    CompiledExpression compiled = compiler.compile();
    executeExpression(compiled, null, vars);
    executeExpression(compiled, null, vars);
}
Also used : HashMap(java.util.HashMap) Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 98 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.

the class WithTests method testInlineWith4.

public void testInlineWith4() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    ParserContext pCtx = new ParserContext();
    pCtx.addImport(Foo.class);
    ExpressionCompiler expr = new ExpressionCompiler("new Foo().{ name = 'bar' }", pCtx);
    CompiledExpression c = expr.compile();
    Foo f = (Foo) executeExpression(c);
    assertEquals("bar", f.getName());
    f = (Foo) executeExpression(c);
    assertEquals("bar", f.getName());
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 99 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.

the class WithTests method testInlineWith3.

public void testInlineWith3() {
    CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}, toUC('doopy')}").compile();
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
    assertEquals("foobie", f.getBar().getName());
    assertEquals("doopy", f.register);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 100 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.

the class WithTests method testNestedWithInList.

public void testNestedWithInList() {
    Recipient recipient1 = new Recipient();
    recipient1.setName("userName1");
    recipient1.setEmail("user1@domain.com");
    Recipient recipient2 = new Recipient();
    recipient2.setName("userName2");
    recipient2.setEmail("user2@domain.com");
    List list = new ArrayList();
    list.add(recipient1);
    list.add(recipient2);
    String text = "array = [" + "(with ( new Recipient() ) {name = 'userName1', email = 'user1@domain.com' })," + "(with ( new Recipient() ) {name = 'userName2', email = 'user2@domain.com' })];\n";
    ParserContext context = new ParserContext();
    context.addImport(Recipient.class);
    ExpressionCompiler compiler = new ExpressionCompiler(text, context);
    Serializable execution = compiler.compile();
    List result = (List) executeExpression(execution, new HashMap());
    assertEquals(list, result);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)219 ParserContext (org.mvel2.ParserContext)119 CompiledExpression (org.mvel2.compiler.CompiledExpression)65 HashMap (java.util.HashMap)39 Serializable (java.io.Serializable)30 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)22 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 Map (java.util.Map)18 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 LinkedHashMap (java.util.LinkedHashMap)15 HashSet (java.util.HashSet)10 List (java.util.List)10 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10 ArrayList (java.util.ArrayList)8 CompileException (org.mvel2.CompileException)8 Interceptor (org.mvel2.integration.Interceptor)8 Macro (org.mvel2.Macro)6 ASTNode (org.mvel2.ast.ASTNode)6