Skip to content

Commit 8405ab4

Browse files
committed
Make PackageGraph.allLibraries private
1 parent 7c559d4 commit 8405ab4

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

lib/src/model/package_graph.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PackageGraph with CommentReferable, Nameable {
8181
@override
8282
String get breadcrumbName => throw UnimplementedError();
8383

84-
/// Adds [resolvedLibrary] to the package graph, adding it to [allLibraries],
84+
/// Adds [resolvedLibrary] to the package graph, adding it to [_allLibraries],
8585
/// and to the [Package] which is created from the [PackageMeta] for the
8686
/// library.
8787
///
@@ -108,11 +108,11 @@ class PackageGraph with CommentReferable, Nameable {
108108
var package = Package.fromPackageMeta(packageMeta, this);
109109
var lib = Library.fromLibraryResult(resolvedLibrary, this, package);
110110
package.libraries.add(lib);
111-
allLibraries[libraryElement.source.fullName] = lib;
111+
_allLibraries[libraryElement.source.fullName] = lib;
112112
}
113113

114114
/// Adds [resolvedLibrary] as a special library to the package graph, which
115-
/// adds the library to [allLibraries], but does not add it to any [Package]'s
115+
/// adds the library to [_allLibraries], but does not add it to any [Package]'s
116116
/// list of libraries.
117117
///
118118
/// Call during initialization to add a library possibly containing
@@ -122,7 +122,7 @@ class PackageGraph with CommentReferable, Nameable {
122122
allLibrariesAdded = true;
123123
assert(!_localDocumentationBuilt);
124124
final libraryElement = resolvedLibrary.element.library;
125-
allLibraries.putIfAbsent(
125+
_allLibraries.putIfAbsent(
126126
libraryElement.source.fullName,
127127
() => Library.fromLibraryResult(
128128
resolvedLibrary,
@@ -312,18 +312,18 @@ class PackageGraph with CommentReferable, Nameable {
312312
return _extensions;
313313
}
314314

315-
/// All library objects related to this package; a superset of [libraries].
315+
/// All library objects related to this package graph; a superset of
316+
/// [libraries].
316317
///
317-
/// Keyed by `LibraryElement.Source.fullName` to resolve different URIs, which
318-
/// refer to the same location, to the same [Library]. This isn't how Dart
318+
/// Keyed by `LibraryElement.source.fullName` to resolve different URIs
319+
/// referring to the same location, to the same [Library]. This isn't how Dart
319320
/// works internally, but Dartdoc pretends to avoid documenting or duplicating
320321
/// data structures for the same "library" on disk based on how it is
321322
/// referenced. We can't use [Source] as a key due to differences in the
322323
/// [TimestampedData] timestamps.
323324
///
324325
/// This mapping must be complete before [initializePackageGraph] is called.
325-
@visibleForTesting
326-
final Map<String, Library> allLibraries = {};
326+
final Map<String, Library> _allLibraries = {};
327327

328328
/// All [ModelElement]s constructed for this package; a superset of
329329
/// the elements gathered in [_gatherModelElements].
@@ -533,8 +533,8 @@ class PackageGraph with CommentReferable, Nameable {
533533
/// which is created if it is not yet populated.
534534
Map<LibraryElement, Set<Library>> get libraryExports {
535535
// Table must be reset if we're still in the middle of adding libraries.
536-
if (allLibraries.keys.length != _lastSizeOfAllLibraries) {
537-
_lastSizeOfAllLibraries = allLibraries.keys.length;
536+
if (_allLibraries.keys.length != _lastSizeOfAllLibraries) {
537+
_lastSizeOfAllLibraries = _allLibraries.keys.length;
538538
_libraryExports = {};
539539
for (var library in publicLibraries) {
540540
_tagExportsFor(library, library.element);
@@ -565,7 +565,7 @@ class PackageGraph with CommentReferable, Nameable {
565565
hrefMap.putIfAbsent(href, () => {}).add(modelElement);
566566
}
567567

568-
for (final library in allLibraries.values) {
568+
for (final library in _allLibraries.values) {
569569
final href = library.href;
570570
if (href == null) continue;
571571
hrefMap.putIfAbsent(href, () => {}).add(library);
@@ -862,7 +862,7 @@ class PackageGraph with CommentReferable, Nameable {
862862
/// set of canonical Libraries).
863863
Library? findButDoNotCreateLibraryFor(Element e) {
864864
// This is just a cache to avoid creating lots of libraries over and over.
865-
return allLibraries[e.library?.source.fullName];
865+
return _allLibraries[e.library?.source.fullName];
866866
}
867867

868868
/// Gathers all of the model elements found in all of the libraries of all
@@ -894,7 +894,9 @@ class PackageGraph with CommentReferable, Nameable {
894894
return allElements;
895895
}
896896

897-
/// Glob lookups can be expensive. Cache per filename.
897+
/// Cache of 'nodoc' configurations.
898+
///
899+
/// Glob lookups can be expensive, so cache per filename.
898900
final _configSetsNodocFor = HashMap<String, bool>();
899901

900902
/// Given an element's [fullName], look up the nodoc configuration data and

test/end2end/model_test.dart

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -839,8 +839,7 @@ void main() async {
839839

840840
setUpAll(() {
841841
anonLib = packageGraph.libraries.named('anonymous_library');
842-
843-
someLib = packageGraph.allLibraries.values.named('reexport.somelib');
842+
someLib = packageGraph.libraries.named('reexport.somelib');
844843
reexportOneLib = packageGraph.libraries.named('reexport_one');
845844
reexportTwoLib = packageGraph.libraries.named('reexport_two');
846845
reexportThreeLib = packageGraph.libraries.named('reexport_three');
@@ -2240,12 +2239,11 @@ void main() async {
22402239
late Constructor aConstructor;
22412240

22422241
setUp(() {
2243-
base = packageGraph.allLibraries.values.named('two_exports.src.base');
2244-
extending =
2245-
packageGraph.allLibraries.values.named('two_exports.src.extending');
2246-
local_scope = packageGraph.allLibraries.values
2247-
.named('two_exports.src.local_scope');
2248-
two_exports = packageGraph.allLibraries.values.named('two_exports');
2242+
base = packageGraph.libraries.named('two_exports.src.base');
2243+
extending = packageGraph.libraries.named('two_exports.src.extending');
2244+
local_scope =
2245+
packageGraph.libraries.named('two_exports.src.local_scope');
2246+
two_exports = packageGraph.libraries.named('two_exports');
22492247

22502248
BaseWithMembers = base.classes.named('BaseWithMembers');
22512249
aStaticField = BaseWithMembers.staticFields.named('aStaticField');
@@ -2469,23 +2467,19 @@ void main() async {
24692467
initViaFieldFormal;
24702468

24712469
setUpAll(() async {
2472-
mylibpub = packageGraph.allLibraries.values.named('mylibpub');
2470+
mylibpub = packageGraph.libraries.named('mylibpub');
24732471
aFunctionUsingRenamedLib =
24742472
fakeLibrary.functions.named('aFunctionUsingRenamedLib');
2475-
Dart = packageGraph.allLibraries.values.named('Dart');
2473+
Dart = packageGraph.libraries.named('Dart');
24762474
DartPackage = packageGraph.packages.firstWhere((p) => p.name == 'Dart');
24772475
nameWithTwoUnderscores =
24782476
fakeLibrary.constants.named('NAME_WITH_TWO_UNDERSCORES');
24792477
nameWithSingleUnderscore =
24802478
fakeLibrary.constants.named('NAME_SINGLEUNDERSCORE');
2481-
string = packageGraph.allLibraries.values
2482-
.named('dart:core')
2483-
.classes
2484-
.named('String');
2485-
metaUseResult = packageGraph.allLibraries.values
2486-
.named('meta')
2487-
.classes
2488-
.named('UseResult');
2479+
string =
2480+
packageGraph.libraries.named('dart:core').classes.named('String');
2481+
metaUseResult =
2482+
packageGraph.libraries.named('meta').classes.named('UseResult');
24892483
baseForDocComments = fakeLibrary.classes.named('BaseForDocComments');
24902484
aNonDefaultConstructor = baseForDocComments.constructors
24912485
.named('BaseForDocComments.aNonDefaultConstructor');
@@ -2512,11 +2506,11 @@ void main() async {
25122506
.named('csspub')
25132507
.properties
25142508
.named('theOnlyThingInTheLibrary');
2515-
doesStuff = packageGraph.allLibraries.values
2509+
doesStuff = packageGraph.libraries
25162510
.named('anonymous_library')
25172511
.functions
25182512
.named('doesStuff');
2519-
BaseClass = packageGraph.allLibraries.values
2513+
BaseClass = packageGraph.libraries
25202514
.named('two_exports.src.base')
25212515
.classes
25222516
.named('BaseClass');
@@ -2531,7 +2525,7 @@ void main() async {
25312525
.named('ImplicitProperties')
25322526
.allFields
25332527
.named('forInheriting');
2534-
action = packageGraph.allLibraries.values
2528+
action = packageGraph.libraries
25352529
.named('reexport.somelib')
25362530
.classes
25372531
.named('BaseReexported')
@@ -2845,10 +2839,8 @@ void main() async {
28452839
reexportOneLib.extensions.named('DocumentThisExtensionOnce');
28462840
documentOnceReexportTwo =
28472841
reexportTwoLib.extensions.named('DocumentThisExtensionOnce');
2848-
string = packageGraph.allLibraries.values
2849-
.named('dart:core')
2850-
.classes
2851-
.named('String');
2842+
string =
2843+
packageGraph.libraries.named('dart:core').classes.named('String');
28522844
apple = exLibrary.classes.named('Apple');
28532845
ext = exLibrary.extensions.named('AppleExtension');
28542846
extensionReferencer = exLibrary.classes.named('ExtensionReferencer');

0 commit comments

Comments
 (0)