Search in sources :

Example 86 with ParserConfiguration

use of org.mvel2.ParserConfiguration in project mvel by mvel.

the class CoreConfidenceTests method testStaticMethodsInvocationWithNullArg.

public void testStaticMethodsInvocationWithNullArg() {
    String str = "org.mvel2.tests.core.CoreConfidenceTests$MyObj.doSomething(null, \"abc\")";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    assertEquals(null + "abc", MVEL.executeExpression(MVEL.compileExpression(str, pctx)));
}
Also used : ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 87 with ParserConfiguration

use of org.mvel2.ParserConfiguration in project mvel by mvel.

the class CoreConfidenceTests method testUnaryNegativeWithSpace.

public void testUnaryNegativeWithSpace() {
    ParserConfiguration conf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(conf);
    pctx.setStrictTypeEnforcement(true);
    pctx.setStrongTyping(true);
    pctx.addInput("value", int.class);
    Map vars = new HashMap() {

        {
            put("value", 42);
        }
    };
    assertEquals(-42, MVEL.executeExpression(MVEL.compileExpression("- value", pctx), vars));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 88 with ParserConfiguration

use of org.mvel2.ParserConfiguration in project mvel by mvel.

the class CoreConfidenceTests method testPackageImportEnum.

// public void testSysoutNullVariable() {
// // Create our root Map object
// Map<String, String> map = new HashMap<String, String>();
// map.put("foo", null);
// 
// VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
// factory.createVariable("this", map);
// 
// org.mvel2.MVEL.executeExpression(org.mvel2.MVEL.compileExpression("System.out.println(foo);"), map, factory);
// }
public void testPackageImportEnum() {
    String str = "new Status( START )";
    ParserConfiguration pconf = new ParserConfiguration();
    pconf.addPackageImport("org.mvel2.tests.core.res");
    pconf.addPackageImport("org.mvel2.tests.core.res.Status");
    ParserContext context = new ParserContext(pconf);
    context.setStrongTyping(true);
    Serializable s = MVEL.compileExpression(str.trim(), context);
    assertEquals(new Status(Status.START), MVEL.executeExpression(s));
    assertFalse(new Status(Status.STOP).equals(MVEL.executeExpression(s)));
}
Also used : Status(org.mvel2.tests.core.res.Status) Serializable(java.io.Serializable) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 89 with ParserConfiguration

use of org.mvel2.ParserConfiguration in project mvel by mvel.

the class CoreConfidenceTests method testArrays.

public void testArrays() {
    String str = "Object[] a = new Object[3]; a[0] = \"a\"; a[1] = \"b\"; a[2] = \"c\"; System.out.println(java.util.Arrays.toString(a));";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    MVEL.executeExpression(stmt, new HashMap());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 90 with ParserConfiguration

use of org.mvel2.ParserConfiguration in project mvel by mvel.

the class CoreConfidenceTests method testInlineConstructor.

public void testInlineConstructor() {
    String str = "cheese = new Cheese().{ type = $c.type };";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("$c", Cheese.class);
    pctx.addImport(Cheese.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    Cheese $c = new Cheese();
    $c.setType("stilton");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("$c", $c);
    Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
    assertEquals("stilton", cheese.getType());
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Cheese(org.mvel2.tests.core.res.Cheese) MapObject(org.mvel2.tests.core.res.MapObject) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Aggregations

ParserConfiguration (org.mvel2.ParserConfiguration)95 ParserContext (org.mvel2.ParserContext)88 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)48 HashMap (java.util.HashMap)43 LinkedHashMap (java.util.LinkedHashMap)30 Map (java.util.Map)27 Serializable (java.io.Serializable)12 CompileException (org.mvel2.CompileException)9 MVEL.evalToBoolean (org.mvel2.MVEL.evalToBoolean)9 IOException (java.io.IOException)7 MapObject (org.mvel2.tests.core.res.MapObject)7 ParserConfiguration (org.mule.mvel2.ParserConfiguration)6 Method (java.lang.reflect.Method)5 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)5 MVELExpressionLanguageContext (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext)5 RecognitionException (org.antlr.runtime.RecognitionException)4 PropertyAccessException (org.mvel2.PropertyAccessException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3