thisOrAncestorMatching<E extends AstNode> method

  1. @override
E? thisOrAncestorMatching<E extends AstNode>(
  1. bool predicate(
    1. AstNode
    )
)
override

Return either this node or the most immediate ancestor of this node for which the predicate returns true, or null if there is no such node.

Implementation

@override
E? thisOrAncestorMatching<E extends AstNode>(
  bool Function(AstNode) predicate,
) {
  AstNode? node = this;
  while (node != null && !predicate(node)) {
    node = node.parent;
  }
  return node as E?;
}