factory ListTree()

in lib/src/list_tree.dart [71:105]


  factory ListTree(AstNode glob, FileSystem fileSystem) {
    // The first step in constructing a tree from the glob is to simplify the
    // problem by eliminating options. [glob.flattenOptions] bubbles all options
    // (and certain ranges) up to the top level of the glob so we can deal with
    // them one at a time.
    var options = glob.flattenOptions();
    var trees = <String, _ListTreeNode>{};

    for (var option in options.options) {
      // Since each option doesn't include its own options, we can safely split
      // it into path components.
      var components = option.split(p.context);
      var firstNode = components.first.nodes.first;
      var root = '.';

      // Determine the root for this option, if it's absolute. If it's not, the
      // root's just ".".
      if (firstNode is LiteralNode) {
        var text = firstNode.text;
        // Platform agnostic way of checking for Windows without `dart:io`.
        if (p.context == p.windows) text.replaceAll('/', '\\');
        if (p.isAbsolute(text)) {
          // If the path is absolute, the root should be the only thing in the
          // first component.
          assert(components.first.nodes.length == 1);
          root = firstNode.text;
          components.removeAt(0);
        }
      }

      _addGlob(root, components, trees);
    }

    return ListTree._(trees, fileSystem);
  }