use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class Union method get.
private Object get(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
if (nextAccessor == null) {
Object o = accessor.getValue(ctx, elCtx, variableFactory);
AccessorOptimizer ao = OptimizerFactory.getDefaultAccessorCompiler();
Class ingress = accessor.getKnownEgressType();
nextAccessor = ao.optimizeAccessor(getCurrentThreadParserContext(), nextExpr, start, offset, o, elCtx, variableFactory, false, ingress);
return ao.getResultOptPass();
} else {
return accessor.getValue(ctx, elCtx, variableFactory);
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testMVEL190.
public void testMVEL190() {
ParserContext context = new ParserContext();
context.addImport(Ship.class);
context.addImport(MapObject.class);
context.addInput("obj", MapObject.class);
Object compiled = MVEL.compileExpression("((Ship) obj).getName()", context);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("obj", new Ship());
VariableResolverFactory varsResolver = new MapVariableResolverFactory(vars);
System.out.println(executeExpression(compiled, varsResolver));
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects.
// interpreted
public void testThisReferenceMapVirtualObjects() {
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
assertEquals(true, eval("this.foo == 'bar'", map, factory));
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testThisReferenceMapVirtualObjects2.
// compiled - asm
public void testThisReferenceMapVirtualObjects2() {
// Create our root Map object
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "bar");
VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
factory.createVariable("this", map);
if (!Boolean.getBoolean("mvel2.disable.jit"))
OptimizerFactory.setDefaultOptimizer("ASM");
// Run test
assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class IntegrationTests method testIndexedVariableFactory.
public void testIndexedVariableFactory() {
ParserContext ctx = ParserContext.create();
String[] vars = { "a", "b" };
Object[] vals = { "foo", "bar" };
ctx.setIndexAllocation(true);
ctx.addIndexedInput(vars);
String expr = "def myfunc(z) { a + b + z }; myfunc('poop');";
SharedVariableSpaceModel model = VariableSpaceCompiler.compileShared(expr, ctx, vals);
Serializable s = MVEL.compileExpression(expr, ctx);
// VariableResolverFactory locals = new CachingMapVariableResolverFactory(new HashMap<String, Object>());
// VariableResolverFactory injected = new IndexedVariableResolverFactory(vars, vals, locals);
assertEquals("foobarpoop", MVEL.executeExpression(s, model.createFactory()));
}
Aggregations