referenceBy method

  1. @nonVirtual
CommentReferable? referenceBy(
  1. List<String> reference,
  2. {required bool filter(
    1. CommentReferable?
    ),
  3. required bool allowTree(
    1. CommentReferable?
    ),
  4. bool tryParents = true,
  5. Iterable<CommentReferable>? parentOverrides}
)
inherited

Look up a comment reference by its component parts.

If tryParents is true, try looking up the same reference in any parents of this. Will skip over results that do not pass a given filter and keep searching. Will skip over entire subtrees whose parent node does not pass allowTree.

Implementation

@nonVirtual
CommentReferable? referenceBy(
  List<String> reference, {
  required bool Function(CommentReferable?) filter,
  required bool Function(CommentReferable?) allowTree,
  bool tryParents = true,
  Iterable<CommentReferable>? parentOverrides,
}) {
  parentOverrides ??= referenceParents;
  if (reference.isEmpty) {
    return tryParents ? null : this;
  }

  for (var referenceLookup in _childLookups(reference)) {
    if (scope != null) {
      var result = _lookupViaScope(referenceLookup,
          filter: filter, allowTree: allowTree);
      if (result != null) {
        return result;
      }
    }
    final referenceChildren = this.referenceChildren;
    final childrenResult = referenceChildren[referenceLookup.lookup];
    if (childrenResult != null) {
      var result = _recurseChildrenAndFilter(referenceLookup, childrenResult,
          allowTree: allowTree, filter: filter);
      if (result != null) {
        return result;
      }
    }
  }
  // If we can't find it in children, try searching parents if allowed.
  if (tryParents) {
    for (var parent in parentOverrides) {
      var result = parent.referenceBy(reference,
          tryParents: true,
          parentOverrides: referenceGrandparentOverrides,
          allowTree: allowTree,
          filter: filter);
      if (result != null) return result;
    }
  }
  return null;
}