Skip to content

Commit f2d416b

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: simplify PackageConfigFileBuilder.toContent
This API did not exist (was not public) in analyzer 7.4.x, so is safe to change in 8.0.0. Change-Id: Ib4a06008b1cdf1be4f33dcb9036ea87b6d258067 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430041 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 058641a commit f2d416b

File tree

12 files changed

+19
-22
lines changed

12 files changed

+19
-22
lines changed

pkg/analysis_server/lib/src/plugin/plugin_manager.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,7 @@ class PluginManager {
887887
}
888888
packageConfigFile.writeAsStringSync(
889889
packageConfigBuilder.toContent(
890-
toUriStr: (path) {
891-
return resourceProvider.pathContext.toUri(path).toString();
892-
},
890+
pathContext: resourceProvider.pathContext,
893891
),
894892
);
895893
} catch (exception) {

pkg/analysis_server/test/analysis/notification_errors_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ analyzer:
175175
// Add the generated project into package_config.json.
176176
var config = PackageConfigFileBuilder();
177177
config.add(name: 'foo', rootPath: generatedProject);
178-
newFile(configPath, config.toContent(toUriStr: toUriStr));
178+
newFile(configPath, config.toContent(pathContext: pathContext));
179179

180180
// Set up project that references the class prior to initial analysis.
181181
var generatedFile = newFile(generatedFilePath, 'class A {}');

pkg/analysis_server/test/analysis_server_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ analyzer:
349349
}
350350

351351
void writePackageConfig(String path, PackageConfigFileBuilder config) {
352-
newFile(path, config.toContent(toUriStr: toUriStr));
352+
newFile(path, config.toContent(pathContext: pathContext));
353353
}
354354

355355
/// Creates a simple package named [name] with [content] in the file at

pkg/analysis_server/test/support/configuration_files.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ mixin ConfigurationFilesMixin on MockPackagesMixin {
9191
config.add(name: 'vector_math', rootPath: libFolder.parent.path);
9292
}
9393

94-
var content = config.toContent(
95-
toUriStr:
96-
(p) => pathContext.toUri(resourceProvider.convertPath(p)).toString(),
97-
);
94+
var content = config.toContent(pathContext: pathContext);
9895

9996
var projectFolder = resourceProvider.getFolder(projectFolderPath);
10097
var dartToolFolder = projectFolder.getChildAssumingFolder(

pkg/analyzer/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4862,7 +4862,7 @@ package:analyzer/utilities/package_config_file_builder.dart:
48624862
new (constructor: PackageConfigFileBuilder Function())
48634863
add (method: void Function({String? languageVersion, required String name, String packageUri, required String rootPath}))
48644864
copy (method: PackageConfigFileBuilder Function())
4865-
toContent (method: String Function({required String Function(String) toUriStr}))
4865+
toContent (method: String Function({required Context pathContext}))
48664866
package:analyzer/workspace/workspace.dart:
48674867
WorkspacePackage (class extends Object):
48684868
new (constructor: WorkspacePackage Function())

pkg/analyzer/lib/utilities/package_config_file_builder.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:path/path.dart' as path;
6+
57
/// Helper for building `.dart_tool/package_config.json` files.
68
///
79
/// See accepted/future-releases/language-versioning/package-config-file-v2.md
@@ -41,7 +43,7 @@ class PackageConfigFileBuilder {
4143
}
4244

4345
/// Returns the contents of the built package config file.
44-
String toContent({required String Function(String) toUriStr}) {
46+
String toContent({required path.Context pathContext}) {
4547
var buffer = StringBuffer();
4648

4749
buffer.writeln('{');
@@ -59,7 +61,7 @@ class PackageConfigFileBuilder {
5961
prefix = ' ' * 6;
6062
buffer.writeln('$prefix"name": "${package.name}",');
6163

62-
var rootUri = toUriStr(package.rootPath);
64+
var rootUri = pathContext.toUri(package.rootPath).toString();
6365
buffer.write('$prefix"rootUri": "$rootUri"');
6466

6567
buffer.writeln(',');

pkg/analyzer/test/src/dart/analysis/context_locator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ ${getFolder(outPath).path}
12511251
PackageConfigFileBuilder()..add(name: 'flutter', rootPath: flutterPath);
12521252
var packagesFile = newPackageConfigJsonFile(
12531253
rootFolder.path,
1254-
packageConfigFileBuilder.toContent(toUriStr: toUriStr),
1254+
packageConfigFileBuilder.toContent(pathContext: pathContext),
12551255
);
12561256

12571257
var roots = contextLocator.locateRoots(includedPaths: [rootFolder.path]);

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class PubPackageResolutionTest extends ContextResolutionTest
344344
String directoryPath,
345345
PackageConfigFileBuilder config,
346346
) {
347-
var content = config.toContent(toUriStr: toUriStr);
347+
var content = config.toContent(pathContext: pathContext);
348348
newPackageConfigJsonFile(directoryPath, content);
349349
}
350350

pkg/analyzer/test/src/workspace/pub_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PackageBuildFileUriResolverTest with ResourceProviderMixin {
7676
config.add(name: 'test', rootPath: convertPath(testPackageRootPath));
7777
newPackageConfigJsonFile(
7878
testPackageRootPath,
79-
config.toContent(toUriStr: toUriStr),
79+
config.toContent(pathContext: pathContext),
8080
);
8181

8282
workspace =
@@ -230,7 +230,7 @@ class PackageBuildPackageUriResolverTest with ResourceProviderMixin {
230230
config.add(name: 'project', rootPath: '/workspace');
231231
newPackageConfigJsonFile(
232232
workspacePath,
233-
config.toContent(toUriStr: toUriStr),
233+
config.toContent(pathContext: pathContext),
234234
);
235235
workspace =
236236
PackageConfigWorkspace.find(
@@ -570,7 +570,7 @@ class PackageConfigWorkspaceTest with ResourceProviderMixin {
570570
for (var name in packageNames) {
571571
config.add(name: name, rootPath: convertPath('/packages/$name'));
572572
}
573-
newPackageConfigJsonFile(root, config.toContent(toUriStr: toUriStr));
573+
newPackageConfigJsonFile(root, config.toContent(pathContext: pathContext));
574574
return PackageConfigWorkspace.find(
575575
resourceProvider,
576576
Packages.empty,
@@ -610,7 +610,7 @@ class PubPackageTest extends WorkspacePackageTest {
610610
config.add(name: 'workspace', rootPath: '/workspace');
611611
newPackageConfigJsonFile(
612612
'/workspace',
613-
config.toContent(toUriStr: toUriStr),
613+
config.toContent(pathContext: pathContext),
614614
);
615615
workspace =
616616
PackageConfigWorkspace.find(
@@ -627,7 +627,7 @@ class PubPackageTest extends WorkspacePackageTest {
627627
config.add(name: 'foo', rootPath: fooPackageRootPath);
628628
newPackageConfigJsonFile(
629629
myPackageRootPath,
630-
config.toContent(toUriStr: toUriStr),
630+
config.toContent(pathContext: pathContext),
631631
);
632632
newFolder(myPackageGeneratedPath);
633633
myWorkspace =

pkg/analyzer_plugin/test/support/abstract_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class AbstractContextTest with MockPackagesMixin, ResourceProviderMixin {
116116
}
117117

118118
void writePackageConfig(String path, PackageConfigFileBuilder config) {
119-
newFile(path, config.toContent(toUriStr: toUriStr));
119+
newFile(path, config.toContent(pathContext: pathContext));
120120
}
121121

122122
/// Write an analysis options file based on the given arguments.

0 commit comments

Comments
 (0)