Skip to content

Commit 739ca67

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
Deprecate MemoryResourceProvider.convertPath in favor of extension
Work towards #55660 The comment for `MemoryResourceProvider.convertPath` includes: > This is a utility method for testing; paths passed in to other > methods in this class are never converted automatically. and indeed, the actual impl of this method is found in an extension, in analyzer's test_utilities/ directory. It seems to me better to leave a testing utility as a testing utility, and not expose it in the public API of MemoryResourceProvider. Additionally, the extension method is used by `ResourceProviderMixin`, which is moving to the public analyzer_testing package. It is illegal to have a circular non-dev dependency between the analyzer package and the analyzer_testing package. The migration for the ~half dozen test files that use this method is to call the extension method directly. Sometimes with an extension override, and sometimes without. Change-Id: I9c2e18600461134bfd91c082b3af0d5079600f0c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426984 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent f9ca69a commit 739ca67

File tree

11 files changed

+126
-132
lines changed

11 files changed

+126
-132
lines changed

pkg/analysis_server/test/src/plugin/notification_manager_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:analysis_server/protocol/protocol.dart' as server;
66
import 'package:analysis_server/protocol/protocol_generated.dart' as server;
77
import 'package:analysis_server/src/channel/channel.dart';
88
import 'package:analysis_server/src/plugin/notification_manager.dart';
9+
import 'package:analyzer/file_system/file_system.dart';
910
import 'package:analyzer/file_system/memory_file_system.dart';
11+
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
1012
import 'package:analyzer_plugin/protocol/protocol_common.dart';
1113
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
1214
import 'package:test/test.dart';
@@ -40,7 +42,7 @@ class NotificationManagerTest extends ProtocolTestUtilities {
4042
late NotificationManager manager;
4143

4244
void setUp() {
43-
var provider = MemoryResourceProvider();
45+
ResourceProvider provider = MemoryResourceProvider();
4446
testDir = provider.convertPath('/test');
4547
fileA = provider.convertPath('/test/a.dart');
4648
fileB = provider.convertPath('/test/b.dart');

pkg/analyzer/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4535,7 +4535,7 @@ package:analyzer/file_system/memory_file_system.dart:
45354535
nextStamp (getter: int)
45364536
nextStamp= (setter: int)
45374537
pathContext (getter: Context)
4538-
convertPath (method: String Function(String))
4538+
convertPath (method: String Function(String), deprecated)
45394539
deleteFile (method: void Function(String))
45404540
deleteFolder (method: void Function(String))
45414541
getFile (method: File Function(String))

pkg/analyzer/lib/file_system/memory_file_system.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class MemoryResourceProvider implements ResourceProvider {
5757
///
5858
/// This is a utility method for testing; paths passed in to other methods in
5959
/// this class are never converted automatically.
60+
@Deprecated("Use 'ResourceProviderExtensions.convertPath' directly")
6061
String convertPath(String filePath) =>
6162
ResourceProviderExtensions(this).convertPath(filePath);
6263

@@ -135,7 +136,9 @@ class MemoryResourceProvider implements ResourceProvider {
135136

136137
@override
137138
Folder getStateLocation(String pluginId) {
138-
var path = convertPath('/user/home/$pluginId');
139+
var path = ResourceProviderExtensions(
140+
this,
141+
).convertPath('/user/home/$pluginId');
139142
return newFolder(path);
140143
}
141144

pkg/analyzer/test/file_system/memory_file_system_test.dart

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analyzer/source/file_source.dart';
1010
import 'package:analyzer/source/source.dart';
1111
import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
1212
import 'package:analyzer/src/generated/utilities_dart.dart';
13+
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
1314
import 'package:path/path.dart' as path;
1415
import 'package:test/test.dart';
1516
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -59,6 +60,9 @@ abstract class BaseTest extends FileSystemTestSupport {
5960
@override
6061
MemoryResourceProvider get provider => _provider ??= createProvider();
6162

63+
String convertPath(String filePath) =>
64+
ResourceProviderExtensions(provider).convertPath(filePath);
65+
6266
/// Create the resource provider to be used by the tests. Subclasses can
6367
/// override this method to change the class of resource provider that is
6468
/// used.
@@ -69,7 +73,7 @@ abstract class BaseTest extends FileSystemTestSupport {
6973
if (filePath == null) {
7074
filePath = defaultFilePath;
7175
} else {
72-
filePath = provider.convertPath(filePath);
76+
filePath = convertPath(filePath);
7377
}
7478
if (exists) {
7579
provider.newFile(filePath, content ?? defaultFileContent);
@@ -82,7 +86,7 @@ abstract class BaseTest extends FileSystemTestSupport {
8286
if (folderPath == null) {
8387
folderPath = defaultFolderPath;
8488
} else {
85-
folderPath = provider.convertPath(folderPath);
89+
folderPath = convertPath(folderPath);
8690
}
8791
if (exists) {
8892
provider.newFolder(folderPath);
@@ -92,17 +96,17 @@ abstract class BaseTest extends FileSystemTestSupport {
9296

9397
@override
9498
Link getLink({required String linkPath, String? target}) {
95-
linkPath = provider.convertPath(linkPath);
99+
linkPath = convertPath(linkPath);
96100
if (target != null) {
97-
target = provider.convertPath(target);
101+
target = convertPath(target);
98102

99103
provider.newLink(linkPath, target);
100104
}
101105
return provider.getLink(linkPath);
102106
}
103107

104108
setUp() {
105-
tempPath = provider.convertPath('/temp');
109+
tempPath = convertPath('/temp');
106110
defaultFolderPath = join(tempPath, 'bar');
107111
defaultFilePath = join(tempPath, 'bar', 'test.dart');
108112
}
@@ -184,16 +188,14 @@ class MemoryFileSourceExistingTest extends BaseTest {
184188
);
185189
expect(
186190
relative,
187-
provider.pathContext.toUri(
188-
provider.convertPath('/temp/bar/bar/baz.dart'),
189-
),
191+
provider.pathContext.toUri(convertPath('/temp/bar/bar/baz.dart')),
190192
);
191193
}
192194

193195
test_resolveRelative_dart() {
194196
File file = getFile(
195197
exists: false,
196-
filePath: provider.convertPath('/sdk/lib/core/core.dart'),
198+
filePath: convertPath('/sdk/lib/core/core.dart'),
197199
);
198200
Source source = FileSource(file, Uri.parse('dart:core'));
199201

@@ -238,9 +240,7 @@ class MemoryFileSourceNotExistingTest extends BaseTest {
238240
);
239241
expect(
240242
relative,
241-
provider.pathContext.toUri(
242-
provider.convertPath('/temp/bar/bar/baz.dart'),
243-
),
243+
provider.pathContext.toUri(convertPath('/temp/bar/bar/baz.dart')),
244244
);
245245
}
246246

@@ -296,12 +296,12 @@ class MemoryFileTest extends BaseTest with FileTestMixin {
296296
@reflectiveTest
297297
class MemoryFolderTest extends BaseTest with FolderTestMixin {
298298
test_isRoot_false() {
299-
var path = provider.convertPath('/foo');
299+
var path = convertPath('/foo');
300300
expect(provider.getFolder(path).isRoot, isFalse);
301301
}
302302

303303
test_isRoot_true() {
304-
var path = provider.convertPath('/');
304+
var path = convertPath('/');
305305
expect(provider.getFolder(path).isRoot, isTrue);
306306
}
307307
}
@@ -404,16 +404,13 @@ class MemoryResourceProviderTest extends BaseTest
404404
}
405405

406406
test_newLink_folder() {
407-
provider.newLink(
408-
provider.convertPath('/test/lib/foo'),
409-
provider.convertPath('/test/lib'),
410-
);
407+
provider.newLink(convertPath('/test/lib/foo'), convertPath('/test/lib'));
411408

412-
provider.newFile(provider.convertPath('/test/lib/a.dart'), 'aaa');
409+
provider.newFile(convertPath('/test/lib/a.dart'), 'aaa');
413410

414411
{
415412
var path = '/test/lib/foo/a.dart';
416-
var convertedPath = provider.convertPath(path);
413+
var convertedPath = convertPath(path);
417414
var file = provider.getFile(convertedPath);
418415
expect(file.exists, true);
419416
expect(file.modificationStamp, isNonNegative);
@@ -422,7 +419,7 @@ class MemoryResourceProviderTest extends BaseTest
422419

423420
{
424421
var path = '/test/lib/foo/foo/a.dart';
425-
var convertedPath = provider.convertPath(path);
422+
var convertedPath = convertPath(path);
426423
var file = provider.getFile(convertedPath);
427424
expect(file.exists, true);
428425
expect(file.modificationStamp, isNonNegative);
@@ -444,7 +441,7 @@ class MemoryResourceProviderTest extends BaseTest
444441
}
445442

446443
test_watch_createFile() {
447-
String rootPath = provider.convertPath('/my/path');
444+
String rootPath = convertPath('/my/path');
448445
provider.newFolder(rootPath);
449446
return _watchingFolder(rootPath, (changesReceived) {
450447
expect(changesReceived, hasLength(0));
@@ -460,7 +457,7 @@ class MemoryResourceProviderTest extends BaseTest
460457
}
461458

462459
test_watch_deleteFile() {
463-
String rootPath = provider.convertPath('/my/path');
460+
String rootPath = convertPath('/my/path');
464461
provider.newFolder(rootPath);
465462
String path = provider.pathContext.join(rootPath, 'foo');
466463
provider.newFile(path, 'contents 1');
@@ -477,7 +474,7 @@ class MemoryResourceProviderTest extends BaseTest
477474
}
478475

479476
test_watch_modifyFile() {
480-
String rootPath = provider.convertPath('/my/path');
477+
String rootPath = convertPath('/my/path');
481478
provider.newFolder(rootPath);
482479
String path = provider.pathContext.join(rootPath, 'foo');
483480
provider.newFile(path, 'contents 1');
@@ -494,7 +491,7 @@ class MemoryResourceProviderTest extends BaseTest
494491
}
495492

496493
test_watch_modifyFile_inSubDir() {
497-
String rootPath = provider.convertPath('/my/path');
494+
String rootPath = convertPath('/my/path');
498495
provider.newFolder(rootPath);
499496
String subdirPath = provider.pathContext.join(rootPath, 'foo');
500497
provider.newFolder(subdirPath);

0 commit comments

Comments
 (0)