referenceBy method

  1. @nonVirtual
CommentReferable referenceBy(
  1. List<String> reference,
  2. {bool tryParents = true,
  3. bool filter(
    1. CommentReferable
    )}
)
@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.

Implementation

@nonVirtual
CommentReferable referenceBy(List<String> reference,
    {bool tryParents = true, bool Function(CommentReferable) filter}) {
  filter ??= (r) => true;
  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);
      if (result != null) break;
    }
    if (referenceChildren.containsKey(referenceLookup.lookup)) {
      result = _lookupViaReferenceChildren(referenceLookup, 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 referenceParents) {
      result = parent.referenceBy(reference, filter: filter);
      if (result != null) break;
    }
  }
  return result;
}