MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / call_runnable

Method call_runnable

src/main/java/fieldbox/boxes/Callbacks.java:187–287  ·  view source on GitHub ↗
(Box box, Dict.Prop<IdempotencyMap<Runnable>> main, Object argMap, boolean evalIfNull, Function<Box, Collection<Box>> direction)

Source from the content-addressed store, hash-verified

185 public static Object call(Box box, Dict.Prop<IdempotencyMap<Supplier<Object>>> main, Object argMap) {
186 return call(box, main, argMap, true, box.upwards());
187 }
188
189 public static void call_runnable(Box box, Dict.Prop<IdempotencyMap<Runnable>> main, Object argMap, boolean evalIfNull, Function<Box, Collection<Box>> direction) {
190 Map<String, Object> undoMap = new LinkedHashMap<>();
191
192 Object ret = null;
193
194 boolean success = false;
195 try {
196 Map<?, ?> m = null;
197
198 Class c = argMap == null ? null : argMap.getClass();
199
200 // todo: these should be set (and restored) all the way up the chain no? Or perhaps we should set and restore them on _root instead...
201 // let's proceed with root
202
203 Box root = box.find(Boxes.root, box.upwards())
204 .findFirst()
205 .orElseThrow(() -> new IllegalArgumentException("can't execute a box not connected to the graph"));
206
207 if (argMap instanceof Map) {
208 m = (Map<?, ?>) Conversions.convert(argMap, Map.class);
209 for (Map.Entry<?, ?> e : m.entrySet()) {
210 Object was = root.properties.get(new Dict.Prop("" + e.getKey()));
211 if (root.properties.has(new Dict.Prop("" + e.getKey())))
212 undoMap.put("" + e.getKey(), was);
213 root.asMap_set("" + e.getKey(), e.getValue());
214 }
215 {
216 Object was = root.properties.get(new Dict.Prop("_origin"));
217 if (root.properties.has(new Dict.Prop("_origin"))) undoMap.put("_origin", was);
218 root.asMap_set("_origin", box);
219 }
220 } else {
221 Dict.Prop arg = new Dict.Prop("arg");
222 if (root.properties.has(arg)) undoMap.put("arg", root.properties.get(arg));
223 root.asMap_set("arg", argMap);
224 }
225
226 success = true;
227
228 try {
229
230 if (evalIfNull && (!box.properties.has(main) || box.properties.get(main)
231 .values()
232 .size() == 0)) {
233 if (Execution.context.get()
234 .stream()
235 .filter(x -> x == box)
236 .count() > 1 && !box.properties.isTrue(new Dict.Prop("recur"), false))
237 return;
238
239// String code = box.properties.get(Execution.code);
240 String code = DisabledRangeHelper.getStringWithDisabledRanges(box, Execution.code, "/* -- start -- ", "-- end -- */");
241 if (code != null) box.first(Execution.execution)
242 .map(x -> x.support(box, Execution.code))
243 .filter(x -> x != null)
244 .ifPresent(x -> x.executeAll(code, box));

Callers 1

compileDocumentMethod · 0.95

Calls 15

convertMethod · 0.95
asMap_setMethod · 0.95
logMethod · 0.95
upwardsMethod · 0.80
countMethod · 0.80
isTrueMethod · 0.80
firstMethod · 0.80
putAllMethod · 0.80
tryToReportToMethod · 0.80
getMethod · 0.65
executeAllMethod · 0.65

Tested by

no test coverage detected