Search in sources :

Example 41 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testStringConcatenation.

public void testStringConcatenation() {
    // debugging MVEL code, it seems that MVEL 'thinks' that the result of the expression:
    // "Drop +5%: "+$sb+" avg: $"+$av+" price: $"+$pr
    // is a double, and as so, he looks for a method:
    // Services.log( double );
    // but finds only:
    // Services.log( String );
    // raising the error.
    String ex = "services.log((String) \"Drop +5%: \"+$sb+\" avg: $\"+$av+\" price: $\"+$pr );";
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("$sb", String.class);
    ctx.addInput("$av", double.class);
    ctx.addInput("$pr", double.class);
    ctx.addInput("services", Services.class);
    try {
        ExpressionCompiler compiler = new ExpressionCompiler(ex);
        compiler.compile(ctx);
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Should not raise exception: " + e.getMessage());
    }
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 42 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testAssignmentRegression.

public void testAssignmentRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("total = total + $cheese.price");
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 43 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testTypeRegression.

public void testTypeRegression() {
    ExpressionCompiler compiler = new ExpressionCompiler("total = 0");
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    compiler.compile(ctx);
    assertEquals(Integer.class, compiler.getParserContextState().getVarOrInputType("total"));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 44 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

the class CoreConfidenceTests method testListNestedInsideList.

public void testListNestedInsideList() {
    ParserContext ctx = new ParserContext();
    ctx.addImport("User", User.class);
    ExpressionCompiler compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users.get( 0 ), users.get( 1 ) ]");
    List list = (List) executeExpression(compiler.compile(ctx), new HashMap());
    User user = (User) list.get(0);
    assertEquals("Darth", user.getFirstName());
    user = (User) list.get(1);
    assertEquals("Bobba", user.getFirstName());
    compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users[0], users[1] ]");
    list = (List) executeExpression(compiler.compile(ctx), new HashMap());
    user = (User) list.get(0);
    assertEquals("Darth", user.getFirstName());
    user = (User) list.get(1);
    assertEquals("Bobba", user.getFirstName());
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) List(java.util.List)

Example 45 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.

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);
    Serializable s = compiler.compile(ctx);
    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) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)219 ParserContext (org.mvel2.ParserContext)119 CompiledExpression (org.mvel2.compiler.CompiledExpression)65 HashMap (java.util.HashMap)39 Serializable (java.io.Serializable)30 Foo (org.mvel2.tests.core.res.Foo)24 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)22 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)19 Map (java.util.Map)18 Debugger (org.mvel2.debug.Debugger)16 Frame (org.mvel2.debug.Frame)16 LinkedHashMap (java.util.LinkedHashMap)15 HashSet (java.util.HashSet)10 List (java.util.List)10 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)10 ArrayList (java.util.ArrayList)8 CompileException (org.mvel2.CompileException)8 Interceptor (org.mvel2.integration.Interceptor)8 Macro (org.mvel2.Macro)6 ASTNode (org.mvel2.ast.ASTNode)6