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; }
public VariableResolver createVariable(String name, Object value, Class<?> type) { if (indexedVariableNames == null) return super.createVariable(name, value, type); VariableResolver vr; boolean newVar = false; try { int idx; if ((idx = variableIndexOf(name)) != -1) { vr = new SimpleValueResolver(value); if (indexedVariableResolvers[idx] == null) { indexedVariableResolvers[idx] = vr; } variableResolvers.put(indexedVariableNames[idx], vr); vr = indexedVariableResolvers[idx]; newVar = true; } else { return super.createVariable(name, value, type); } } catch (UnresolveablePropertyException e) { vr = null; } if (!newVar && vr != null && vr.getType() != null) { throw new RuntimeException("variable already defined within scope: " + vr.getType() + " " + name); } else { addResolver(name, vr = new MapVariableResolver(variables, name, type)).setValue(value); return vr; } }
public VariableResolver getVariableResolver(String name) { if (indexedVariableNames == null) return super.getVariableResolver(name); int idx; // if (variableResolvers.containsKey(name)) return variableResolvers.get(name); if ((idx = variableIndexOf(name)) != -1) { if (indexedVariableResolvers[idx] == null) { indexedVariableResolvers[idx] = new SimpleValueResolver(null); } variableResolvers.put(indexedVariableNames[idx], null); return indexedVariableResolvers[idx]; } return super.getVariableResolver(name); }
public VariableResolver getVariableResolver(String name) { if (indexedVariableNames == null) return super.getVariableResolver(name); int idx; // if (variableResolvers.containsKey(name)) return variableResolvers.get(name); if ((idx = variableIndexOf(name)) != -1) { if (indexedVariableResolvers[idx] == null) { indexedVariableResolvers[idx] = new SimpleValueResolver(null); } variableResolvers.put(indexedVariableNames[idx], null); return indexedVariableResolvers[idx]; } return super.getVariableResolver(name); }
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; }
public VariableResolver createVariable(String name, Object value, Class<?> type) { if (indexedVariableNames == null) return super.createVariable(name, value, type); VariableResolver vr; boolean newVar = false; try { int idx; if ((idx = variableIndexOf(name)) != -1) { vr = new SimpleValueResolver(value); if (indexedVariableResolvers[idx] == null) { indexedVariableResolvers[idx] = vr; } variableResolvers.put(indexedVariableNames[idx], vr); vr = indexedVariableResolvers[idx]; newVar = true; } else { return super.createVariable(name, value, type); } } catch (UnresolveablePropertyException e) { vr = null; } if (!newVar && vr != null && vr.getType() != null) { throw new RuntimeException("variable already defined within scope: " + vr.getType() + " " + name); } else { addResolver(name, vr = new MapVariableResolver(variables, name, type)).setValue(value); return vr; } }
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; }
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; }
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 FastList(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 FastList(col.size()); for (Object o : col) { list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory)); } } return list; }
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())); list = new FastList(((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())); list = new FastList(((Collection) x).size()); for (Object o : (Collection) x) { list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory)); } } return list; }
public Object call(Object ctx, Object thisValue, VariableResolverFactory factory, Object[] parms) { if (parms != null && parms.length != 0) { // detect tail recursion if (factory instanceof FunctionVariableResolverFactory && ((FunctionVariableResolverFactory) factory).getIndexedVariableResolvers().length == parms.length) { FunctionVariableResolverFactory fvrf = (FunctionVariableResolverFactory) factory; if (fvrf.getFunction().equals(this)) { VariableResolver[] swapVR = fvrf.getIndexedVariableResolvers(); fvrf.updateParameters(parms); try { return compiledBlock.getValue(ctx, thisValue, fvrf); } finally { fvrf.setIndexedVariableResolvers(swapVR); } } } return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new FunctionVariableResolverFactory(this, factory, parameters, parms))); } else if (compiledMode) { return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new DefaultLocalVariableResolverFactory(factory, parameters))); } else { return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new DefaultLocalVariableResolverFactory(factory, parameters))); } }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public Object call(Object ctx, Object thisValue, VariableResolverFactory factory, Object[] parms) { if (parms != null && parms.length != 0) { // detect tail recursion if (factory instanceof FunctionVariableResolverFactory && ((FunctionVariableResolverFactory) factory).getIndexedVariableResolvers().length == parms.length) { FunctionVariableResolverFactory fvrf = (FunctionVariableResolverFactory) factory; if (fvrf.getFunction().equals(this)) { VariableResolver[] swapVR = fvrf.getIndexedVariableResolvers(); fvrf.updateParameters(parms); try { return compiledBlock.getValue(ctx, thisValue, fvrf); } finally { fvrf.setIndexedVariableResolvers(swapVR); } } } return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new FunctionVariableResolverFactory(this, factory, parameters, parms))); } else if (compiledMode) { return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new DefaultLocalVariableResolverFactory(factory, parameters))); } else { return compiledBlock.getValue(thisValue, new StackDemarcResolverFactory(new DefaultLocalVariableResolverFactory(factory, parameters))); } }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public void testWhileUsingImports() { Map<String, Object> imports = new HashMap<String, Object>(); imports.put("ArrayList", java.util.ArrayList.class); imports.put("List", java.util.List.class); ParserContext context = new ParserContext(imports, null, "testfile"); ExpressionCompiler compiler = new ExpressionCompiler("List list = new ArrayList(); return (list == empty)", context); assertTrue((Boolean) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory())); }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item); ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
public void testDynamicImports3() { String expression = "import java.util.*; HashMap map = new HashMap(); map.size()"; ExpressionCompiler compiler = new ExpressionCompiler(expression); Serializable s = compiler.compile(); assertEquals(0, executeExpression(s, new DefaultLocalVariableResolverFactory())); assertEquals(0, MVEL.eval(expression, new HashMap())); }