thisOrAncestorOfType<E extends AstNode> method

  1. @override
E? thisOrAncestorOfType<E extends AstNode>()
override

Return either this node or the most immediate ancestor of this node that has the given type, or null if there is no such node.

Implementation

@override
E? thisOrAncestorOfType<E extends AstNode>() {
  AstNode? node = this;
  while (node != null && node is! E) {
    node = node.parent;
  }
  return node as E?;
}