use of org.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.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.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.mvel2.ParserContext in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrongTyping3.
public void testStrongTyping3() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
new ExpressionCompiler("foo.toUC(100.5").compile(ctx);
} catch (Exception e) {
// should fail.
return;
}
assertTrue(false);
}
use of org.mvel2.ParserContext in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrictTypingCompilation3.
public void testStrictTypingCompilation3() throws NoSuchMethodException {
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler("message='Hello';b=7;\nSystem.out.println(message + ';' + b);\n" + "System.out.println(message + ';' + b); b");
assertEquals(7, executeExpression(compiler.compile(ctx), new DefaultLocalVariableResolverFactory()));
}
Aggregations