use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testJIRA168.
public void testJIRA168() {
boolean before = MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL;
try {
Map<String, Object> st = new HashMap<String, Object>();
st.put("__fact__", new ArrayList());
st.put("__expected__", 0);
String expressionNaked = "__fact__.size == __expected__";
String expressionNonNaked = "__fact__.size() == __expected__";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
// the following works fine
ParserContext ctx = new ParserContext();
for (Map.Entry<String, Object> entry : st.entrySet()) {
ctx.addInput(entry.getKey(), entry.getValue().getClass());
}
CompiledExpression expr = new ExpressionCompiler(expressionNaked, ctx).compile();
Boolean result = (Boolean) executeExpression(expr, st);
assertTrue(result);
// the following works fine
result = (Boolean) MVEL.eval(expressionNonNaked, st);
assertTrue(result);
// the following fails
result = (Boolean) MVEL.eval(expressionNaked, st);
assertTrue(result);
} finally {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = before;
}
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testStrictTypingCompilation.
public void testStrictTypingCompilation() {
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("a.foo;\nb.foo;\n x = 5", ctx);
try {
compiler.compile();
} catch (CompileException e) {
e.printStackTrace();
return;
}
assertTrue(false);
// OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImportsWithNullConstructorParamWithStrongType.
public void testDynamicImportsWithNullConstructorParamWithStrongType() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", null)", ctx);
Cheesery p1 = new Cheesery("bobbo", null);
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
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, ctx);
Serializable s = compiler.compile();
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);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mvel.
the class CoreConfidenceTests method testArray.
public void testArray() {
String ex = " TestHelper.method(1, new String[]{\"a\", \"b\"});\n" + " TestHelper.method(2, new String[]{new String(\"a\"), new String(\"b\")});\n" + " TestHelper.method(3, new Fooz[]{new Fooz(\"a\"), new Fooz(\"b\")});";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport(TestHelper.class);
ctx.addImport(Fooz.class);
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
OptimizerFactory.setDefaultOptimizer("ASM");
CompiledExpression expr = compiler.compile();
executeExpression(expr);
OptimizerFactory.setDefaultOptimizer("reflective");
expr = compiler.compile();
executeExpression(expr);
}
Aggregations