Skip to content

Commit

Permalink
Make PackageGraph.allLibraries private
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jun 19, 2024
1 parent 6330a13 commit 853a591
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
30 changes: 16 additions & 14 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PackageGraph with CommentReferable, Nameable {
@override
String get breadcrumbName => throw UnimplementedError();

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

/// Adds [resolvedLibrary] as a special library to the package graph, which
/// adds the library to [allLibraries], but does not add it to any [Package]'s
/// adds the library to [_allLibraries], but does not add it to any [Package]'s
/// list of libraries.
///
/// Call during initialization to add a library possibly containing
Expand All @@ -122,7 +122,7 @@ class PackageGraph with CommentReferable, Nameable {
allLibrariesAdded = true;
assert(!_localDocumentationBuilt);
final libraryElement = resolvedLibrary.element.library;
allLibraries.putIfAbsent(
_allLibraries.putIfAbsent(
libraryElement.source.fullName,
() => Library.fromLibraryResult(
resolvedLibrary,
Expand Down Expand Up @@ -312,18 +312,18 @@ class PackageGraph with CommentReferable, Nameable {
return _extensions;
}

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

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

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

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

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

/// Given an element's [fullName], look up the nodoc configuration data and
Expand Down
42 changes: 17 additions & 25 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,7 @@ void main() async {

setUpAll(() {
anonLib = packageGraph.libraries.named('anonymous_library');

someLib = packageGraph.allLibraries.values.named('reexport.somelib');
someLib = packageGraph.libraries.named('reexport.somelib');
reexportOneLib = packageGraph.libraries.named('reexport_one');
reexportTwoLib = packageGraph.libraries.named('reexport_two');
reexportThreeLib = packageGraph.libraries.named('reexport_three');
Expand Down Expand Up @@ -2238,12 +2237,11 @@ void main() async {
late Constructor aConstructor;

setUp(() {
base = packageGraph.allLibraries.values.named('two_exports.src.base');
extending =
packageGraph.allLibraries.values.named('two_exports.src.extending');
local_scope = packageGraph.allLibraries.values
.named('two_exports.src.local_scope');
two_exports = packageGraph.allLibraries.values.named('two_exports');
base = packageGraph.libraries.named('two_exports.src.base');
extending = packageGraph.libraries.named('two_exports.src.extending');
local_scope =
packageGraph.libraries.named('two_exports.src.local_scope');
two_exports = packageGraph.libraries.named('two_exports');

BaseWithMembers = base.classes.named('BaseWithMembers');
aStaticField = BaseWithMembers.staticFields.named('aStaticField');
Expand Down Expand Up @@ -2467,23 +2465,19 @@ void main() async {
initViaFieldFormal;

setUpAll(() async {
mylibpub = packageGraph.allLibraries.values.named('mylibpub');
mylibpub = packageGraph.libraries.named('mylibpub');
aFunctionUsingRenamedLib =
fakeLibrary.functions.named('aFunctionUsingRenamedLib');
Dart = packageGraph.allLibraries.values.named('Dart');
Dart = packageGraph.libraries.named('Dart');
DartPackage = packageGraph.packages.firstWhere((p) => p.name == 'Dart');
nameWithTwoUnderscores =
fakeLibrary.constants.named('NAME_WITH_TWO_UNDERSCORES');
nameWithSingleUnderscore =
fakeLibrary.constants.named('NAME_SINGLEUNDERSCORE');
string = packageGraph.allLibraries.values
.named('dart:core')
.classes
.named('String');
metaUseResult = packageGraph.allLibraries.values
.named('meta')
.classes
.named('UseResult');
string =
packageGraph.libraries.named('dart:core').classes.named('String');
metaUseResult =
packageGraph.libraries.named('meta').classes.named('UseResult');
baseForDocComments = fakeLibrary.classes.named('BaseForDocComments');
aNonDefaultConstructor = baseForDocComments.constructors
.named('BaseForDocComments.aNonDefaultConstructor');
Expand All @@ -2510,11 +2504,11 @@ void main() async {
.named('csspub')
.properties
.named('theOnlyThingInTheLibrary');
doesStuff = packageGraph.allLibraries.values
doesStuff = packageGraph.libraries
.named('anonymous_library')
.functions
.named('doesStuff');
BaseClass = packageGraph.allLibraries.values
BaseClass = packageGraph.libraries
.named('two_exports.src.base')
.classes
.named('BaseClass');
Expand All @@ -2529,7 +2523,7 @@ void main() async {
.named('ImplicitProperties')
.allFields
.named('forInheriting');
action = packageGraph.allLibraries.values
action = packageGraph.libraries
.named('reexport.somelib')
.classes
.named('BaseReexported')
Expand Down Expand Up @@ -2843,10 +2837,8 @@ void main() async {
reexportOneLib.extensions.named('DocumentThisExtensionOnce');
documentOnceReexportTwo =
reexportTwoLib.extensions.named('DocumentThisExtensionOnce');
string = packageGraph.allLibraries.values
.named('dart:core')
.classes
.named('String');
string =
packageGraph.libraries.named('dart:core').classes.named('String');
apple = exLibrary.classes.named('Apple');
ext = exLibrary.extensions.named('AppleExtension');
extensionReferencer = exLibrary.classes.named('ExtensionReferencer');
Expand Down

0 comments on commit 853a591

Please sign in to comment.