allHrefs property

Map<String, Set<ModelElement>> get allHrefs

A lookup index for hrefs to allow warnings to indicate where a broken link or orphaned file may have come from.

This is not cached because ModelElements can be created at any time.

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);
    hrefMap
        .putIfAbsent(href.replaceAll(htmlBasePlaceholder, ''), () => {})
        .add(modelElement);
  }

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