Search in sources :

Example 96 with ParserConfiguration

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

the class CoreConfidenceTests method testContextObjMethodCall.

public void testContextObjMethodCall() {
    String str = "getName() == \"bob\"";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("this", Bar.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    Bar ctx = new Bar();
    ctx.setName("bob");
    Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
    assertTrue(result);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) Bar(org.mvel2.tests.core.res.Bar) ParserContext(org.mvel2.ParserContext) MVEL.evalToBoolean(org.mvel2.MVEL.evalToBoolean) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 97 with ParserConfiguration

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

the class CoreConfidenceTests method testInstanceofWithPackageImportAndInnerClass.

public void testInstanceofWithPackageImportAndInnerClass() {
    ParserConfiguration conf = new ParserConfiguration();
    conf.addPackageImport("org.mvel2.tests.core.CoreConfidenceTests");
    ParserContext pctx = new ParserContext(conf);
    pctx.setStrictTypeEnforcement(true);
    pctx.setStrongTyping(true);
    pctx.addInput("value", Object.class);
    Map vars = new HashMap() {

        {
            put("value", new ARef());
        }
    };
    assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof ARef", pctx), vars));
    assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + ARef.class.getCanonicalName(), 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 98 with ParserConfiguration

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

the class CoreConfidenceTests method testFullyQualifiedEnums.

public void testFullyQualifiedEnums() {
    String str = "System.out.println( STATIC_ENUM.FOO ); \n" + "System.out.println( org.mvel2.tests.core.res.MyInterface$STATIC_ENUM.BAR );\n" + "System.out.println( org.mvel2.tests.core.res.MyInterface.MyInnerInterface.INNER_STATIC_ENUM.BAR );\n" + "System.out.println( RoundingMode.UP );\n" + "System.out.println( java.math.RoundingMode.DOWN );";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("this", MyInterface.class);
    pctx.addImport(MyInterface.STATIC_ENUM.class);
    pctx.addImport(java.math.RoundingMode.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) MyInterface(org.mvel2.tests.core.res.MyInterface) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 99 with ParserConfiguration

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

the class CoreConfidenceTests method testJavaLangImport.

public void testJavaLangImport() throws Exception {
    String s = "Exception e = null;";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    MVEL.compileExpression(s, pctx);
}
Also used : ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 100 with ParserConfiguration

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

the class ArithmeticTests method testMathCeil.

public void testMathCeil() {
    String str = "Math.ceil( x/3.0 ) == 2";
    ParserConfiguration pconf = new ParserConfiguration();
    pconf.addImport("Math", Math.class);
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("x", int.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    Map vars = new HashMap();
    vars.put("x", 4);
    Boolean result = (Boolean) MVEL.executeExpression(stmt, vars);
    assertTrue(result);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ParserConfiguration(org.mvel2.ParserConfiguration)

Aggregations

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