referenceBy method

  1. @nonVirtual
CommentReferable referenceBy(
  1. List<String> reference,
  2. {bool tryParents = true,
  3. bool filter(
    1. CommentReferable
    ),
  4. bool allowTree(
    1. CommentReferable
    ),
  5. Iterable<CommentReferable> parentOverrides}
)
@nonVirtual, 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,
    {bool tryParents = true,
    bool Function(CommentReferable) filter,
    bool Function(CommentReferable) allowTree,
    Iterable<CommentReferable> parentOverrides}) {
  filter ??= (r) => true;
  allowTree ??= (r) => true;
  parentOverrides ??= referenceParents;
  if (reference.isEmpty) {
    if (tryParents == false) return this;
    return null;
  }
  CommentReferable result;

  /// Search for the reference.
  for (var referenceLookup in childLookups(reference)) {
    if (scope != null) {
      result = lookupViaScope(referenceLookup, filter, allowTree);
      if (result != null) break;
    }
    if (referenceChildren.containsKey(referenceLookup.lookup)) {
      result = recurseChildrenAndFilter(
          referenceLookup, referenceChildren[referenceLookup.lookup],
          allowTree: allowTree, filter: filter);
      if (result != null) break;
    }
  }
  // If we can't find it in children, try searching parents if allowed.
  if (result == null && tryParents) {
    for (var parent in parentOverrides) {
      result = parent.referenceBy(reference,
          tryParents: true,
          parentOverrides: referenceGrandparentOverrides,
          allowTree: allowTree,
          filter: filter);
      if (result != null) break;
    }
  }
  return result;
}