diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index 65c49ceb08..1e48d2f4bd 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -99,16 +99,23 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { void addSpecialLibraryToGraph(DartDocResolvedLibrary resolvedLibrary) { allLibrariesAdded = true; assert(!_localDocumentationBuilt); - findOrCreateLibraryFor(resolvedLibrary); + final libraryElement = resolvedLibrary.element.library; + allLibraries.putIfAbsent( + libraryElement.source.fullName, + () => Library.fromLibraryResult( + resolvedLibrary, + this, + Package.fromPackageMeta( + packageMetaProvider.fromElement(libraryElement, config.sdkDir)!, + packageGraph), + ), + ); } /// Call after all libraries are added. Future initializePackageGraph() async { assert(!_localDocumentationBuilt); allLibrariesAdded = true; - // From here on in, we might find special objects. Initialize the - // specialClasses handler so when we find them, they get added. - specialClasses = SpecialClasses(); // Go through docs of every ModelElement in package to pre-build the macros // index. await Future.wait(_precacheLocalDocs()); @@ -137,9 +144,10 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { } /// Generate a list of futures for any docs that actually require precaching. - Iterable> _precacheLocalDocs() sync* { + Iterable> _precacheLocalDocs() { // Prevent reentrancy. var precachedElements = {}; + var futures = >[]; for (var element in _allModelElements) { // Only precache elements which are canonical, have a canonical element @@ -153,14 +161,14 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { .where((d) => d.hasDocumentationComment)) { if (d.needsPrecache && !precachedElements.contains(d)) { precachedElements.add(d as ModelElement); - yield d.precacheLocalDocs(); + futures.add(d.precacheLocalDocs()); logProgress(d.name); // [TopLevelVariable]s get their documentation from getters and // setters, so should be precached if either has a template. if (element is TopLevelVariable && !precachedElements.contains(element)) { precachedElements.add(element); - yield element.precacheLocalDocs(); + futures.add(element.precacheLocalDocs()); logProgress(d.name); } } @@ -168,7 +176,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { } } // Now wait for any of the tasks still running to complete. - yield config.tools.runner.wait(); + futures.add(config.tools.runner.wait()); + return futures; } /// Initializes the category mappings in all [packages]. @@ -178,10 +187,13 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { } } - // Many ModelElements have the same ModelNode; don't build/cache this data more - // than once for them. + // Many ModelElements have the same ModelNode; don't build/cache this data + // more than once for them. final Map _modelNodes = {}; + /// The collection of "special" classes for which we need some special access. + final specialClasses = SpecialClasses(); + /// Populate's [_modelNodes] with elements in [resolvedLibrary]. /// /// This is done as [Library] model objects are created, while we are holding @@ -253,8 +265,6 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { ModelNode? getModelNodeFor(Element element) => _modelNodes[element]; - late SpecialClasses specialClasses; - /// It is safe to cache values derived from the [_implementors] table if this /// is true. bool allImplementorsAdded = false; @@ -639,8 +649,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { ?.linkedName ?? 'Object'; - /// Return the set of [Class]es which objects should inherit through if they - /// show up in the inheritance chain. + /// The set of [Class]es which should _not_ be presented as implementors. /// /// Add classes here if they are similar to Interceptor in that they are to be /// ignored even when they are the implementors of [Inheritable]s, and the @@ -856,24 +865,6 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder { return allLibraries[e.library?.source.fullName]; } - /// This is used when we might need a [Library] that isn't actually a - /// documentation entry point (for elements that have no [Library] within the - /// set of canonical libraries). - Library findOrCreateLibraryFor(DartDocResolvedLibrary resolvedLibrary) { - final libraryElement = resolvedLibrary.element.library; - var foundLibrary = findButDoNotCreateLibraryFor(libraryElement); - if (foundLibrary != null) return foundLibrary; - - foundLibrary = Library.fromLibraryResult( - resolvedLibrary, - this, - Package.fromPackageMeta( - packageMetaProvider.fromElement(libraryElement, config.sdkDir)!, - packageGraph)); - allLibraries[libraryElement.source.fullName] = foundLibrary; - return foundLibrary; - } - late final Iterable _allModelElements = () { assert(allLibrariesAdded); var allElements = [];