enclosingProgram property

Program? get enclosingProgram

Returns the Program node enclosing this node, possibly the node itself, or null if not enclosed in any program.

Implementation

Program? get enclosingProgram {
  Node? node = this;
  while (node != null) {
    if (node is Program) return node;
    node = node.parent;
  }
  return null;
}