use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class TypesAndInferenceTests method testEgressTypeCorrect.
public void testEgressTypeCorrect() {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("type", ParserContext.create().stronglyTyped().withInput("this", Cheese.class));
assertEquals(String.class, stmt.getKnownEgressType());
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class TypesAndInferenceTests method testGenerics1.
public void testGenerics1() {
String str = "addresses[0] == new Address(\"s1\") && addresses[0].street == new Address(\"s1\").street";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", PersonAddresses.class);
pctx.addImport(Address.class);
pctx.addImport(PersonAddresses.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
PersonAddresses ctx = new PersonAddresses();
ctx.getAddresses().add(new Address("s1"));
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class TypesAndInferenceTests method testEgressTypeCorrect2.
public void testEgressTypeCorrect2() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("this", SampleBean.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("( map2[ 'yyy' ] )", context);
SampleBean s = new SampleBean();
s.getMap2().put("yyy", 1);
assertEquals(new Integer(1), MVEL.executeExpression(stmt, s));
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class TypesAndInferenceTests method testContextMethodCallsInStrongMode.
public void testContextMethodCallsInStrongMode() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("this", EchoContext.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("this.echo( 'Mac')", context);
stmt = (ExecutableStatement) MVEL.compileExpression("echo( 'Mac')", context);
assertEquals("Mac", MVEL.executeExpression(stmt, new EchoContext()));
}
Aggregations