Search in sources :

Example 51 with ExpressionCompiler

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

the class MVEL method analysisCompile.

/**
 * Performs an analysis compileShared, which will populate the ParserContext with type, input and variable information,
 * but will not produce a payload.
 *
 * @param expression - the expression to analyze
 * @param ctx        - the parser context
 */
public static void analysisCompile(char[] expression, ParserContext ctx) {
    ExpressionCompiler compiler = new ExpressionCompiler(expression, ctx);
    compiler.setVerifyOnly(true);
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 52 with ExpressionCompiler

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

the class MVEL method analyze.

public static Class analyze(char[] expression, ParserContext ctx) {
    ExpressionCompiler compiler = new ExpressionCompiler(expression, ctx);
    compiler.setVerifyOnly(true);
    compiler.compile();
    return compiler.getReturnType();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 53 with ExpressionCompiler

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

the class CoreConfidenceTests method testParserErrorHandling.

public void testParserErrorHandling() {
    final ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler("a[", ctx);
    try {
        compiler.compile();
    } catch (Exception e) {
        return;
    }
    assertTrue(false);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompileException(org.mvel2.CompileException) IOException(java.io.IOException)

Example 54 with ExpressionCompiler

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

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 ) ]", ctx);
    List list = (List) executeExpression(compiler.compile(), 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] ]", ctx);
    list = (List) executeExpression(compiler.compile(), new HashMap());
    user = (User) list.get(0);
    assertEquals("Darth", user.getFirstName());
    user = (User) list.get(1);
    assertEquals("Bobba", user.getFirstName());
}
Also used : User(org.mvel2.tests.core.res.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) List(java.util.List) ArrayList(java.util.ArrayList) ParserContext(org.mvel2.ParserContext)

Example 55 with ExpressionCompiler

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

the class CoreConfidenceTests method testStaticNestedWithMethodCall.

public void testStaticNestedWithMethodCall() {
    String expr = "item = new Item( \"Some Item\"); $msg.addItem( item ); return $msg";
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(false);
    context.addImport("Message", Message.class);
    context.addImport("Item", Item.class);
    // Serializable compiledExpression = compiler.compileShared(context);
    Map vars = new HashMap();
    vars.put("$msg", new Message());
    ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
    Message msg = (Message) executeExpression(compiler.compile(), vars);
    Item item = (Item) msg.getItems().get(0);
    assertEquals("Some Item", item.getName());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

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