visitChildren method

T? visitChildren(
  1. RuleNode node
)

{@inheritDoc}

The default implementation initializes the aggregate result to {@link #defaultResult defaultResult()}. Before visiting each child, it calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result is [false] no more children are visited and the current aggregate result is returned. After visiting a child, the aggregate result is updated by calling {@link #aggregateResult aggregateResult} with the previous aggregate result and the result of visiting the child.

The default implementation is not safe for use in visitors that modify the tree structure. Visitors that modify the tree should override this method to behave properly in respect to the specific algorithm in use.

Implementation

T? visitChildren(RuleNode node) {
  var result = defaultResult();
  final n = node.childCount;
  for (var i = 0; i < n; i++) {
    if (!shouldVisitNextChild(node, result)) {
      break;
    }

    final c = node.getChild(i)!;
    final childResult = c.accept(this);
    result = aggregateResult(result, childResult);
  }

  return result;
}