@@ -66,9 +66,9 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
66
66
throw DartdocFailure (packageMetaProvider.getMessageForMissingPackageMeta (
67
67
libraryElement, config));
68
68
}
69
- var lib = Library . fromLibraryResult (
70
- resolvedLibrary, this , Package . fromPackageMeta (packageMeta, this ) );
71
- packageMap[packageMeta.name] ! .libraries.add (lib);
69
+ var package = Package . fromPackageMeta (packageMeta, this );
70
+ var lib = Library . fromLibraryResult ( resolvedLibrary, this , package );
71
+ package .libraries.add (lib);
72
72
allLibraries[libraryElement.source.fullName] = lib;
73
73
}
74
74
@@ -83,14 +83,14 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
83
83
84
84
/// Call after all libraries are added.
85
85
Future <void > initializePackageGraph () async {
86
- allLibrariesAdded = true ;
87
86
assert (! _localDocumentationBuilt);
87
+ allLibrariesAdded = true ;
88
88
// From here on in, we might find special objects. Initialize the
89
89
// specialClasses handler so when we find them, they get added.
90
90
specialClasses = SpecialClasses ();
91
91
// Go through docs of every ModelElement in package to pre-build the macros
92
92
// index.
93
- await Future .wait (precacheLocalDocs ());
93
+ await Future .wait (_precacheLocalDocs ());
94
94
_localDocumentationBuilt = true ;
95
95
96
96
// Scan all model elements to insure that interceptor and other special
@@ -116,7 +116,7 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
116
116
}
117
117
118
118
/// Generate a list of futures for any docs that actually require precaching.
119
- Iterable <Future <void >> precacheLocalDocs () sync * {
119
+ Iterable <Future <void >> _precacheLocalDocs () sync * {
120
120
// Prevent reentrancy.
121
121
var precachedElements = < ModelElement > {};
122
122
@@ -144,14 +144,13 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
144
144
// Not the same as allCanonicalModelElements since we need to run
145
145
// for any ModelElement that might not have a canonical ModelElement,
146
146
// too.
147
- if (m.canonicalModelElement !=
148
- null // A canonical element exists somewhere
149
- &&
150
- ! m.isCanonical // This element is not canonical
151
- &&
152
- ! m.enclosingElement!
153
- .isCanonical // The enclosingElement won't need a oneLineDoc from this
154
- ) {
147
+ if (
148
+ // A canonical element exists somewhere.
149
+ m.canonicalModelElement != null &&
150
+ // This element is not canonical.
151
+ ! m.isCanonical &&
152
+ // The enclosing element won't need a `oneLineDoc` from this.
153
+ ! m.enclosingElement! .isCanonical) {
155
154
continue ;
156
155
}
157
156
yield * precacheOneElement (m);
@@ -197,13 +196,17 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
197
196
return _extensions;
198
197
}
199
198
200
- // All library objects related to this package; a superset of _libraries.
201
- // Keyed by [LibraryElement.Source.fullName] to resolve multiple URIs
202
- // referring to the same location to the same [Library]. This isn't how
203
- // Dart works internally, but Dartdoc pretends to avoid documenting or
204
- // duplicating data structures for the same "library" on disk based
205
- // on how it is referenced. We can't use [Source] as a key since because
206
- // of differences in the [TimestampedData] timestamps.
199
+ /// All library objects related to this package; a superset of [libraries] .
200
+ ///
201
+ /// Keyed by `LibraryElement.Source.fullName` to resolve different URIs, which
202
+ /// refer to the same location, to the same [Library] . This isn't how Dart
203
+ /// works internally, but Dartdoc pretends to avoid documenting or duplicating
204
+ /// data structures for the same "library" on disk based on how it is
205
+ /// referenced. We can't use [Source] as a key due to differences in the
206
+ /// [TimestampedData] timestamps.
207
+ ///
208
+ /// This mapping must be complete before [initializePackageGraph] is called.
209
+ @visibleForTesting
207
210
final allLibraries = < String , Library > {};
208
211
209
212
/// All ModelElements constructed for this package; a superset of [allModelElements] .
@@ -252,6 +255,8 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
252
255
PackageGraph get packageGraph => this ;
253
256
254
257
/// Map of package name to Package.
258
+ ///
259
+ /// This mapping must be complete before [initializePackageGraph] is called.
255
260
final Map <String , Package > packageMap = {};
256
261
257
262
ResourceProvider get resourceProvider => config.resourceProvider;
@@ -265,6 +270,9 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
265
270
final Map <String , String > _macros = {};
266
271
final Map <String , String > _htmlFragments = {};
267
272
bool allLibrariesAdded = false ;
273
+
274
+ /// Whether the local documentation has been built, which is only complete
275
+ /// after all of the work in [_precacheLocalDocs] is done.
268
276
bool _localDocumentationBuilt = false ;
269
277
270
278
/// Keep track of warnings.
@@ -506,10 +514,9 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
506
514
}
507
515
_reexportsTagged.add (key);
508
516
if (libraryElement == null ) {
509
- // The first call to _tagReexportFor should not have a null libraryElement.
510
- assert (lastExportedElement != null );
517
+ lastExportedElement! ;
511
518
warnOnElement (
512
- findButDoNotCreateLibraryFor (lastExportedElement! .enclosingElement! ),
519
+ findButDoNotCreateLibraryFor (lastExportedElement.enclosingElement! ),
513
520
PackageWarning .unresolvedExport,
514
521
message: '"${lastExportedElement .uri }"' ,
515
522
referredFrom: < Locatable > [topLevelLibrary]);
@@ -870,9 +877,9 @@ class PackageGraph with CommentReferable, Nameable, ModelBuilder {
870
877
return allLibraries[e.library? .source.fullName];
871
878
}
872
879
873
- /// This is used when we might need a Library object that isn't actually
874
- /// a documentation entry point (for elements that have no Library within the
875
- /// set of canonical Libraries ).
880
+ /// This is used when we might need a [ Library] that isn't actually a
881
+ /// documentation entry point (for elements that have no [ Library] within the
882
+ /// set of canonical libraries ).
876
883
Library findOrCreateLibraryFor (DartDocResolvedLibrary resolvedLibrary) {
877
884
final libraryElement = resolvedLibrary.element.library;
878
885
var foundLibrary = findButDoNotCreateLibraryFor (libraryElement);
0 commit comments