Search in sources :

Example 56 with VariableResolverFactory

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);
    }
}
Also used : AccessorOptimizer(org.mvel2.optimizers.AccessorOptimizer)

Example 57 with VariableResolverFactory

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));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 58 with VariableResolverFactory

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));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 59 with VariableResolverFactory

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));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 60 with VariableResolverFactory

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()));
}
Also used : Serializable(java.io.Serializable) SharedVariableSpaceModel(org.mvel2.util.SharedVariableSpaceModel) ParserContext(org.mvel2.ParserContext)

Aggregations

VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)16 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)15 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)15 VariableResolver (org.mvel2.integration.VariableResolver)14 HashMap (java.util.HashMap)10 CompileException (org.mvel2.CompileException)7 ParserContext (org.mvel2.ParserContext)7 AccessorOptimizer (org.mvel2.optimizers.AccessorOptimizer)7 List (java.util.List)6 Map (java.util.Map)6 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)6 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 ASTNode (org.mvel2.ast.ASTNode)5 CompiledExpression (org.mvel2.compiler.CompiledExpression)5 Foo (org.mvel2.tests.core.res.Foo)5 IOException (java.io.IOException)4 Debugger (org.mvel2.debug.Debugger)4 Frame (org.mvel2.debug.Frame)4 Interceptor (org.mvel2.integration.Interceptor)4