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();
}
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()));
}
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);
}
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();
}
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();
}
Aggregations