Search in sources :

Example 91 with ParserConfiguration

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

the class CoreConfidenceTests method testInvokeVarargConstructor.

public void testInvokeVarargConstructor() {
    ParserConfiguration conf = new ParserConfiguration();
    conf.addImport(Thingy.class);
    ParserContext pctx = new ParserContext(conf);
    pctx.setStrictTypeEnforcement(true);
    pctx.setStrongTyping(true);
    pctx.addInput("name", String.class);
    Map vars = new HashMap() {

        {
            put("name", "test");
        }
    };
    Thingy result = (Thingy) MVEL.executeExpression(MVEL.compileExpression("new Thingy(name)", pctx), vars);
    assertEquals("test", result.getName());
}
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 92 with ParserConfiguration

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

the class CoreConfidenceTests method testPrimitiveSubtyping.

public void testPrimitiveSubtyping() {
    ParserConfiguration conf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(conf);
    pctx.setStrictTypeEnforcement(true);
    pctx.setStrongTyping(true);
    BigDecimal result = (BigDecimal) MVEL.executeExpression(MVEL.compileExpression("java.math.BigDecimal.valueOf(100)", pctx), new HashMap());
    assertEquals("100", result.toString());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) BigDecimal(java.math.BigDecimal) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 93 with ParserConfiguration

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

the class CoreConfidenceTests method testMethodReturningPrimitiveTypeAnalysis.

public void testMethodReturningPrimitiveTypeAnalysis() {
    String str = "value";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.addInput("this", MyObj.class);
    pctx.setStrongTyping(true);
    Class<?> returnType = MVEL.analyze(str, pctx);
    assertEquals(long.class, returnType);
}
Also used : ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 94 with ParserConfiguration

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

the class CoreConfidenceTests method testWithInsideBlock.

public void testWithInsideBlock() {
    String str = "Foo f = new Foo(); with(f) { setBoolTest( true ) }; f.isBoolTest()";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("this", Bar.class);
    pctx.addImport(Foo.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    Bar ctx = new Bar();
    Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx, new HashMap());
    assertTrue(result);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) Bar(org.mvel2.tests.core.res.Bar) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParserContext(org.mvel2.ParserContext) MVEL.evalToBoolean(org.mvel2.MVEL.evalToBoolean) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 95 with ParserConfiguration

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

the class CoreConfidenceTests method testInstanceofOnInnerClass.

public void testInstanceofOnInnerClass() {
    ParserConfiguration conf = new ParserConfiguration();
    conf.addImport(ARef.class);
    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)

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