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); }
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); }
public static SimpleVariableSpaceModel compile(String expr, ParserContext pCtx) { 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 SimpleVariableSpaceModel(allVars); } }
public static SimpleVariableSpaceModel compile(String expr, ParserContext pCtx) { 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 SimpleVariableSpaceModel(allVars); } }
public void testTypeVarDeclr() { String ex = "String a;"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); compiler.compile(); assertNotNull(ctx.getVariables()); assertEquals(1, ctx.getVariables().entrySet().size()); for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) { assertEquals(String.class, entry.getValue()); } }
public void testMultiTypeVarDeclr() { String ex = "String a, b, c"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); compiler.compile(); assertNotNull(ctx.getVariables()); assertEquals(3, ctx.getVariables().entrySet().size()); for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) { assertEquals(String.class, entry.getValue()); } }
public void testMultiTypeVarDeclr2() { String ex = "String a = 'foo', b = 'baz', c = 'bar'"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); compiler.compile(); assertNotNull(ctx.getVariables()); assertEquals(3, ctx.getVariables().entrySet().size()); for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) { assertEquals(String.class, entry.getValue()); } }
if (pCtx.getVariables() != null) { for (Map.Entry<String, Class> e : pCtx.getVariables().entrySet()) { ctx.addInput(e.getKey(), e.getValue()); ctx.addIndexedVariables(ctx.getVariables().keySet()); ctx.getVariables().clear();
if (pCtx.getVariables() != null) { for (Map.Entry<String, Class> e : pCtx.getVariables().entrySet()) { ctx.getVariables().remove(e.getKey()); ctx.addInput(e.getKey(), e.getValue()); ctx.addIndexedInputs(ctx.getVariables().keySet()); ctx.getVariables().clear();
public void testGetCorrectInputs() { String str = "total = total + $cheese.price"; ParserConfiguration pconf = new ParserConfiguration(); ParserContext pctx = new ParserContext(pconf); pctx.setStrongTyping(true); pctx.addInput("total", int.class); pctx.addInput("$cheese", Cheese.class); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); assertTrue("Should not contain" + pctx.getVariables(), pctx.getVariables().isEmpty()); }
public void testMultiTypeVarDeclr3() { String ex = "int a = 52 * 3, b = 8, c = 16;"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); Serializable s = compiler.compile(); assertNotNull(ctx.getVariables()); assertEquals(3, ctx.getVariables().entrySet().size()); for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) { assertEquals(int.class, entry.getValue()); } Map vars = new HashMap(); executeExpression(s, vars); assertEquals(52 * 3, vars.get("a")); assertEquals(8, vars.get("b")); assertEquals(16, vars.get("c")); }
public void testMultiVarDeclr() { String ex = "var a, b, c"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); compiler.setVerifyOnly(true); compiler.compile(); assertEquals(3, ctx.getVariables().size()); }
public void testVarDeclr() { String ex = "var a"; ParserContext ctx = new ParserContext(); ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx); compiler.setVerifyOnly(true); compiler.compile(); assertEquals(1, ctx.getVariables().size()); }
public void testAnalysisCompile() { ParserContext pCtx = new ParserContext(); ExpressionCompiler e = new ExpressionCompiler("foo.aValue = 'bar'", pCtx); e.setVerifyOnly(true); e.compile(); assertTrue(pCtx.getInputs().keySet().contains("foo")); assertEquals(1, pCtx.getInputs().size()); assertEquals(0, pCtx.getVariables().size()); }
public void testVarInputs() { ParserContext pCtx = ParserContext.create(); MVEL.analysisCompile("test != foo && bo.addSomething(trouble) " + "&& 1 + 2 / 3 == 1; String bleh = foo; twa = bleh;", pCtx); assertEquals(4, pCtx.getInputs().size()); assertTrue(pCtx.getInputs().containsKey("test")); assertTrue(pCtx.getInputs().containsKey("foo")); assertTrue(pCtx.getInputs().containsKey("bo")); assertTrue(pCtx.getInputs().containsKey("trouble")); assertEquals(2, pCtx.getVariables().size()); assertTrue(pCtx.getVariables().containsKey("bleh")); assertTrue(pCtx.getVariables().containsKey("twa")); assertEquals(String.class, pCtx.getVarOrInputType("bleh")); }
public void testVarInputs5() { ParserContext pCtx = ParserContext.create().withInput("list", List.class); MVEL.analysisCompile("String nodeName = list[0];\nSystem.out.println(nodeName);nodeName = list[1];\nSystem.out.println(nodeName);", pCtx); assertEquals(1, pCtx.getInputs().size()); assertTrue(pCtx.getInputs().containsKey("list")); assertEquals(1, pCtx.getVariables().size()); assertTrue(pCtx.getVariables().containsKey("nodeName")); assertEquals(List.class, pCtx.getVarOrInputType("list")); assertEquals(String.class, pCtx.getVarOrInputType("nodeName")); }
public void testStrictTypingCompilation4() throws NoSuchMethodException { ParserContext ctx = new ParserContext(); ctx.addImport(Foo.class); ctx.setStrictTypeEnforcement(true); ExpressionCompiler compiler = new ExpressionCompiler("x_a = new Foo()", ctx); compiler.compile(); assertEquals(Foo.class, ctx.getVariables().get("x_a")); }
languageLevel ); Set<String> localNames = parserContext.getVariables().keySet();
if (pCtx != spCtx) pCtx.addVariables(spCtx.getVariables()); varsEscape = true; pCtx.addVariables(spCtx.getVariables());
if (pCtx != spCtx) pCtx.addVariables(spCtx.getVariables()); varsEscape = true; pCtx.addVariables(spCtx.getVariables());