@Override @SuppressWarnings("unchecked") public Object eval(ScriptContext context) throws ScriptException { try { Map<String, Object> map = new HashMap<String, Object>(); for (Iterator it = context.getScopes().iterator(); it.hasNext();) { int scope = ((Integer) it.next()).intValue(); Bindings bindings = context.getBindings(scope); Set keys = bindings.keySet(); for (Object key : keys) { map.put((String) key, bindings.get(key)); } } return this.expression.execute(map); } catch (Exception e) { throw new ScriptException(e); } }
@Override public List<Integer> getScopes() { return context.getScopes(); } }
private Set<String> totalKeySet() { Set<String> keys = new HashSet<String>(); List<Integer> scopes = context.getScopes(); for (int i : scopes) { keys.addAll(context.getBindings(i).keySet()); } return Collections.unmodifiableSet(keys); }
private Set<Object> totalValueSet() { Set<Object> values = new HashSet<Object>(); List<Integer> scopes = context.getScopes(); for (int i : scopes) { values.addAll(context.getBindings(i).values()); } return Collections.unmodifiableSet(values); }
private Map<String, Object> totalMap() { Map<String, Object> map = new HashMap<String,Object>(); for (int i : context.getScopes()) if (null != context.getBindings(i)) map.putAll(context.getBindings(i)); return map; }
@Override public Object[] getIds() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } return list.toArray(new String[list.size()]); }
/** * Removes all mappings from this map (optional operation). * * @throws UnsupportedOperationException clear is not supported by this map. */ @Override public void clear() { for (int i : context.getScopes()) context.getBindings(i).clear(); }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); ScriptContext context = new SimpleScriptContext(); int scope = context.getScopes().get(0); context.setAttribute("japan", 100, scope); context.setAttribute("london", 10, scope); context.setAttribute("jhon", -10, scope); context.setAttribute("last", 1000, scope); String str = "usa_newyork= japan / london * 44 + jhon < last - 987"; Object usa_newyork = engine.eval(str, context); System.out.println(usa_newyork);
@Override @SuppressWarnings("unchecked") public Object eval(ScriptContext context) throws ScriptException { try { Map<String, Object> map = new HashMap<String, Object>(); for (Iterator it = context.getScopes().iterator(); it.hasNext();) { int scope = ((Integer) it.next()).intValue(); Bindings bindings = context.getBindings(scope); Set keys = bindings.keySet(); for (Object key : keys) { map.put((String) key, bindings.get(key)); } } return this.expression.execute(map); } catch (Exception e) { throw new ScriptException(e); } }
private Map<String, Object> getContextMatches(String start) { Map<String, Object> found = new HashMap<String, Object>(); if (context != null) { for (Integer scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); for (String var : bindings.keySet()) { if (var.startsWith(start)) { found.put(var, bindings.get(var)); } } } } //this was originally part of the code completor that lived in the CLI //I don't think we need it, because the services are present under the //same names in the context. This code can never add any new matches. /* if (services != null) { for (String var : services.keySet()) { if (var.startsWith(start)) { found.put(var, services.get(var)); } } } */ return found; }
Map<String, Object> found = new HashMap<String, Object>(); if (context != null) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); for (String var : bindings.keySet()) {
@Override public Object eval(ScriptContext context) throws ScriptException { final HashMap<String, Object> map = new HashMap<String, Object>(); final List<Integer> scopes = new ArrayList<Integer>(context.getScopes()); Collections.sort(scopes); // lowest scope at first pos Collections.reverse(scopes); // highest scope at first pos for (final Integer scope : scopes) { map.putAll(context.getBindings(scope)); } preparsed.setOut(toPrintStream(context.getWriter())); preparsed.setErr(toPrintStream(context.getErrorWriter())); try { return preparsed.invoke(map); } catch (final EvalError e) { throw constructScriptException(e); } }
this.printEngines(); else if (line.equals(Tokens.BINDINGS_DEBUG)) { for (int scope : this.mutant.getCurrentEngine().getEngine().getContext().getScopes()) { Bindings bindings = this.mutant.getCurrentEngine().getEngine().getContext().getBindings(scope); if (null != bindings) {
@ExposedMethod public PyObject scope_keys() { PyList members = new PyList(); List<Integer> scopes = context.getScopes(); for (int scope : scopes) { Bindings bindings = context.getBindings(scope); if (bindings == null) continue; for (String key : bindings.keySet()) members.append(new PyString(key)); } members.sort(); return members; }