package org.karaffe.compiler.tree;

import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

public interface Node extends Positioned {

  Tree getParent();

  void addChild(Tree child);

  NodeType getNodeType();

  List<Tree> getChildren();

  boolean hasChildren();

  default Optional<Tree> findFirstFromChildren(Predicate<Tree> p) {
    return this.getChildren().stream().filter(p).findFirst();
  }

  default Optional<Tree> findFirstFromChildren(NodeType nodeType) {
    return findFirstFromChildren(p -> p.getNodeType().equals(nodeType));
  }

  default boolean hasChildren(NodeType nodeType) {
    return findFirstFromChildren(p -> p.getNodeType().equals(nodeType)).isPresent();
  }

  default int indexOf(NodeType nodeType) {
    return this.getChildren().indexOf(this.findFirstFromChildren(nodeType).orElse(null));
  }

  void replaceThis(Tree after);

  void addAllChildren(List<Tree> children);
}

@@ -115,16 +115,52 @@
 edicate;
+%0Aimport java.util.stream.Collectors;
 %0A%0Apublic
@@ -603,32 +603,316 @@
 odeType));%0A  %7D%0A%0A
+  default List%3CTree%3E findAllFromChildren(Predicate%3CTree%3E p) %7B%0A    return this.getChildren().stream().filter(p).collect(Collectors.toList());%0A  %7D%0A%0A  default List%3CTree%3E findAllFromChildren(NodeType nodeType) %7B%0A    return findAllFromChildren(p -%3E p.getNodeType().equals(nodeType));%0A  %7D%0A%0A
   default boolea

Add Node#findAllFromChildren