canonicalLibrary property

Library canonicalLibrary
override

Implementation

@override
Library get canonicalLibrary {
  if (!_canonicalLibraryIsSet) {
    // This is not accurate if we are constructing the Package.
    assert(packageGraph.allLibrariesAdded);

    // Privately named elements can never have a canonical library, so
    // just shortcut them out.
    if (!utils.hasPublicName(element)) {
      _canonicalLibrary = null;
    } else if (!packageGraph.localPublicLibraries.contains(definingLibrary)) {
      _canonicalLibrary = _searchForCanonicalLibrary();
    } else {
      _canonicalLibrary = definingLibrary;
    }
    // Only pretend when not linking to remote packages.
    if (this is Inheritable && !config.linkToRemote) {
      if ((this as Inheritable).isInherited &&
          _canonicalLibrary == null &&
          packageGraph.publicLibraries.contains(library)) {
        // In the event we've inherited a field from an object that isn't directly reexported,
        // we may need to pretend we are canonical for this.
        _canonicalLibrary = library;
      }
    }
    _canonicalLibraryIsSet = true;
  }
  assert(_canonicalLibrary == null ||
      packageGraph.publicLibraries.contains(_canonicalLibrary));
  return _canonicalLibrary;
}