use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class TypesAndInferenceTests method testAutoBoxing2.
public void testAutoBoxing2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("base", Base.class);
Serializable s = compileExpression("java.util.List list = new java.util.ArrayList(); " + "list.add( base.intValue ); list", ctx);
Map vars = new HashMap();
vars.put("base", new Base());
List list = (List) executeExpression(s, vars);
assertEquals(1, list.size());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class TypesAndInferenceTests method testAnalyzer.
public void testAnalyzer() {
ParserContext ctx = new ParserContext();
MVEL.compileExpression("order.id == 10", ctx);
for (String input : ctx.getInputs().keySet()) {
System.out.println("input>" + input);
}
assertEquals(1, ctx.getInputs().size());
assertTrue(ctx.getInputs().containsKey("order"));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class TypesAndInferenceTests method testDataConverterStrictMode.
public void testDataConverterStrictMode() throws Exception {
OptimizerFactory.setDefaultOptimizer("ASM");
DataConversion.addConversionHandler(Date.class, new MVELDateCoercion());
ParserContext ctx = new ParserContext();
ctx.addImport("Cheese", Cheese.class);
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
Locale.setDefault(Locale.US);
Cheese expectedCheese = new Cheese();
expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c", ctx);
Cheese actualCheese = (Cheese) executeExpression(compiler.compile(), createTestMap());
assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class TypesAndInferenceTests method testStaticFieldAccessForInputs.
public void testStaticFieldAccessForInputs() {
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
ParserContext pCtx = ParserContext.create();
MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);
assertFalse(pCtx.getInputs().containsKey("java"));
assertEquals(0, pCtx.getInputs().size());
// MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
//
// pCtx = ParserContext.create();
// MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx);
//
// assertFalse(pCtx.getInputs().containsKey("java"));
//
// assertEquals(0,
// pCtx.getInputs().size());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class TypesAndInferenceTests method testGenericInference.
public void testGenericInference() {
String expression = "$result = person.footributes[0].name";
ParserContext ctx;
MVEL.analysisCompile(expression, ctx = ParserContext.create().stronglyTyped().withInput("person", Person.class));
assertEquals(String.class, ctx.getVarOrInputTypeOrNull("$result"));
Serializable s = MVEL.compileExpression(expression, ParserContext.create().stronglyTyped().withInput("person", Person.class));
Map<String, Object> vars = new HashMap<String, Object>();
Person p = new Person();
p.setFootributes(new ArrayList<Foo>());
p.getFootributes().add(new Foo());
vars.put("person", p);
assertEquals("dog", executeExpression(s, vars));
}
Aggregations