Search in sources :

Example 61 with ExpressionCompiler

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

the class CoreConfidenceTests method testCompileParserContextShouldNotLoopIndefinitelyOnValidJavaExpression.

/**
 * Provided by: Phillipe Ombredanne
 */
public void testCompileParserContextShouldNotLoopIndefinitelyOnValidJavaExpression() {
    String expr = // 
    "		System.out.println( message );\n" + // 
    "m.setMessage( \"Goodbye cruel world\" );\n" + // 
    "System.out.println(m.getStatus());\n" + "m.setStatus( Message.GOODBYE );\n";
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(false);
    context.addImport("Message", Message.class);
    context.addInput("System", void.class);
    context.addInput("message", Object.class);
    context.addInput("m", Object.class);
    ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 62 with ExpressionCompiler

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

the class CoreConfidenceTests method testWhileUsingImports.

public void testWhileUsingImports() {
    Map<String, Object> imports = new HashMap<String, Object>();
    imports.put("ArrayList", java.util.ArrayList.class);
    imports.put("List", java.util.List.class);
    ParserContext context = new ParserContext(imports, null, "testfile");
    ExpressionCompiler compiler = new ExpressionCompiler("List list = new ArrayList(); return (list == empty)", context);
    assertTrue((Boolean) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory()));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) MapObject(org.mvel2.tests.core.res.MapObject) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 63 with ExpressionCompiler

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

the class CoreConfidenceTests method testTestIntToLong.

public void testTestIntToLong() {
    String s = "1+(long)a";
    ParserContext pc = new ParserContext();
    pc.addInput("a", Integer.class);
    ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
    CompiledExpression expr = compiler.compile();
    Map vars = new HashMap();
    vars.put("a", 1);
    Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
    assertEquals(new Long(2), r);
}
Also used : ExecutableStatement(org.mvel2.compiler.ExecutableStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) MapObject(org.mvel2.tests.core.res.MapObject) ParserContext(org.mvel2.ParserContext) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 64 with ExpressionCompiler

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

the class CoreConfidenceTests method testCompileWithNewInsideMethodCall.

public void testCompileWithNewInsideMethodCall() {
    String expr = "     p.name = \"goober\";\n" + "     System.out.println(p.name);\n" + "     drools.insert(new Address(\"Latona\"));\n";
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(false);
    context.addImport("Person", Person.class);
    context.addImport("Address", Address.class);
    context.addInput("p", Person.class);
    context.addInput("drools", Drools.class);
    ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
    compiler.compile();
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext)

Example 65 with ExpressionCompiler

use of org.mule.mvel2.compiler.ExpressionCompiler 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)

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