use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class WithTests method testWithMultipleMethodCalls.
public void testWithMultipleMethodCalls() {
ParserContext ctx = ParserContext.create().stronglyTyped().withInput("foo", Foo.class);
MVEL.compileExpression("with (foo) { setName('foo'), setBar(null) }", ctx);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class MutationsTests method testDeepAssignment2.
public void testDeepAssignment2() {
Map map = createTestMap();
ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
ParserContext ctx = new ParserContext();
ctx.addInput("foo", Foo.class);
ctx.setStrongTyping(true);
CompiledExpression ce = compiler.compile(ctx);
executeExpression(ce, map);
assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class PropertyAccessTests method testMVELCompilerBoth.
public void testMVELCompilerBoth() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
PropertyHandlerFactory.registerPropertyHandler(DynaBean.class, new DynaBeanPropertyHandler());
TestBean bean = new TestBean("value1");
Map<String, Object> vars = new LinkedHashMap<String, Object>();
vars.put("attr", bean);
ParserContext parserContext = new ParserContext();
Object compiled = MVEL.compileExpression("attr.value", parserContext);
assertEquals("value1", MVEL.executeExpression(compiled, null, vars));
DynaBean dyna = new LazyDynaBean();
dyna.set("value", "value2");
vars.put("attr", dyna);
assertEquals("value2", MVEL.executeExpression(compiled, null, vars));
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class TemplateTests method testMVEL244.
public void testMVEL244() {
Foo244 foo = new Foo244("plop");
String template = "@foreach{val : foo.liste[0].liste} plop @end{}";
CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(template);
Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", foo);
System.out.println(TemplateRuntime.execute(compiledTemplate, new ParserContext(), new MapVariableResolverFactory(model)));
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class IndexedVariablesTests method testVariableInjection3.
public void testVariableInjection3() {
String[] varNames = { "x", "y", "z" };
Object[] values = { 10, 20, 30 };
String expr = "def add(a,b) { a + b }; foo = -1; res = x + y + z;\n" + "if (x > 9) {\n" + " res = z - y - x;\n" + " int k = 5;\n" + " foo = add(5,10);" + "}; \n" + "for (i = 0; i < 100000; i++) { foo++; }; foo;";
ParserContext ctx = ParserContext.create();
ctx.addIndexedInput(varNames);
ctx.setIndexAllocation(true);
SimpleVariableSpaceModel model = VariableSpaceCompiler.compile(expr, ctx);
Serializable indexCompile = MVEL.compileExpression(expr, ctx);
Serializable dynamicCompile = MVEL.compileExpression(expr, ParserContext.create());
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", 10);
map.put("y", 20);
map.put("z", 30);
assertEquals(MVEL.executeExpression(dynamicCompile, map), MVEL.executeExpression(indexCompile, model.createFactory(values)));
}
Aggregations