Search in sources :

Example 71 with ParserContext

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

the class CoreConfidenceTests method testOverloading.

public void testOverloading() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrictTypeEnforcement(true);
    parserContext.setStrongTyping(true);
    parserContext.addInput("this", Overloaded.class);
    Overloaded overloaded = new Overloaded();
    assertEquals(15, MVEL.executeExpression(MVEL.compileExpression("method(5, 9, \"x\")", parserContext), overloaded));
    assertEquals(-3, MVEL.executeExpression(MVEL.compileExpression("method(5, \"x\", 9)", parserContext), overloaded));
    assertEquals(-13, MVEL.executeExpression(MVEL.compileExpression("method(\"x\", 5, 9)", parserContext), overloaded));
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 72 with ParserContext

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

the class CoreConfidenceTests method testDynamicImportsWithIdentifierSameAsClassWithDiffCase.

public void testDynamicImportsWithIdentifierSameAsClassWithDiffCase() {
    ParserContext ctx = new ParserContext();
    ctx.addPackageImport("org.mvel2.tests.core.res");
    ctx.setStrictTypeEnforcement(false);
    ExpressionCompiler compiler = new ExpressionCompiler("bar.add(\"hello\")", ctx);
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 73 with ParserContext

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

the class CoreConfidenceTests method testDynamicImports.

public void testDynamicImports() {
    ParserContext ctx = new ParserContext();
    ctx.addPackageImport("java.util");
    ExpressionCompiler compiler = new ExpressionCompiler("HashMap", ctx);
    Serializable s = compiler.compile();
    assertEquals(HashMap.class, executeExpression(s));
    compiler = new ExpressionCompiler("map = new HashMap(); map.size()", ctx);
    s = compiler.compile();
    assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory()));
}
Also used : Serializable(java.io.Serializable) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 74 with ParserContext

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

the class CoreConfidenceTests method testGenericsWithOr.

public void testGenericsWithOr() {
    final ParserContext parserContext = new ParserContext();
    parserContext.setStrictTypeEnforcement(true);
    parserContext.setStrongTyping(true);
    parserContext.addInput("o", OrderLine.class);
    parserContext.addInput("p", Product.class);
    Class<?> clazz = MVEL.analyze("p.id == o.product.id || p.category == o.product.category", parserContext);
    assertEquals(Boolean.class, clazz);
}
Also used : ParserContext(org.mvel2.ParserContext)

Example 75 with ParserContext

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

the class DebuggerTests method testDebugSymbolsWithWindowsLinedEndings.

public void testDebugSymbolsWithWindowsLinedEndings() throws Exception {
    String expr = "   System.out.println( \"a1\" );\r\n" + "   System.out.println( \"a2\" );\r\n" + "   System.out.println( \"a3\" );\r\n" + "   System.out.println( \"a4\" );\r\n";
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ctx.setDebugSymbols(true);
    ctx.setSourceFile("mysource");
    ExpressionCompiler compiler = new ExpressionCompiler(expr, ctx);
    String s = org.mvel2.debug.DebugTools.decompile(compiler.compile());
    System.out.println(s);
    int fromIndex = 0;
    int count = 0;
    while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
        count++;
    }
    assertEquals(4, count);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

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