@@ -44,12 +44,13 @@ class PackageGraph {
4444 /// span packages.
4545 void addLibraryToGraph (DartDocResolvedLibrary resolvedLibrary) {
4646 assert (! allLibrariesAdded);
47- var element = resolvedLibrary.element;
48- var packageMeta = packageMetaProvider.fromElement (element, config.sdkDir);
47+ var libraryElement = resolvedLibrary.element;
48+ var packageMeta =
49+ packageMetaProvider.fromElement (libraryElement, config.sdkDir);
4950 var lib = Library .fromLibraryResult (
5051 resolvedLibrary, this , Package .fromPackageMeta (packageMeta, this ));
5152 packageMap[packageMeta.name].libraries.add (lib);
52- allLibraries[element ] = lib;
53+ allLibraries[libraryElement.source.fullName ] = lib;
5354 }
5455
5556 /// Call during initialization to add a library possibly containing
@@ -203,7 +204,13 @@ class PackageGraph {
203204 }
204205
205206 // All library objects related to this package; a superset of _libraries.
206- final Map <LibraryElement , Library > allLibraries = {};
207+ // Keyed by [LibraryElement.Source.fullName] to resolve multiple URIs
208+ // referring to the same location to the same [Library]. This isn't how
209+ // Dart works internally, but Dartdoc pretends to avoid documenting or
210+ // duplicating data structures for the same "library" on disk based
211+ // on how it is referenced. We can't use [Source] as a key since because
212+ // of differences in the [TimestampedData] timestamps.
213+ final allLibraries = < String , Library > {};
207214
208215 /// Keep track of warnings
209216 PackageWarningCounter _packageWarningCounter;
@@ -869,32 +876,28 @@ class PackageGraph {
869876 /// set of canonical Libraries).
870877 Library findButDoNotCreateLibraryFor (Element e) {
871878 // This is just a cache to avoid creating lots of libraries over and over.
872- if (allLibraries.containsKey (e.library)) {
873- return allLibraries[e.library];
874- }
875- return null ;
879+ return allLibraries[e.library? .source? .fullName];
876880 }
877881
878882 /// This is used when we might need a Library object that isn't actually
879883 /// a documentation entry point (for elements that have no Library within the
880884 /// set of canonical Libraries).
881885 Library findOrCreateLibraryFor (DartDocResolvedLibrary resolvedLibrary) {
882- final elementLibrary = resolvedLibrary.library;
883- // This is just a cache to avoid creating lots of libraries over and over.
884- if (allLibraries.containsKey (elementLibrary)) {
885- return allLibraries[elementLibrary];
886- }
886+ final libraryElement = resolvedLibrary.library;
887887 // can be null if e is for dynamic
888- if (elementLibrary == null ) {
888+ if (libraryElement == null ) {
889889 return null ;
890890 }
891- var foundLibrary = Library .fromLibraryResult (
891+ var foundLibrary = findButDoNotCreateLibraryFor (libraryElement);
892+ if (foundLibrary != null ) return foundLibrary;
893+
894+ foundLibrary = Library .fromLibraryResult (
892895 resolvedLibrary,
893896 this ,
894897 Package .fromPackageMeta (
895- packageMetaProvider.fromElement (elementLibrary , config.sdkDir),
898+ packageMetaProvider.fromElement (libraryElement , config.sdkDir),
896899 packageGraph));
897- allLibraries[elementLibrary ] = foundLibrary;
900+ allLibraries[libraryElement.source.fullName ] = foundLibrary;
898901 return foundLibrary;
899902 }
900903
0 commit comments