Search in sources :

Example 1 with IndexedVariableResolverFactory

use of org.mvel2.integration.impl.IndexedVariableResolverFactory in project mvel by mvel.

the class CoreConfidenceTests method testNullCollection.

public void testNullCollection() throws CompileException {
    boolean allowCompilerOverride = MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING;
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    String[] names = { "missing" };
    String[] values = { null };
    try {
        MVEL.executeExpression((CompiledExpression) MVEL.compileExpression("1; missing[3]"), new IndexedVariableResolverFactory(names, values));
        fail("Should throw a NullPointerExcption");
    } catch (Exception e) {
    } finally {
        MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = allowCompilerOverride;
    }
}
Also used : CompileException(org.mvel2.CompileException) IOException(java.io.IOException) IndexedVariableResolverFactory(org.mvel2.integration.impl.IndexedVariableResolverFactory)

Example 2 with IndexedVariableResolverFactory

use of org.mvel2.integration.impl.IndexedVariableResolverFactory in project mvel by mvel.

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)

Example 3 with IndexedVariableResolverFactory

use of org.mvel2.integration.impl.IndexedVariableResolverFactory 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

Serializable (java.io.Serializable)2 ParserContext (org.mvel2.ParserContext)2 SharedVariableSpaceModel (org.mvel2.util.SharedVariableSpaceModel)2 IOException (java.io.IOException)1 CompileException (org.mvel2.CompileException)1 IndexedVariableResolverFactory (org.mvel2.integration.impl.IndexedVariableResolverFactory)1