Ejemplo n.º 1
0
 public <A, S extends A> SysExpr addUniversalListener(
     Class<S> argType, In2Out1<Node, A, Do> callback) {
   final In2Out1<Node, Object, Do> was = universalListener;
   universalListener =
       (node, arg) -> {
         final Do toUndo = was.io(node, arg);
         if (argType.isInstance(arg) || arg == null) {
           final Do undo = callback.io(node, (A) arg);
           return toUndo.doAfter(undo);
         }
         return toUndo;
       };
   return this;
 }
Ejemplo n.º 2
0
 public <A, R> R readAsOneNode(In2Out1<Node, A, R> callback, A arg) {
   if (nodes.length == 1) {
     final Node node = nodes[0].out1();
     try (Do undo = universalListener.io(node, arg)) {
       R r = callback.io(node, arg);
       return r;
     }
   }
   JsonContainerExpr json = JsonContainerExpr.jsonArray(nodes().map(n -> (Expression) n));
   try (Do undo = universalListener.io(json, arg)) {
     R r = callback.io(json, arg);
     return r;
   }
 }
Ejemplo n.º 3
0
 public <A, Vis extends VoidVisitor<A>> In3<Vis, Node, A> voidVisit(Vis vis, A arg) {
   final In3 factory = voidFactory.io(vis, arg);
   return (v, n, a) -> {
     try (Do undo = universalListener.io(n, a)) {
       factory.in(v, n, a);
     }
   };
 }
Ejemplo n.º 4
0
 public <A, R, Vis extends GenericVisitor<R, A>> In3Out1<Vis, Node, A, R> genericVisit(
     Vis vis, A arg) {
   final In3Out1 factory = genericFactory.io(vis, arg);
   return (v, n, a) -> {
     try (Do undo = universalListener.io(n, a)) {
       return (R) factory.io(v, n, a);
     }
   };
 }
Ejemplo n.º 5
0
 public <A> SysExpr readNodesWhile(Filter1<Node> filter, In1<Node> callback, A arg) {
   for (Out1<Node> node : nodes) {
     final Node n = node.out1();
     if (filter.filter1(n)) {
       try (final Do undo = universalListener.io(n, arg)) {
         callback.in(n);
       }
     } else {
       return this;
     }
   }
   return this;
 }