use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class WithTests method testInlineWith5.
public void testInlineWith5() {
OptimizerFactory.setDefaultOptimizer("ASM");
ParserContext pCtx = new ParserContext();
pCtx.setStrongTyping(true);
pCtx.addInput("foo", Foo.class);
CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile(pCtx);
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class MutationsTests method testDeepAssignment2.
public void testDeepAssignment2() {
Map map = createTestMap();
ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
ParserContext ctx = new ParserContext();
ctx.addInput("foo", Foo.class);
ctx.setStrongTyping(true);
CompiledExpression ce = compiler.compile(ctx);
executeExpression(ce, map);
assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class MutationsTests method testUnQualifiedStaticTyping.
public void testUnQualifiedStaticTyping() {
CompiledExpression ce = (CompiledExpression) compileExpression("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ");
assertEquals(new BigDecimal(20), testCompiledSimple("import java.math.BigDecimal; BigDecimal a = new BigDecimal( 10.0 ); BigDecimal b = new BigDecimal( 10.0 ); BigDecimal c = a + b; return c; ", new HashMap()));
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL228.
public void testMVEL228() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
HashMap<String, Class> params = new HashMap<String, Class>();
params.put("helper", ScriptHelper228.class);
params.put("person", Person228.class);
ctx.setInputs(params);
String script = "helper.methodB(2);\n" + "person.getName2();";
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx);
} catch (Exception e) {
return;
}
fail("Should have thrown an exception");
}
use of org.mvel2.compiler.CompiledExpression in project mvel by mikebrock.
the class TypesAndInferenceTests method testMVEL234.
public void testMVEL234() {
StringBuffer buffer = new StringBuffer();
buffer.append("import java.text.SimpleDateFormat;");
buffer.append("if (\"test\".matches(\"[0-9]\")) {");
buffer.append(" return false;");
buffer.append("}else{");
buffer.append(" SimpleDateFormat sqf = new SimpleDateFormat(\"yyyyMMdd\");");
buffer.append("}");
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
try {
CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations