use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromMethod.
public final void testInferLastTypeParametersFromMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.values()").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
assertTrue("No type parameters detected", null != context.getLastTypeParameters());
assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromPropertyMethod.
public final void testInferLastTypeParametersFromPropertyMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.getFooMap()[\"key\"].someMethod()").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertEquals("Expression did not evaluate correctly: ", "bar", val);
assertNotNull("No type parameters detected", context.getLastTypeParameters());
assertEquals("Wrong parametric type inferred", String.class, context.getLastTypeParameters()[0]);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromProperty.
public final void testInferLastTypeParametersFromProperty() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.strings").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
assertTrue("No type parameters detected", null != context.getLastTypeParameters());
assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class ArraysTests method testArrayLength.
public void testArrayLength() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("x", String[].class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context);
}
use of org.mule.mvel2.ParserContext in project mvel by mikebrock.
the class ArraysTests method testArrayCoercion1.
public void testArrayCoercion1() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("bar", Bar.class);
Serializable s = compileSetExpression("bar.intarray[0]", ctx);
Foo foo = new Foo();
executeSetExpression(s, foo, "12");
assertEquals(12, foo.getBar().getIntarray()[0].intValue());
foo = new Foo();
executeSetExpression(s, foo, "13");
assertEquals(13, foo.getBar().getIntarray()[0].intValue());
OptimizerFactory.setDefaultOptimizer("ASM");
ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("bar", Bar.class);
s = compileSetExpression("bar.intarray[0]", ctx);
foo = new Foo();
executeSetExpression(s, foo, "12");
assertEquals(12, foo.getBar().getIntarray()[0].intValue());
executeSetExpression(s, foo, "13");
assertEquals(13, foo.getBar().getIntarray()[0].intValue());
}
Aggregations