Search in sources :

Example 56 with ParserContext

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

the class CoreConfidenceTests method testDynamicImportsWithNullConstructorParamWithStrongType.

public void testDynamicImportsWithNullConstructorParamWithStrongType() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addPackageImport("org.mvel2.tests.core.res");
    ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", null)", ctx);
    Cheesery p1 = new Cheesery("bobbo", null);
    Cheesery p2 = (Cheesery) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory());
    assertEquals(p1, p2);
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) Cheesery(org.mvel2.tests.core.res.Cheesery) ParserContext(org.mvel2.ParserContext)

Example 57 with ParserContext

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

the class CoreConfidenceTests method testUnaryNegative.

public void testUnaryNegative() {
    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 58 with ParserContext

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

the class CoreConfidenceTests method testMapAccessWithNestedProperty.

public void testMapAccessWithNestedProperty() {
    String str = "map[key] == \"one\"";
    ParserConfiguration pconf = new ParserConfiguration();
    ParserContext pctx = new ParserContext(pconf);
    pctx.setStrongTyping(true);
    pctx.addInput("this", POJO.class);
    ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
    POJO ctx = new POJO();
    ctx.getMap().put("1", "one");
    Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
    assertTrue(result);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) ParserContext(org.mvel2.ParserContext) ParserConfiguration(org.mvel2.ParserConfiguration)

Example 59 with ParserContext

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

the class CoreConfidenceTests method testJIRA155.

public void testJIRA155() {
    ParserContext pctx = new ParserContext();
    pctx.addImport("returnTrue", MVEL.getStaticMethod(CoreConfidenceTests.class, "returnTrue", new Class[0]));
    assertEquals(true, executeExpression(MVEL.compileExpression("!true || returnTrue()", pctx)));
}
Also used : TestClass(org.mvel2.tests.core.res.TestClass) PublicClass(org.mvel2.tests.core.res.res2.PublicClass) MyClass(org.mvel2.tests.core.res.MyClass) OverloadedClass(org.mvel2.tests.core.res.res2.OverloadedClass) ParserContext(org.mvel2.ParserContext)

Example 60 with ParserContext

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

the class CoreConfidenceTests method testComaProblemStrikesBack.

public void testComaProblemStrikesBack() {
    String ex = "a.explanation = \"There is a coma, in here\"";
    ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
    Serializable s = compiler.compile();
    Base a = new Base();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("a", a);
    executeExpression(s, variables);
    assertEquals("There is a coma, in here", a.data);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) MapObject(org.mvel2.tests.core.res.MapObject) ParserContext(org.mvel2.ParserContext) RuleBase(org.mvel2.tests.core.res.RuleBase) Base(org.mvel2.tests.core.res.Base)

Aggregations

ParserContext (org.mvel2.ParserContext)340 HashMap (java.util.HashMap)128 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)119 Serializable (java.io.Serializable)82 ParserConfiguration (org.mvel2.ParserConfiguration)70 Map (java.util.Map)64 LinkedHashMap (java.util.LinkedHashMap)62 CompiledExpression (org.mvel2.compiler.CompiledExpression)48 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)42 CompileException (org.mvel2.CompileException)37 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)23 ArrayList (java.util.ArrayList)20 List (java.util.List)19 MapObject (org.mvel2.tests.core.res.MapObject)18 Debugger (org.mvel2.debug.Debugger)15 Frame (org.mvel2.debug.Frame)15 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)14 HashSet (java.util.HashSet)12 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10