use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class WithTests method testInlineWith2.
public void testInlineWith2() {
CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}}").compile();
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
assertEquals("foobie", f.getBar().getName());
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testDetermineEgressParametricType2.
public final void testDetermineEgressParametricType2() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("strings", List.class, new Class[] { String.class });
final CompiledExpression expr = new ExpressionCompiler("strings", parserContext).compile();
assertTrue(STRINGS.equals(executeExpression(expr, new A())));
final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
assertTrue(null != typeParameters);
assertTrue(String.class.equals(typeParameters[0]));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL236.
public void testMVEL236() {
StringBuffer buffer = new StringBuffer();
buffer.append("MyInterface2 var2 = (MyInterface2)var1;");
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("var1", MyInterface3.class);
ctx.addImport(MyInterface2.class);
ctx.addImport(MyInterface3.class);
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
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).compile(ctx);
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.CompiledExpression in project mvel by mikebrock.
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);
OptimizerFactory.setDefaultOptimizer("ASM");
CompiledExpression expr = compiler.compile(ctx);
executeExpression(expr);
OptimizerFactory.setDefaultOptimizer("reflective");
expr = compiler.compile(ctx);
executeExpression(expr);
}
Aggregations