use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory 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()));
}
use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testDynamicImports.
public void testDynamicImports() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("java.util");
ExpressionCompiler compiler = new ExpressionCompiler("HashMap");
Serializable s = compiler.compile(ctx);
assertEquals(HashMap.class, executeExpression(s));
compiler = new ExpressionCompiler("map = new HashMap(); map.size()");
s = compiler.compile(ctx);
assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory()));
}
use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.
the class CoreConfidenceTests method testDynamicImportsOnNestedExpressions.
public void testDynamicImportsOnNestedExpressions() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", new Cheese(\"cheddar\", 15))");
Cheesery p1 = new Cheesery("bobbo", new Cheese("cheddar", 15));
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(ctx), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.
the class Fold method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
List list;
if (constraintEx != null) {
Collection col = ((Collection) dataEx.getValue(ctx, thisValue, factory));
list = new ArrayList(col.size());
for (Object o : col) {
itemR.value = o;
if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
list.add(subEx.getValue(o, thisValue, itemFactory));
}
}
} else {
Collection col = ((Collection) dataEx.getValue(ctx, thisValue, factory));
list = new ArrayList(col.size());
for (Object o : col) {
list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
}
}
return list;
}
use of org.mvel2.integration.impl.DefaultLocalVariableResolverFactory in project mvel by mikebrock.
the class Fold method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
List list;
if (constraintEx != null) {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
itemR.value = o;
if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
list.add(subEx.getValue(o, thisValue, itemFactory));
}
}
} else {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
}
}
return list;
}
Aggregations