Skip to content

Commit 9b4cda1

Browse files
asashourCommit Queue
authored and
Commit Queue
committed
[analysis_server] DataDriven: allow replacedBy from a package to another one
Bug: #48204 Change-Id: Id13f038e39e9e150e1d6b21bcdde25bb815b15a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241004 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 599836a commit 9b4cda1

File tree

6 files changed

+36
-60
lines changed

6 files changed

+36
-60
lines changed

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ class TransformSetErrorCode extends ErrorCode {
161161
"The key 'static' is only supported for elements in a class, enum, "
162162
"extension, or mixin.");
163163

164-
/**
165-
* No parameters.
166-
*/
167-
static const TransformSetErrorCode unsupportedUriChange = TransformSetErrorCode(
168-
'unsupported_uri_change',
169-
"The set of URIs for the replacement element must match the transformed "
170-
"element.");
171-
172164
/**
173165
* No parameters.
174166
*/

pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ class TransformSetParser {
162162
return _translateTransformSet(map);
163163
}
164164

165-
bool _equalUris(List<Uri> oldUris, List<Uri> newUris) {
166-
var oldSet = oldUris.toSet();
167-
var newSet = newUris.toSet();
168-
return oldSet.difference(newSet).isEmpty &&
169-
newSet.difference(oldSet).isEmpty;
170-
}
171-
172165
/// Convert the given [template] into a list of components. Variable
173166
/// references in the template are looked up in the map of [generators].
174167
List<TemplateComponent> _extractTemplateComponents(
@@ -877,10 +870,6 @@ class TransformSetParser {
877870
}
878871
var oldElement = elementBeingTransformed;
879872
if (oldElement != null) {
880-
if (!_equalUris(oldElement.libraryUris, newElement.libraryUris)) {
881-
_reportError(TransformSetErrorCode.unsupportedUriChange,
882-
(node.valueAt(_newElementKey) as YamlMap).valueAt(_urisKey)!);
883-
}
884873
var compatibleTypes = compatibleReplacementTypes[oldElement.kind];
885874
if (compatibleTypes == null) {
886875
_reportError(

pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import 'unexpected_token_test.dart' as unexpected_token;
2424
import 'unknown_accessor_test.dart' as unknown_accessor;
2525
import 'unsupported_key_test.dart' as unsupported_key;
2626
import 'unsupported_static_test.dart' as unsupported_static;
27-
import 'unsupported_uri_change_test.dart' as unsupported_uri_change;
2827
import 'unsupported_version_test.dart' as unsupported_version;
2928
import 'wrong_token_test.dart' as wrong_token;
3029
import 'yaml_syntax_error_test.dart' as yaml_syntax_error;
@@ -51,7 +50,6 @@ void main() {
5150
unknown_accessor.main();
5251
unsupported_key.main();
5352
unsupported_static.main();
54-
unsupported_uri_change.main();
5553
unsupported_version.main();
5654
wrong_token.main();
5755
yaml_syntax_error.main();

pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/unsupported_uri_change_test.dart

Lines changed: 0 additions & 36 deletions
This file was deleted.

pkg/analysis_server/test/src/services/correction/fix/data_driven/end_to_end_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void f(New o) {}
164164
''', errorFilter: ignoreUnusedImport);
165165
}
166166

167-
Future<void> test_replaceBy() async {
167+
Future<void> test_replacedBy() async {
168168
addSdkDataFile('''
169169
version: 1
170170
transforms:

pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,39 @@ ${newImport}var x = $prefixReference${newElement.reference}$invocation;
883883

884884
@reflectiveTest
885885
class ReplacedByUriSemanticsTest extends DataDrivenFixProcessorTest {
886+
Future<void> test_different_uris() async {
887+
setPackageContent('''
888+
@deprecated
889+
double oldSin(num n) => 1;
890+
''');
891+
addPackageDataFile('''
892+
version: 1
893+
transforms:
894+
- title: 'Replace with different uri'
895+
date: 2022-09-28
896+
element:
897+
uris: ['$importUri']
898+
function: 'oldSin'
899+
changes:
900+
- kind: 'replacedBy'
901+
newElement:
902+
uris: ['dart:math']
903+
function: 'sin'
904+
''');
905+
await resolveTestCode('''
906+
import '$importUri';
907+
908+
var x = oldSin(1);
909+
''');
910+
await assertHasFix('''
911+
import 'dart:math';
912+
913+
import '$importUri';
914+
915+
var x = sin(1);
916+
''');
917+
}
918+
886919
Future<void> test_new_element_uris_multiple() async {
887920
setPackageContent('');
888921
newFile('$workspaceRootPath/p/lib/expect.dart', '''
@@ -894,7 +927,7 @@ export 'expect.dart';
894927
addPackageDataFile('''
895928
version: 1
896929
transforms:
897-
- title: 'Replace expect'
930+
- title: 'Replace expect'
898931
date: 2022-05-12
899932
bulkApply: false
900933
element:
@@ -928,7 +961,7 @@ f() {
928961
addPackageDataFile('''
929962
version: 1
930963
transforms:
931-
- title: 'Replace expect'
964+
- title: 'Replace expect'
932965
date: 2022-05-12
933966
bulkApply: false
934967
element:

0 commit comments

Comments
 (0)