Search in sources :

Example 11 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler 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);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 12 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class InlineCollectionsTests method testToListStrictMode.

@SuppressWarnings({ "UnnecessaryBoxing" })
public void testToListStrictMode() {
    String text = "misc.toList(foo.bar.name, 'hello', 42, ['key1' : 'value1'," + " c : [ foo.bar.age, 'car', 42 ]], [42, [c : 'value1']] )";
    ParserContext ctx = new ParserContext();
    ctx.addInput("misc", MiscTestClass.class);
    ctx.addInput("foo", Foo.class);
    ctx.addInput("c", String.class);
    ctx.setStrictTypeEnforcement(true);
    ExpressionCompiler compiler = new ExpressionCompiler(text);
    List list = (List) executeExpression(compiler.compile(ctx), createTestMap());
    assertSame("dog", list.get(0));
    assertEquals("hello", list.get(1));
    assertEquals(new Integer(42), list.get(2));
    Map map = (Map) list.get(3);
    assertEquals("value1", map.get("key1"));
    List nestedList = (List) map.get("cat");
    assertEquals(14, nestedList.get(0));
    assertEquals("car", nestedList.get(1));
    assertEquals(42, nestedList.get(2));
    nestedList = (List) list.get(4);
    assertEquals(42, nestedList.get(0));
    map = (Map) nestedList.get(1);
    assertEquals("value1", map.get("cat"));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) List(java.util.List) ArrayList(java.util.ArrayList) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class TypesAndInferenceTests method testStrongTyping2.

public void testStrongTyping2() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("blah", String.class);
    try {
        new ExpressionCompiler("1-blah").compile(ctx);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    assertTrue(false);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 14 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class TypesAndInferenceTests method testCompileTimeCoercion.

public void testCompileTimeCoercion() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("foo", Foo.class);
    assertEquals(true, executeExpression(new ExpressionCompiler("foo.bar.woof == 'true'").compile(ctx), createTestMap()));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 15 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class TypesAndInferenceTests method testParameterizedTypeInStrictMode2.

public void testParameterizedTypeInStrictMode2() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("ctx", Object.class);
    ExpressionCompiler compiler = new ExpressionCompiler("org.mvel2.DataConversion.convert(ctx, String).toUpperCase()");
    assertEquals(String.class, compiler.compile(ctx).getKnownEgressType());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)219 ParserContext (org.mvel2.ParserContext)119 CompiledExpression (org.mvel2.compiler.CompiledExpression)65 HashMap (java.util.HashMap)39 Serializable (java.io.Serializable)30 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)22 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 Map (java.util.Map)18 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 LinkedHashMap (java.util.LinkedHashMap)15 HashSet (java.util.HashSet)10 List (java.util.List)10 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10 ArrayList (java.util.ArrayList)8 CompileException (org.mvel2.CompileException)8 Interceptor (org.mvel2.integration.Interceptor)8 Macro (org.mvel2.Macro)6 ASTNode (org.mvel2.ast.ASTNode)6