use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class WithTests method testWithAndEnumInPackageImport.
public void testWithAndEnumInPackageImport() {
ParserConfiguration pconf = new ParserConfiguration();
pconf.addPackageImport(MyEnum.class.getPackage().getName());
ParserContext pCtx = new ParserContext(pconf);
pCtx.setStrongTyping(true);
pCtx.addInput("thing", Thing.class);
Thing thing = new Thing("xxx");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("thing", thing);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("with( thing ) { myEnum = MyEnum.FULL_DOCUMENTATION }", pCtx);
MVEL.executeExpression(stmt, null, vars);
assertEquals(MyEnum.FULL_DOCUMENTATION, thing.getMyEnum());
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class CoreConfidenceTests method testNestedNumInMapKey.
public void testNestedNumInMapKey() {
String str = "objectKeyMaptributes[Triangle.Foo.OBTUSE]";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport("Triangle", Triangle.class);
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Person.class);
pctx.setStrongTyping(true);
Foo foo = new Foo();
Person p = new Person();
Map<Object, Foo> map = new HashMap<Object, Foo>();
map.put(Triangle.Foo.OBTUSE, foo);
p.setObjectKeyMaptributes(map);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Object o = MVEL.executeExpression(stmt, p, new HashMap());
}
use of org.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class CoreConfidenceTests method testNestedClassWithNestedGenericsOnNakedMethod.
public void testNestedClassWithNestedGenericsOnNakedMethod() {
String str = "deliveries.size";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Triangle.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertEquals(Integer.valueOf(0), (Integer) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
str = "deliveries.size == 0";
stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertTrue((Boolean) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
use of org.mvel2.compiler.ExecutableStatement 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.mvel2.compiler.ExecutableStatement in project mvel by mikebrock.
the class CoreConfidenceTests method testArrayLength.
// public void testStaticImportWithWildcard() {
// // this isn't supported yet
// assertEquals("hello",
// test("import_static " + getClass().getName() + ".StaticClassWithStaticMethod.*; getString()"));
// }
public void testArrayLength() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("x", String[].class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression("x.length", context);
}
Aggregations