Skip to content

Commit 853a591

Browse files
committed
Make PackageGraph.allLibraries private
1 parent 6330a13 commit 853a591

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);
@@ -566,7 +566,7 @@ class PackageGraph with CommentReferable, Nameable {
566566
hrefMap.putIfAbsent(href, () => {}).add(modelElement);
567567
}
568568

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

869869
/// Gathers all of the model elements found in all of the libraries of all
@@ -900,7 +900,9 @@ class PackageGraph with CommentReferable, Nameable {
900900
for (var library in _localLibraries) ...library.allModelElements
901901
];
902902

903-
/// Glob lookups can be expensive. Cache per filename.
903+
/// Cache of 'nodoc' configurations.
904+
///
905+
/// Glob lookups can be expensive, so cache per filename.
904906
final _configSetsNodocFor = HashMap<String, bool>();
905907

906908
/// 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
@@ -837,8 +837,7 @@ void main() async {
837837

838838
setUpAll(() {
839839
anonLib = packageGraph.libraries.named('anonymous_library');
840-
841-
someLib = packageGraph.allLibraries.values.named('reexport.somelib');
840+
someLib = packageGraph.libraries.named('reexport.somelib');
842841
reexportOneLib = packageGraph.libraries.named('reexport_one');
843842
reexportTwoLib = packageGraph.libraries.named('reexport_two');
844843
reexportThreeLib = packageGraph.libraries.named('reexport_three');
@@ -2238,12 +2237,11 @@ void main() async {
22382237
late Constructor aConstructor;
22392238

22402239
setUp(() {
2241-
base = packageGraph.allLibraries.values.named('two_exports.src.base');
2242-
extending =
2243-
packageGraph.allLibraries.values.named('two_exports.src.extending');
2244-
local_scope = packageGraph.allLibraries.values
2245-
.named('two_exports.src.local_scope');
2246-
two_exports = packageGraph.allLibraries.values.named('two_exports');
2240+
base = packageGraph.libraries.named('two_exports.src.base');
2241+
extending = packageGraph.libraries.named('two_exports.src.extending');
2242+
local_scope =
2243+
packageGraph.libraries.named('two_exports.src.local_scope');
2244+
two_exports = packageGraph.libraries.named('two_exports');
22472245

22482246
BaseWithMembers = base.classes.named('BaseWithMembers');
22492247
aStaticField = BaseWithMembers.staticFields.named('aStaticField');
@@ -2467,23 +2465,19 @@ void main() async {
24672465
initViaFieldFormal;
24682466

24692467
setUpAll(() async {
2470-
mylibpub = packageGraph.allLibraries.values.named('mylibpub');
2468+
mylibpub = packageGraph.libraries.named('mylibpub');
24712469
aFunctionUsingRenamedLib =
24722470
fakeLibrary.functions.named('aFunctionUsingRenamedLib');
2473-
Dart = packageGraph.allLibraries.values.named('Dart');
2471+
Dart = packageGraph.libraries.named('Dart');
24742472
DartPackage = packageGraph.packages.firstWhere((p) => p.name == 'Dart');
24752473
nameWithTwoUnderscores =
24762474
fakeLibrary.constants.named('NAME_WITH_TWO_UNDERSCORES');
24772475
nameWithSingleUnderscore =
24782476
fakeLibrary.constants.named('NAME_SINGLEUNDERSCORE');
2479-
string = packageGraph.allLibraries.values
2480-
.named('dart:core')
2481-
.classes
2482-
.named('String');
2483-
metaUseResult = packageGraph.allLibraries.values
2484-
.named('meta')
2485-
.classes
2486-
.named('UseResult');
2477+
string =
2478+
packageGraph.libraries.named('dart:core').classes.named('String');
2479+
metaUseResult =
2480+
packageGraph.libraries.named('meta').classes.named('UseResult');
24872481
baseForDocComments = fakeLibrary.classes.named('BaseForDocComments');
24882482
aNonDefaultConstructor = baseForDocComments.constructors
24892483
.named('BaseForDocComments.aNonDefaultConstructor');
@@ -2510,11 +2504,11 @@ void main() async {
25102504
.named('csspub')
25112505
.properties
25122506
.named('theOnlyThingInTheLibrary');
2513-
doesStuff = packageGraph.allLibraries.values
2507+
doesStuff = packageGraph.libraries
25142508
.named('anonymous_library')
25152509
.functions
25162510
.named('doesStuff');
2517-
BaseClass = packageGraph.allLibraries.values
2511+
BaseClass = packageGraph.libraries
25182512
.named('two_exports.src.base')
25192513
.classes
25202514
.named('BaseClass');
@@ -2529,7 +2523,7 @@ void main() async {
25292523
.named('ImplicitProperties')
25302524
.allFields
25312525
.named('forInheriting');
2532-
action = packageGraph.allLibraries.values
2526+
action = packageGraph.libraries
25332527
.named('reexport.somelib')
25342528
.classes
25352529
.named('BaseReexported')
@@ -2843,10 +2837,8 @@ void main() async {
28432837
reexportOneLib.extensions.named('DocumentThisExtensionOnce');
28442838
documentOnceReexportTwo =
28452839
reexportTwoLib.extensions.named('DocumentThisExtensionOnce');
2846-
string = packageGraph.allLibraries.values
2847-
.named('dart:core')
2848-
.classes
2849-
.named('String');
2840+
string =
2841+
packageGraph.libraries.named('dart:core').classes.named('String');
28502842
apple = exLibrary.classes.named('Apple');
28512843
ext = exLibrary.extensions.named('AppleExtension');
28522844
extensionReferencer = exLibrary.classes.named('ExtensionReferencer');

0 commit comments

Comments
 (0)