hierarchy method Null safety

Iterable<Module> hierarchy()

Returns an Iterable of Modules representing the hierarchical path to this Module.

The first element of the Iterable is the top-most hierarchy. The last element of the Iterable is this Module. Only returns valid information after build.

Implementation

Iterable<Module> hierarchy() {
  if (!hasBuilt) {
    throw ModuleNotBuiltException(
        'Module must be built before accessing hierarchy.'
        '  Call build() before executing this.');
  }
  Module? pModule = this;
  final hierarchyQueue = Queue<Module>();
  while (pModule != null) {
    hierarchyQueue.addFirst(pModule);
    pModule = pModule.parent;
  }
  return hierarchyQueue;
}