use of org.mvel2.ParserContext in project mvel by mikebrock.
the class CoreConfidenceTests method testDynamicImportsWithIdentifierSameAsClassWithDiffCase.
public void testDynamicImportsWithIdentifierSameAsClassWithDiffCase() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("org.mvel2.tests.core.res");
ctx.setStrictTypeEnforcement(false);
ExpressionCompiler compiler = new ExpressionCompiler("bar.add(\"hello\")");
compiler.compile(ctx);
}
use of org.mvel2.ParserContext 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.ParserContext in project mvel by mikebrock.
the class CoreConfidenceTests method testTestIntToLong.
public void testTestIntToLong() {
String s = "1+(long)a";
ParserContext pc = new ParserContext();
pc.addInput("a", Integer.class);
ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
CompiledExpression expr = compiler.compile();
Map vars = new HashMap();
vars.put("a", 1);
Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
assertEquals(new Long(2), r);
}
use of org.mvel2.ParserContext 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.ParserContext in project mvel by mikebrock.
the class VariableSpaceCompiler method compileShared.
public static SharedVariableSpaceModel compileShared(String expr, ParserContext pCtx, Object[] vars) {
String[] varNames = pCtx.getIndexedVarNames();
ParserContext analysisContext = ParserContext.create();
analysisContext.setIndexAllocation(true);
MVEL.analysisCompile(expr, analysisContext);
Set<String> localNames = analysisContext.getVariables().keySet();
pCtx.addIndexedLocals(localNames);
String[] locals = localNames.toArray(new String[localNames.size()]);
String[] allVars = new String[varNames.length + locals.length];
System.arraycopy(varNames, 0, allVars, 0, varNames.length);
System.arraycopy(locals, 0, allVars, varNames.length, locals.length);
return new SharedVariableSpaceModel(allVars, vars);
}
Aggregations