allHrefs property

Map<String, Set<ModelElement>> allHrefs

A lookup index for hrefs to allow warnings to indicate where a broken link or orphaned file may have come from. Not cached because ModelElements can be created at any time and we're basing this on more than just allLocalModelElements to make the error messages comprehensive.

Implementation

Map<String, Set<ModelElement>> get allHrefs {
  final hrefMap = <String, Set<ModelElement>>{};
  // TODO(jcollins-g ): handle calculating hrefs causing new elements better
  //                    than toList().
  for (final modelElement in allConstructedModelElements.values.toList()) {
    // Technically speaking we should be able to use canonical model elements
    // only here, but since the warnings that depend on this debug
    // canonicalization problems, don't limit ourselves in case an href is
    // generated for something non-canonical.
    if (modelElement is Dynamic) continue;
    // TODO: see [Accessor.enclosingCombo]
    if (modelElement is Accessor) continue;
    final href = modelElement.href;
    if (href == null) continue;

    hrefMap.putIfAbsent(href, () => {}).add(modelElement);
  }

  for (final library in allLibraries.values) {
    final href = library.href;
    if (href == null) continue;
    hrefMap.putIfAbsent(href, () => {}).add(library);
  }
  return hrefMap;
}