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");
}
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);
}
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());
}
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);
}
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);
}
Aggregations