mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 20:21:21 +00:00
[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 <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
599836a2c5
commit
9b4cda1bfd
|
@ -161,14 +161,6 @@ class TransformSetErrorCode extends ErrorCode {
|
|||
"The key 'static' is only supported for elements in a class, enum, "
|
||||
"extension, or mixin.");
|
||||
|
||||
/**
|
||||
* No parameters.
|
||||
*/
|
||||
static const TransformSetErrorCode unsupportedUriChange = TransformSetErrorCode(
|
||||
'unsupported_uri_change',
|
||||
"The set of URIs for the replacement element must match the transformed "
|
||||
"element.");
|
||||
|
||||
/**
|
||||
* No parameters.
|
||||
*/
|
||||
|
|
|
@ -162,13 +162,6 @@ class TransformSetParser {
|
|||
return _translateTransformSet(map);
|
||||
}
|
||||
|
||||
bool _equalUris(List<Uri> oldUris, List<Uri> newUris) {
|
||||
var oldSet = oldUris.toSet();
|
||||
var newSet = newUris.toSet();
|
||||
return oldSet.difference(newSet).isEmpty &&
|
||||
newSet.difference(oldSet).isEmpty;
|
||||
}
|
||||
|
||||
/// Convert the given [template] into a list of components. Variable
|
||||
/// references in the template are looked up in the map of [generators].
|
||||
List<TemplateComponent> _extractTemplateComponents(
|
||||
|
@ -877,10 +870,6 @@ class TransformSetParser {
|
|||
}
|
||||
var oldElement = elementBeingTransformed;
|
||||
if (oldElement != null) {
|
||||
if (!_equalUris(oldElement.libraryUris, newElement.libraryUris)) {
|
||||
_reportError(TransformSetErrorCode.unsupportedUriChange,
|
||||
(node.valueAt(_newElementKey) as YamlMap).valueAt(_urisKey)!);
|
||||
}
|
||||
var compatibleTypes = compatibleReplacementTypes[oldElement.kind];
|
||||
if (compatibleTypes == null) {
|
||||
_reportError(
|
||||
|
|
|
@ -24,7 +24,6 @@ import 'unexpected_token_test.dart' as unexpected_token;
|
|||
import 'unknown_accessor_test.dart' as unknown_accessor;
|
||||
import 'unsupported_key_test.dart' as unsupported_key;
|
||||
import 'unsupported_static_test.dart' as unsupported_static;
|
||||
import 'unsupported_uri_change_test.dart' as unsupported_uri_change;
|
||||
import 'unsupported_version_test.dart' as unsupported_version;
|
||||
import 'wrong_token_test.dart' as wrong_token;
|
||||
import 'yaml_syntax_error_test.dart' as yaml_syntax_error;
|
||||
|
@ -51,7 +50,6 @@ void main() {
|
|||
unknown_accessor.main();
|
||||
unsupported_key.main();
|
||||
unsupported_static.main();
|
||||
unsupported_uri_change.main();
|
||||
unsupported_version.main();
|
||||
wrong_token.main();
|
||||
yaml_syntax_error.main();
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../transform_set_parser_test_support.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(UnsupportedUriChangeTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class UnsupportedUriChangeTest extends AbstractTransformSetParserTest {
|
||||
void test_integer() {
|
||||
assertErrors('''
|
||||
version: 1
|
||||
transforms:
|
||||
- title: 'Replace'
|
||||
date: 2021-11-30
|
||||
element:
|
||||
uris: ['test.dart']
|
||||
function: 'f'
|
||||
changes:
|
||||
- kind: 'replacedBy'
|
||||
newElement:
|
||||
uris: ['other.dart']
|
||||
function: 'g'
|
||||
''', [
|
||||
error(TransformSetErrorCode.unsupportedUriChange, 182, 14),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -164,7 +164,7 @@ void f(New o) {}
|
|||
''', errorFilter: ignoreUnusedImport);
|
||||
}
|
||||
|
||||
Future<void> test_replaceBy() async {
|
||||
Future<void> test_replacedBy() async {
|
||||
addSdkDataFile('''
|
||||
version: 1
|
||||
transforms:
|
||||
|
|
|
@ -883,6 +883,39 @@ ${newImport}var x = $prefixReference${newElement.reference}$invocation;
|
|||
|
||||
@reflectiveTest
|
||||
class ReplacedByUriSemanticsTest extends DataDrivenFixProcessorTest {
|
||||
Future<void> test_different_uris() async {
|
||||
setPackageContent('''
|
||||
@deprecated
|
||||
double oldSin(num n) => 1;
|
||||
''');
|
||||
addPackageDataFile('''
|
||||
version: 1
|
||||
transforms:
|
||||
- title: 'Replace with different uri'
|
||||
date: 2022-09-28
|
||||
element:
|
||||
uris: ['$importUri']
|
||||
function: 'oldSin'
|
||||
changes:
|
||||
- kind: 'replacedBy'
|
||||
newElement:
|
||||
uris: ['dart:math']
|
||||
function: 'sin'
|
||||
''');
|
||||
await resolveTestCode('''
|
||||
import '$importUri';
|
||||
|
||||
var x = oldSin(1);
|
||||
''');
|
||||
await assertHasFix('''
|
||||
import 'dart:math';
|
||||
|
||||
import '$importUri';
|
||||
|
||||
var x = sin(1);
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_new_element_uris_multiple() async {
|
||||
setPackageContent('');
|
||||
newFile('$workspaceRootPath/p/lib/expect.dart', '''
|
||||
|
@ -894,7 +927,7 @@ export 'expect.dart';
|
|||
addPackageDataFile('''
|
||||
version: 1
|
||||
transforms:
|
||||
- title: 'Replace expect'
|
||||
- title: 'Replace expect'
|
||||
date: 2022-05-12
|
||||
bulkApply: false
|
||||
element:
|
||||
|
@ -928,7 +961,7 @@ f() {
|
|||
addPackageDataFile('''
|
||||
version: 1
|
||||
transforms:
|
||||
- title: 'Replace expect'
|
||||
- title: 'Replace expect'
|
||||
date: 2022-05-12
|
||||
bulkApply: false
|
||||
element:
|
||||
|
|
Loading…
Reference in a new issue