Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some code in PackageBuilder #3447

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,9 @@ class PubPackageBuilder implements PackageBuilder {

current = _packageMetasForFiles(files.difference(_knownParts));
// To get canonicalization correct for non-locally documented packages
// (so we can generate the right hyperlinks), it's vital that we
// add all libraries in dependent packages. So if the analyzer
// discovers some files in a package we haven't seen yet, add files
// for that package.
// (so we can generate the right hyperlinks), it's vital that we add all
// libraries in dependent packages. So if the analyzer discovers some
// files in a package we haven't seen yet, add files for that package.
for (var meta in current.difference(lastPass)) {
if (meta.isSdk) {
if (!_skipUnreachableSdkLibraries) {
Expand Down Expand Up @@ -337,9 +336,10 @@ class PubPackageBuilder implements PackageBuilder {

/// Lists the contents of [dir].
///
/// If [recursive] is `true`, lists subdirectory contents (defaults to `false`).
/// If [recursive] is `true`, lists subdirectory contents (defaults to
/// `false`).
///
/// Excludes files and directories beginning with `.`
/// Excludes files and directories beginning with `.`.
///
/// The returned paths are guaranteed to begin with [dir].
Iterable<String> _listDir(String dir,
Expand Down Expand Up @@ -419,13 +419,11 @@ class PubPackageBuilder implements PackageBuilder {
}

Future<void> getLibraries(PackageGraph uninitializedPackageGraph) async {
DartSdk findSpecialsSdk;
var embedderSdk = this.embedderSdk;
if (embedderSdk != null && embedderSdk.urlMappings.isNotEmpty) {
findSpecialsSdk = embedderSdk;
} else {
findSpecialsSdk = sdk;
}
var findSpecialsSdk = switch (embedderSdk) {
EmbedderSdk(:var urlMappings) when urlMappings.isNotEmpty => embedderSdk,
_ => sdk,
};
var files = await _getFiles();
var specialFiles = specialLibraryFiles(findSpecialsSdk);

Expand Down Expand Up @@ -499,16 +497,7 @@ class DartDocResolvedLibrary {
if (fullName != null && !element.isSynthetic && element.nameOffset != -1) {
var unit = _units[fullName];
if (unit != null) {
var locator = NodeLocator2(element.nameOffset);
var node = locator.searchWithin(unit);
if (node is SimpleIdentifier) {
// TODO(scheglov) Remove this branch after the breaking change for
// the analyzer, when we start returning the declaring node, not
// the name, which will be just a `Token`.
return node.parent;
} else {
return node;
}
return NodeLocator2(element.nameOffset).searchWithin(unit);
}
}
return null;
Expand Down
Loading