Version 2.16.0-74.0.dev
Merge commit 'bc8133c3fb2069d4483bc90ca85f9acbf585b750' into 'dev'
diff --git a/DEPS b/DEPS
index 434e57a..74b90b2 100644
--- a/DEPS
+++ b/DEPS
@@ -79,8 +79,8 @@
"bazel_worker_rev": "ceeba0982d4ff40d32371c9d35f3d2dc1868de20",
"benchmark_harness_rev": "c546dbd9f639f75cd2f75de8df2eb9f8ea15e8e7",
"boolean_selector_rev": "665e6921ab246569420376f827bff4585dff0b14",
- "boringssl_gen_rev": "7322fc15cc065d8d2957fccce6b62a509dc4d641",
- "boringssl_rev" : "1607f54fed72c6589d560254626909a64124f091",
+ "boringssl_gen_rev": "ced85ef0a00bbca77ce5a91261a5f2ae61b1e62f",
+ "boringssl_rev" : "87f316d7748268eb56f2dc147bd593254ae93198",
"browser-compat-data_tag": "v1.0.22",
"browser_launcher_rev": "c6cc1025d6901926cf022e144ba109677e3548f1",
"characters_rev": "6ec389c4dfa8fce14820dc5cbf6e693202e7e052",
diff --git a/pkg/analysis_server/lib/src/services/completion/yaml/fix_data_generator.dart b/pkg/analysis_server/lib/src/services/completion/yaml/fix_data_generator.dart
index 15ef594..d57592a 100644
--- a/pkg/analysis_server/lib/src/services/completion/yaml/fix_data_generator.dart
+++ b/pkg/analysis_server/lib/src/services/completion/yaml/fix_data_generator.dart
@@ -16,27 +16,7 @@
'title': EmptyProducer(),
'date': EmptyProducer(),
'bulkApply': BooleanProducer(),
- 'element': MapProducer({
- // TODO(brianwilkerson) Support suggesting uris.
- 'uris': EmptyProducer(),
- 'class': EmptyProducer(),
- 'constant': EmptyProducer(),
- 'constructor': EmptyProducer(),
- 'enum': EmptyProducer(),
- 'extension': EmptyProducer(),
- 'field': EmptyProducer(),
- 'function': EmptyProducer(),
- 'getter': EmptyProducer(),
- 'method': EmptyProducer(),
- 'mixin': EmptyProducer(),
- 'setter': EmptyProducer(),
- 'typedef': EmptyProducer(),
- 'variable': EmptyProducer(),
- 'inClass': EmptyProducer(),
- 'inEnum': EmptyProducer(),
- 'inExtension': EmptyProducer(),
- 'inMixin': EmptyProducer(),
- }),
+ 'element': _elementProducer,
'changes': _changesProducer,
'oneOf': ListProducer(MapProducer({
'if': EmptyProducer(),
@@ -56,6 +36,7 @@
'removeParameter',
'rename',
'renameParameter',
+ 'replacedBy',
]),
'index': EmptyProducer(),
'name': EmptyProducer(),
@@ -69,8 +50,32 @@
'extends': EmptyProducer(),
'oldName': EmptyProducer(),
'newName': EmptyProducer(),
+ 'newElement': _elementProducer,
}));
+ /// The producer representing the known valid structure of an element.
+ static const MapProducer _elementProducer = MapProducer({
+ // TODO(brianwilkerson) Support suggesting uris.
+ 'uris': EmptyProducer(),
+ 'class': EmptyProducer(),
+ 'constant': EmptyProducer(),
+ 'constructor': EmptyProducer(),
+ 'enum': EmptyProducer(),
+ 'extension': EmptyProducer(),
+ 'field': EmptyProducer(),
+ 'function': EmptyProducer(),
+ 'getter': EmptyProducer(),
+ 'method': EmptyProducer(),
+ 'mixin': EmptyProducer(),
+ 'setter': EmptyProducer(),
+ 'typedef': EmptyProducer(),
+ 'variable': EmptyProducer(),
+ 'inClass': EmptyProducer(),
+ 'inEnum': EmptyProducer(),
+ 'inExtension': EmptyProducer(),
+ 'inMixin': EmptyProducer(),
+ });
+
/// Initialize a newly created suggestion generator for fix data files.
FixDataGenerator(ResourceProvider resourceProvider)
: super(resourceProvider, null);
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_kind.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_kind.dart
index a3fb8b1..4da8683 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_kind.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_kind.dart
@@ -20,6 +20,38 @@
}
extension ElementKindUtilities on ElementKind {
+ /// Return a human readable name for the kind.
+ String get displayName {
+ switch (this) {
+ case ElementKind.classKind:
+ return 'class';
+ case ElementKind.constantKind:
+ return 'constant';
+ case ElementKind.constructorKind:
+ return 'constructor';
+ case ElementKind.enumKind:
+ return 'enum';
+ case ElementKind.extensionKind:
+ return 'extension';
+ case ElementKind.fieldKind:
+ return 'field';
+ case ElementKind.functionKind:
+ return 'function';
+ case ElementKind.getterKind:
+ return 'getter';
+ case ElementKind.methodKind:
+ return 'method';
+ case ElementKind.mixinKind:
+ return 'mixin';
+ case ElementKind.setterKind:
+ return 'setter';
+ case ElementKind.typedefKind:
+ return 'typedef';
+ case ElementKind.variableKind:
+ return 'variable';
+ }
+ }
+
/// Return the element kind corresponding to the given [name].
static ElementKind? fromName(String name) {
for (var kind in ElementKind.values) {
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
index 49751f1..837025a 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart
@@ -342,20 +342,27 @@
// If the old class has been removed then this might have been a
// constructor invocation.
ElementKind.constructorKind,
+ ElementKind.functionKind, // tear-off
ElementKind.getterKind,
ElementKind.setterKind,
ElementKind.variableKind
];
}
return const [
+ ElementKind.constantKind,
ElementKind.fieldKind,
+ ElementKind.functionKind, // tear-off
ElementKind.getterKind,
+ ElementKind.methodKind, // tear-off
ElementKind.setterKind
];
} else if (node is PropertyAccess) {
return const [
+ ElementKind.constantKind,
ElementKind.fieldKind,
+ ElementKind.functionKind, // tear-off, prefixed
ElementKind.getterKind,
+ ElementKind.methodKind, // tear-off, prefixed
ElementKind.setterKind
];
} else if (node is SimpleIdentifier) {
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/replaced_by.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/replaced_by.dart
new file mode 100644
index 0000000..92e23b9
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/replaced_by.dart
@@ -0,0 +1,140 @@
+// 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/dart/data_driven.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/change.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/element_descriptor.dart';
+import 'package:analyzer/dart/ast/ast.dart';
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/source/source_range.dart';
+import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
+import 'package:analyzer_plugin/utilities/range_factory.dart';
+
+/// The data related to an element that has been replaced by another element.
+class ReplacedBy extends Change<_Data> {
+ /// The replacing element.
+ final ElementDescriptor newElement;
+
+ /// Initialize a newly created transform to describe a replacement of an old
+ /// element by a [newElement].
+ ReplacedBy({required this.newElement});
+
+ @override
+ void apply(DartFileEditBuilder builder, DataDrivenFix fix, _Data data) {
+ var referenceRange = data.referenceRange;
+ builder.addSimpleReplacement(referenceRange, _referenceTo(newElement));
+ }
+
+ @override
+ _Data? validate(DataDrivenFix fix) {
+ var node = fix.node;
+ if (node is SimpleIdentifier) {
+ var components = fix.element.components;
+ if (components.isEmpty) {
+ return null;
+ } else if (components.length == 1) {
+ if (components[0] != node.name) {
+ return null;
+ }
+ // We have an '<element>' pattern, so we replace the name.
+ return _Data(range.node(node));
+ }
+ // The element being replaced is a member in a top-level element.
+ var containerName = components[1];
+ if (components[0].isEmpty && containerName == node.name) {
+ // We have a '<className>()' pattern, so we replace the class name.
+ return _Data(range.node(node));
+ }
+ var parent = node.parent;
+ if (parent is MethodInvocation) {
+ var target = parent.target;
+ if (target == null) {
+ // We have a '<member>()' pattern, so we replace the member name.
+ return _Data(range.node(node));
+ } else if (target is SimpleIdentifier && target.name == containerName) {
+ // We have a '<container>.<member>()' pattern, so we replace both parts.
+ return _Data(range.startEnd(target, node));
+ } else if (target is PrefixedIdentifier) {
+ if (target.prefix.staticElement is PrefixElement &&
+ target.identifier.name == containerName) {
+ // We have a '<prefix>.<container>.<member>()' pattern so we leave
+ // the prefix while replacing the rest.
+ return _Data(range.startEnd(target.identifier, node));
+ }
+ // We shouldn't get here.
+ return null;
+ }
+ } else if (parent is PrefixedIdentifier) {
+ if (parent.prefix.staticElement is PrefixElement) {
+ // We have a '<prefix>.<topLevel>' pattern so we leave the prefix
+ // while replacing the rest.
+ return _Data(range.node(node));
+ }
+ // We have a '<container>.<member>' pattern so we replace both parts.
+ return _Data(range.node(parent));
+ } else if (parent is PropertyAccess) {
+ var target = parent.target;
+ if (target is PrefixedIdentifier) {
+ // We have a '<prefix>.<container>.<member>' pattern so we leave the
+ // prefix while replacing the rest.
+ return _Data(range.startEnd(target.identifier, node));
+ }
+ // We have a '<container>.<member>' pattern so we replace both parts.
+ return _Data(range.node(parent));
+ }
+ // We have a '<member>' pattern so we replace the member name.
+ return _Data(range.node(node));
+ } else if (node is PrefixedIdentifier) {
+ var parent = node.parent;
+ if (parent is NamedType) {
+ var identifier = node.identifier;
+ var components = fix.element.components;
+ if (components.length > 1 &&
+ components[0].isEmpty &&
+ components[1] == identifier.name) {
+ // We have a '<prefix>.<className>' pattern, so we replace only the
+ // class name.
+ return _Data(range.node(identifier));
+ }
+ }
+ } else if (node is ConstructorName) {
+ var typeName = node.type2.name;
+ SimpleIdentifier classNameNode;
+ if (typeName is SimpleIdentifier) {
+ classNameNode = typeName;
+ } else if (typeName is PrefixedIdentifier) {
+ classNameNode = typeName.identifier;
+ } else {
+ return null;
+ }
+ var constructorNameNode = node.name;
+ var constructorName = constructorNameNode?.name ?? '';
+ var components = fix.element.components;
+ if (components.length == 2 &&
+ constructorName == components[0] &&
+ classNameNode.name == components[1]) {
+ if (constructorNameNode != null) {
+ return _Data(range.startEnd(classNameNode, constructorNameNode));
+ }
+ return _Data(range.node(classNameNode));
+ }
+ }
+ return null;
+ }
+
+ String _referenceTo(ElementDescriptor element) {
+ var components = element.components;
+ if (components[0].isEmpty) {
+ return components[1];
+ }
+ return components.reversed.join('.');
+ }
+}
+
+/// The data about a reference to an element that's been replaced.
+class _Data {
+ final SourceRange referenceRange;
+
+ _Data(this.referenceRange);
+}
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart
index 1c992e0..42aeba2 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_error_code.dart
@@ -25,6 +25,26 @@
/**
* Parameters:
+ * 0: the old kind
+ * 1: the new kind
+ */
+ static const TransformSetErrorCode incompatibleElementKind =
+ TransformSetErrorCode(
+ 'incompatible_element_kind',
+ "An element of kind '{0}' can't be replaced by "
+ "an element of kind '{1}'.");
+
+ /**
+ * Parameters:
+ * 0: the change kind that is invalid
+ * 1: the element kind for the transform
+ */
+ static const TransformSetErrorCode invalidChangeForKind =
+ TransformSetErrorCode('invalid_change_for_kind',
+ "A change of type '{0}' can't be used for an element of kind '{1}'.");
+
+ /**
+ * Parameters:
* 0: the character that is invalid
*/
static const TransformSetErrorCode invalidCharacter =
@@ -136,6 +156,14 @@
/**
* 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.
+ */
static const TransformSetErrorCode unsupportedVersion = TransformSetErrorCode(
'unsupported_version', "Only version '1' is supported at this time.");
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart
index 4605bd6..dc8184c 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/transform_set_parser.dart
@@ -14,6 +14,7 @@
import 'package:analysis_server/src/services/correction/fix/data_driven/parameter_reference.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/rename.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/rename_parameter.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/replaced_by.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/transform.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart';
@@ -64,6 +65,7 @@
static const String _methodKey = 'method';
static const String _mixinKey = 'mixin';
static const String _nameKey = 'name';
+ static const String _newElementKey = 'newElement';
static const String _newNameKey = 'newName';
static const String _oldNameKey = 'oldName';
static const String _oneOfKey = 'oneOf';
@@ -97,6 +99,7 @@
static const String _removeParameterKind = 'removeParameter';
static const String _renameKind = 'rename';
static const String _renameParameterKind = 'renameParameter';
+ static const String _replacedByKind = 'replacedBy';
/// The valid values for the [_styleKey] in an [_addParameterKind] change.
static const List<String> validStyles = [
@@ -106,6 +109,11 @@
'required_positional'
];
+ /// A table mapping the kinds of elements that can be replaced by a different
+ /// element to a set of the kinds of elements with which they can be replaced.
+ static final Map<ElementKind, Set<ElementKind>> compatibleReplacementTypes =
+ _createCompatibleReplacementTypes();
+
static const String _openComponent = '{%';
static const String _closeComponent = '%}';
@@ -125,6 +133,12 @@
/// found.
final String packageName;
+ /// The description of the element that is being transformed by the current
+ /// transformation, or `null` if we are not in the process of parsing a
+ /// transformation or if the element associated with the transformation is not
+ /// valid.
+ ElementDescriptor? elementBeingTransformed;
+
/// The variable scope defined for the current transform.
VariableScope transformVariableScope = VariableScope.empty;
@@ -147,6 +161,13 @@
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(
@@ -446,6 +467,8 @@
return _translateRenameChange(node);
} else if (kind == _renameParameterKind) {
return _translateRenameParameterChange(node);
+ } else if (kind == _replacedByKind) {
+ return _translateReplacedByChange(node);
}
return _reportInvalidValueOneOf(kindNode, kindContext, [
_addParameterKind,
@@ -453,6 +476,7 @@
_removeParameterKind,
_renameKind,
_renameParameterKind,
+ _replacedByKind,
]);
} else {
return _reportInvalidValue(node, context, 'Map');
@@ -821,6 +845,41 @@
return RenameParameter(newName: newName, oldName: oldName);
}
+ /// Translate the [node] into a replaced_by change. Return the resulting
+ /// change, or `null` if the [node] does not represent a valid replaced_by
+ /// change.
+ ReplacedBy? _translateReplacedByChange(YamlMap node) {
+ _reportUnsupportedKeys(node, const {_kindKey, _newElementKey});
+ var newElement = _translateElement(node.valueAt(_newElementKey),
+ ErrorContext(key: _newElementKey, parentNode: node));
+ if (newElement == null) {
+ // The error has already been reported.
+ return null;
+ }
+ 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(
+ TransformSetErrorCode.invalidChangeForKind,
+ node.valueAt(_newElementKey)!,
+ [_replacedByKind, oldElement.kind.displayName]);
+ return null;
+ } else if (!compatibleTypes.contains(newElement.kind)) {
+ _reportError(
+ TransformSetErrorCode.incompatibleElementKind,
+ node.valueAt(_newElementKey)!,
+ [oldElement.kind.displayName, newElement.kind.displayName]);
+ return null;
+ }
+ }
+ return ReplacedBy(newElement: newElement);
+ }
+
/// Translate the [node] into a string. Return the resulting string, or `null`
/// if the [node] doesn't represent a valid string. If the [node] isn't valid,
/// use the [context] to report the error. If the [node] doesn't exist and
@@ -893,6 +952,7 @@
true;
var element = _translateElement(node.valueAt(_elementKey),
ErrorContext(key: _elementKey, parentNode: node));
+ elementBeingTransformed = element;
transformVariableScope = _translateTemplateVariables(
node.valueAt(_variablesKey),
ErrorContext(key: _variablesKey, parentNode: node));
@@ -1032,4 +1092,43 @@
return _reportInvalidValue(node, context, 'Map');
}
}
+
+ static Map<ElementKind, Set<ElementKind>>
+ _createCompatibleReplacementTypes() {
+ var types = <ElementKind, Set<ElementKind>>{};
+
+ void addSet(Set<ElementKind> set) {
+ for (var kind in set) {
+ types.putIfAbsent(kind, () => {}).addAll(set);
+ }
+ }
+
+ // Constructors can replace constructors.
+ addSet({
+ ElementKind.constructorKind,
+ });
+ // Static methods and top-level functions can replace each other.
+ addSet({
+ ElementKind.functionKind,
+ ElementKind.methodKind,
+ });
+ // Static getters and getter-inducing elements can replace each other.
+ addSet({
+ ElementKind.constantKind,
+ ElementKind.fieldKind,
+ ElementKind.getterKind,
+ ElementKind.variableKind,
+ });
+ // Static setters and setter-inducing elements can replace each other.
+ // TODO(brianwilkerson) We can't currently distinguish between final and
+ // non-final elements, but we don't support replacing setters with final
+ // elements, nor vice versa. We need a way to distinguish these cases if we
+ // want to be able to report an error.
+ addSet({
+ ElementKind.fieldKind,
+ ElementKind.setterKind,
+ ElementKind.variableKind,
+ });
+ return types;
+ }
}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/incompatible_element_kind_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/incompatible_element_kind_test.dart
new file mode 100644
index 0000000..4561ddd
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/incompatible_element_kind_test.dart
@@ -0,0 +1,37 @@
+// 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(IncompatibleElementKindTest);
+ });
+}
+
+@reflectiveTest
+class IncompatibleElementKindTest extends AbstractTransformSetParserTest {
+ void test_integer() {
+ assertErrors('''
+version: 1
+transforms:
+- title: 'Replace'
+ date: 2021-11-30
+ element:
+ uris: ['test.dart']
+ method: 'm'
+ inClass: 'C'
+ changes:
+ - kind: 'replacedBy'
+ newElement:
+ uris: ['test.dart']
+ variable: 'v'
+''', [
+ error(TransformSetErrorCode.incompatibleElementKind, 191, 42),
+ ]);
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/invalid_change_for_kind_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/invalid_change_for_kind_test.dart
new file mode 100644
index 0000000..ee118e9
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/invalid_change_for_kind_test.dart
@@ -0,0 +1,36 @@
+// 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(InvalidChangeForKindTest);
+ });
+}
+
+@reflectiveTest
+class InvalidChangeForKindTest extends AbstractTransformSetParserTest {
+ void test_integer() {
+ assertErrors('''
+version: 1
+transforms:
+- title: 'Replace'
+ date: 2021-11-30
+ element:
+ uris: ['test.dart']
+ class: 'C'
+ changes:
+ - kind: 'replacedBy'
+ newElement:
+ uris: ['test.dart']
+ class: 'D'
+''', [
+ error(TransformSetErrorCode.invalidChangeForKind, 173, 39),
+ ]);
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart
index bb2464ae..375c983 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/test_all.dart
@@ -6,6 +6,8 @@
import 'conflicting_key_test.dart' as conflicting_key;
import 'expected_primary_test.dart' as expected_primary;
+import 'incompatible_element_kind_test.dart' as incompatible_element_kind;
+import 'invalid_change_for_kind_test.dart' as invalid_change_for_kind;
import 'invalid_character_test.dart' as invalid_character;
import 'invalid_key_test.dart' as invalid_key;
import 'invalid_parameter_style_test.dart' as invalid_parameter_style;
@@ -21,6 +23,7 @@
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_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;
@@ -29,6 +32,8 @@
defineReflectiveSuite(() {
conflicting_key.main();
expected_primary.main();
+ incompatible_element_kind.main();
+ invalid_change_for_kind.main();
invalid_character.main();
invalid_key.main();
invalid_parameter_style.main();
@@ -44,6 +49,7 @@
unexpected_token.main();
unknown_accessor.main();
unsupported_key.main();
+ unsupported_uri_change.main();
unsupported_version.main();
wrong_token.main();
yaml_syntax_error.main();
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/unsupported_uri_change_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/unsupported_uri_change_test.dart
new file mode 100644
index 0000000..ecc493a
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/diagnostics/unsupported_uri_change_test.dart
@@ -0,0 +1,36 @@
+// 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),
+ ]);
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/element_matcher_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/element_matcher_test.dart
index e9e0363..16ec4ae 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/element_matcher_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/element_matcher_test.dart
@@ -41,8 +41,11 @@
class ElementMatcherComponentAndKindTest extends AbstractElementMatcherTest {
/// The kinds that are expected where a getter or setter is allowed.
static List<ElementKind> accessorKinds = [
+ ElementKind.constantKind,
ElementKind.fieldKind,
+ ElementKind.functionKind, // tear-off
ElementKind.getterKind,
+ ElementKind.methodKind, // tear-off
ElementKind.setterKind,
];
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart
new file mode 100644
index 0000000..03d89fe
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/replaced_by_test.dart
@@ -0,0 +1,1069 @@
+// 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/changes_selector.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/element_descriptor.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/replaced_by.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/transform.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import 'data_driven_test_support.dart';
+
+void main() {
+ defineReflectiveSuite(() {
+ defineReflectiveTests(ReplacedByTest);
+ });
+}
+
+@reflectiveTest
+class ReplacedByTest extends DataDrivenFixProcessorTest {
+ Future<void> test_defaultConstructor_defaultConstructor() async {
+ await _assertReplacement(
+ _Element.defaultConstructor(isDeprecated: true, isOld: true),
+ _Element.defaultConstructor(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_defaultConstructor_defaultConstructor_prefixed() async {
+ await _assertReplacement(
+ _Element.defaultConstructor(isDeprecated: true, isOld: true),
+ _Element.defaultConstructor(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_defaultConstructor_namedConstructor() async {
+ await _assertReplacement(
+ _Element.defaultConstructor(isDeprecated: true, isOld: true),
+ _Element.namedConstructor(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_defaultConstructor_namedConstructor_prefixed() async {
+ await _assertReplacement(
+ _Element.defaultConstructor(isDeprecated: true, isOld: true),
+ _Element.namedConstructor(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_enumConstant_enumConstant() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ );
+ }
+
+ Future<void> test_enumConstant_enumConstant_prefixed() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_enumConstant_staticField() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ );
+ }
+
+ Future<void> test_enumConstant_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_enumConstant_staticGetter() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ );
+ }
+
+ Future<void> test_enumConstant_staticGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_enumConstant_topLevelGetter() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ );
+ }
+
+ Future<void> test_enumConstant_topLevelGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_enumConstant_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ );
+ }
+
+ Future<void> test_enumConstant_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.constant(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_function_function_invocation() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.topLevelFunction(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_function_function_invocation_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.topLevelFunction(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_function_function_tearoff() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.topLevelFunction(),
+ );
+ }
+
+ Future<void> test_function_function_tearoff_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.topLevelFunction(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_function_staticMethod_invocation() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.method(isStatic: true),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_function_staticMethod_invocation_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.method(isStatic: true),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_function_staticMethod_tearoff() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.method(isStatic: true),
+ );
+ }
+
+ Future<void> test_function_staticMethod_tearoff_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelFunction(isDeprecated: true, isOld: true),
+ _Element.method(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_namedConstructor_defaultConstructor() async {
+ await _assertReplacement(
+ _Element.namedConstructor(isDeprecated: true, isOld: true),
+ _Element.defaultConstructor(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_namedConstructor_defaultConstructor_prefixed() async {
+ await _assertReplacement(
+ _Element.namedConstructor(isDeprecated: true, isOld: true),
+ _Element.defaultConstructor(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_namedConstructor_namedConstructor() async {
+ await _assertReplacement(
+ _Element.namedConstructor(isDeprecated: true, isOld: true),
+ _Element.namedConstructor(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_namedConstructor_namedConstructor_prefixed() async {
+ await _assertReplacement(
+ _Element.namedConstructor(isDeprecated: true, isOld: true),
+ _Element.namedConstructor(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_enumConstant() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.constant(),
+ );
+ }
+
+ Future<void> test_staticField_enumConstant_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.constant(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_staticField() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ );
+ }
+
+ Future<void> test_staticField_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_staticGetter() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.getter(isStatic: true),
+ );
+ }
+
+ Future<void> test_staticField_staticGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.getter(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_staticSetter() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticField_staticSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_topLevelGetter() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelGetter(),
+ );
+ }
+
+ Future<void> test_staticField_topLevelGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelGetter(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_topLevelSetter() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticField_topLevelSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticField_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ );
+ }
+
+ Future<void> test_staticField_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.field(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticGetter_enumConstant() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.constant(),
+ );
+ }
+
+ Future<void> test_staticGetter_enumConstant_prefixed() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.constant(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticGetter_staticField() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ );
+ }
+
+ Future<void> test_staticGetter_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticGetter_staticGetter() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.getter(isStatic: true),
+ );
+ }
+
+ Future<void> test_staticGetter_staticGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.getter(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticGetter_topLevelGetter() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelGetter(),
+ );
+ }
+
+ Future<void> test_staticGetter_topLevelGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelGetter(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticGetter_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ );
+ }
+
+ Future<void> test_staticGetter_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.getter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticMethod_function_invocation() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelFunction(),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_staticMethod_function_invocation_prefixed() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelFunction(),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticMethod_function_tearoff() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelFunction(),
+ );
+ }
+
+ Future<void> test_staticMethod_function_tearoff_prefixed() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelFunction(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticMethod_staticMethod_invocation() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.method(isStatic: true),
+ isInvocation: true,
+ );
+ }
+
+ Future<void> test_staticMethod_staticMethod_invocation_prefixed() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.method(isStatic: true),
+ isInvocation: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticMethod_staticMethod_tearoff() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.method(isStatic: true),
+ );
+ }
+
+ Future<void> test_staticMethod_staticMethod_tearoff_prefixed() async {
+ await _assertReplacement(
+ _Element.method(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.method(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticSetter_staticField() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticSetter_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.field(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticSetter_staticSetter() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticSetter_staticSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticSetter_topLevelSetter() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticSetter_topLevelSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_staticSetter_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_staticSetter_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.setter(isDeprecated: true, isOld: true, isStatic: true),
+ _Element.topLevelVariable(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelGetter_enumConstant() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ );
+ }
+
+ Future<void> test_topLevelGetter_enumConstant_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelGetter_staticField() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ );
+ }
+
+ Future<void> test_topLevelGetter_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelGetter_staticGetter() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ );
+ }
+
+ Future<void> test_topLevelGetter_staticGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelGetter_topLevelGetter() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ );
+ }
+
+ Future<void> test_topLevelGetter_topLevelGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelGetter_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ );
+ }
+
+ Future<void> test_topLevelGetter_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelGetter(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_staticField() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_staticSetter() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_staticSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_topLevelSetter() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_topLevelSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelSetter_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelSetter(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_enumConstant() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ );
+ }
+
+ Future<void> test_topLevelVariable_enumConstant_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.constant(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticField() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticField_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.field(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticGetter() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.getter(isStatic: true),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticSetter() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_staticSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.setter(isStatic: true),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelGetter() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelGetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelGetter(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelSetter() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelSetter_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelSetter(),
+ isAssignment: true,
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelVariable() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ );
+ }
+
+ Future<void> test_topLevelVariable_topLevelVariable_prefixed() async {
+ await _assertReplacement(
+ _Element.topLevelVariable(isDeprecated: true, isOld: true),
+ _Element.topLevelVariable(),
+ isPrefixed: true,
+ );
+ }
+
+ Future<void> _assertReplacement(_Element oldElement, _Element newElement,
+ {bool isAssignment = false,
+ bool isInvocation = false,
+ bool isPrefixed = false}) async {
+ assert(!(isAssignment && isInvocation));
+ setPackageContent('''
+${oldElement.declaration}
+${newElement.declaration}
+''');
+ setPackageData(_replacedBy(oldElement.kind, oldElement.components,
+ newElement.kind, newElement.components));
+ var prefixDeclaration = isPrefixed ? ' as p' : '';
+ var prefixReference = isPrefixed ? 'p.' : '';
+ var invocation = isInvocation ? '()' : '';
+ if (isAssignment) {
+ await resolveTestCode('''
+import '$importUri'$prefixDeclaration;
+
+void g() {
+ $prefixReference${oldElement.reference} = 0;
+}
+''');
+ await assertHasFix('''
+import '$importUri'$prefixDeclaration;
+
+void g() {
+ $prefixReference${newElement.reference} = 0;
+}
+''');
+ return;
+ }
+ await resolveTestCode('''
+import '$importUri'$prefixDeclaration;
+
+var x = $prefixReference${oldElement.reference}$invocation;
+''');
+ await assertHasFix('''
+import '$importUri'$prefixDeclaration;
+
+var x = $prefixReference${newElement.reference}$invocation;
+''');
+ }
+
+ Transform _replacedBy(ElementKind oldKind, List<String> oldComponents,
+ ElementKind newKind, List<String> newComponents) {
+ var uris = [Uri.parse(importUri)];
+ var oldElement = ElementDescriptor(
+ libraryUris: uris, kind: oldKind, components: oldComponents);
+ var newElement2 = ElementDescriptor(
+ libraryUris: uris, kind: newKind, components: newComponents);
+ return Transform(
+ title: 'title',
+ date: DateTime.now(),
+ element: oldElement,
+ bulkApply: true,
+ changesSelector: UnconditionalChangesSelector([
+ ReplacedBy(newElement: newElement2),
+ ]));
+ }
+}
+
+class _Element {
+ final ElementKind kind;
+ final List<String> components;
+ final String declaration;
+
+ _Element(this.kind, this.components, this.declaration);
+
+ // ignore: unused_element
+ factory _Element.class_({bool isDeprecated = false, bool isOld = false}) {
+ var name = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated, isTopLevel: true);
+ return _Element(
+ ElementKind.classKind,
+ [name],
+ '''
+${annotation}class $name {}''',
+ );
+ }
+
+ factory _Element.constant({bool isDeprecated = false, bool isOld = false}) {
+ var enumName = isOld ? 'E_old' : 'E_new';
+ var constantName = isOld ? 'c_old' : 'c_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.constantKind,
+ [constantName, enumName],
+ '''
+enum $enumName {
+ $annotation$constantName
+}''',
+ );
+ }
+
+ factory _Element.defaultConstructor(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.constructorKind,
+ ['', className],
+ '''
+class $className {
+ $annotation$className();
+}''',
+ );
+ }
+
+ // ignore: unused_element
+ factory _Element.enum_({bool isDeprecated = false, bool isOld = false}) {
+ var enumName = isOld ? 'E_old' : 'E_new';
+ var constantName = isOld ? 'c_old' : 'c_new';
+ var annotation = _annotation(isDeprecated: isDeprecated, isTopLevel: true);
+ return _Element(
+ ElementKind.enumKind,
+ [enumName],
+ '''
+${annotation}enum $enumName { $constantName }''',
+ );
+ }
+
+ factory _Element.field(
+ {bool isDeprecated = false, bool isOld = false, bool isStatic = false}) {
+ var fieldName = isOld ? 'sf_old' : 'sf_new';
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ var keyword = isStatic ? 'static ' : '';
+ return _Element(
+ ElementKind.fieldKind,
+ [fieldName, className],
+ '''
+class $className {
+ $annotation${keyword}int $fieldName = 0;
+}''',
+ );
+ }
+
+ factory _Element.getter(
+ {bool isDeprecated = false, bool isOld = false, bool isStatic = false}) {
+ var getterName = isOld ? 'g_old' : 'g_new';
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ var keyword = isStatic ? 'static ' : '';
+ return _Element(
+ ElementKind.getterKind,
+ [getterName, className],
+ '''
+class $className {
+ $annotation${keyword}int get $getterName => 0;
+}''',
+ );
+ }
+
+ factory _Element.method(
+ {bool isDeprecated = false, bool isOld = false, bool isStatic = false}) {
+ var methodName = isOld ? 'm_old' : 'm_new';
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ var keyword = isStatic ? 'static ' : '';
+ return _Element(
+ ElementKind.methodKind,
+ [methodName, className],
+ '''
+class $className {
+ $annotation${keyword}int $methodName() => 0;
+}''',
+ );
+ }
+
+ factory _Element.namedConstructor(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var constructorName = isOld ? 'c_old' : 'c_new';
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.constructorKind,
+ [constructorName, className],
+ '''
+class $className {
+ $annotation$className.$constructorName();
+}''',
+ );
+ }
+
+ factory _Element.setter(
+ {bool isDeprecated = false, bool isOld = false, bool isStatic = false}) {
+ var setterName = isOld ? 's_old' : 's_new';
+ var className = isOld ? 'C_old' : 'C_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ var keyword = isStatic ? 'static ' : '';
+ return _Element(
+ ElementKind.setterKind,
+ [setterName, className],
+ '''
+class $className {
+ $annotation${keyword}set $setterName(int v) {}
+}''',
+ );
+ }
+
+ factory _Element.topLevelFunction(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var name = isOld ? 'f_old' : 'f_new';
+ var annotation = _annotation(isDeprecated: isDeprecated, isTopLevel: true);
+ return _Element(
+ ElementKind.functionKind,
+ [name],
+ '''
+${annotation}int $name() => 0;''',
+ );
+ }
+
+ factory _Element.topLevelGetter(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var getterName = isOld ? 'g_old' : 'g_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.getterKind,
+ [getterName],
+ '''
+${annotation}int get $getterName => 0;''',
+ );
+ }
+
+ factory _Element.topLevelSetter(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var setterName = isOld ? 's_old' : 's_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.setterKind,
+ [setterName],
+ '''
+${annotation}set $setterName(int v) {}''',
+ );
+ }
+
+ factory _Element.topLevelVariable(
+ {bool isDeprecated = false, bool isOld = false}) {
+ var name = isOld ? 'v_old' : 'v_new';
+ var annotation = _annotation(isDeprecated: isDeprecated, isTopLevel: true);
+ return _Element(
+ ElementKind.variableKind,
+ [name],
+ '''
+${annotation}int $name = 0;''',
+ );
+ }
+
+ // ignore: unused_element
+ factory _Element.typedef({bool isDeprecated = false, bool isOld = false}) {
+ var name = isOld ? 'T_old' : 'T_new';
+ var annotation = _annotation(isDeprecated: isDeprecated);
+ return _Element(
+ ElementKind.typedefKind,
+ [name],
+ '''
+${annotation}typedef $name = int Function();''',
+ );
+ }
+
+ String get reference {
+ if (components[0].isEmpty) {
+ return components[1];
+ }
+ return components.reversed.join('.');
+ }
+
+ static String _annotation(
+ {required bool isDeprecated, bool isTopLevel = false}) {
+ var indent = isTopLevel ? '' : ' ';
+ return isDeprecated ? '@deprecated\n$indent' : '';
+ }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
index 64cffa2..544f27c 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/test_all.dart
@@ -15,6 +15,7 @@
import 'modify_parameters_test.dart' as modify_parameters;
import 'rename_parameter_test.dart' as rename_parameter;
import 'rename_test.dart' as rename;
+import 'replaced_by_test.dart' as replaced_by;
import 'sdk_fix_test.dart' as sdk_fix;
import 'transform_override_set_parser_test.dart'
as transform_override_set_parser;
@@ -34,6 +35,7 @@
modify_parameters.main();
rename_parameter.main();
rename.main();
+ replaced_by.main();
sdk_fix.main();
transform_override_set_parser.main();
transform_set_manager.main();
diff --git a/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_parser_test.dart b/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_parser_test.dart
index 08c69d5..51421b4 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_parser_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/data_driven/transform_set_parser_test.dart
@@ -7,11 +7,13 @@
import 'package:analysis_server/src/services/correction/fix/data_driven/change.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/changes_selector.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/code_template.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/element_kind.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/element_matcher.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/expression.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/modify_parameters.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/parameter_reference.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/rename.dart';
+import 'package:analysis_server/src/services/correction/fix/data_driven/replaced_by.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/transform.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/transform_set_error_code.dart';
import 'package:analysis_server/src/services/correction/fix/data_driven/value_generator.dart';
@@ -673,6 +675,34 @@
expect(rename.newName, 'B');
}
+ void test_replacedBy() {
+ assertNoErrors('''
+version: 1
+transforms:
+- title: 'Replace'
+ date: 2021-11-30
+ element:
+ uris: ['test.dart']
+ function: 'f'
+ changes:
+ - kind: 'replacedBy'
+ newElement:
+ uris: ['test.dart']
+ method: 'm'
+ inClass: 'C'
+''');
+ var transforms = _transforms('f');
+ expect(transforms, hasLength(1));
+ var transform = transforms[0];
+ expect(transform.title, 'Replace');
+ var changes = _changes(transform);
+ expect(changes, hasLength(1));
+ var change = changes[0] as ReplacedBy;
+ var newElement = change.newElement;
+ expect(newElement.kind, ElementKind.methodKind);
+ expect(newElement.components, ['m', 'C']);
+ }
+
void test_requiredIf() {
assertNoErrors('''
version: 1
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 1f513c1..beabb03 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -335,7 +335,7 @@
/// Compute [_constants] in all units.
void _computeConstants() {
computeConstants(_typeProvider, _typeSystem, _declaredVariables,
- _constants.toList(), _analysisOptions.experimentStatus);
+ _constants.toList(), _libraryElement.featureSet);
}
void _computeHints(FileState file, CompilationUnit unit) {
diff --git a/pkg/analyzer/lib/src/dart/constant/compute.dart b/pkg/analyzer/lib/src/dart/constant/compute.dart
index 295c41c..cb56ffe 100644
--- a/pkg/analyzer/lib/src/dart/constant/compute.dart
+++ b/pkg/analyzer/lib/src/dart/constant/compute.dart
@@ -3,8 +3,8 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/analysis/declared_variables.dart';
+import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/element/type_provider.dart';
-import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/dart/constant/evaluation.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
@@ -17,8 +17,8 @@
TypeSystemImpl typeSystem,
DeclaredVariables declaredVariables,
List<ConstantEvaluationTarget> constants,
- ExperimentStatus experimentStatus) {
- var walker = _ConstantWalker(declaredVariables, experimentStatus);
+ FeatureSet featureSet) {
+ var walker = _ConstantWalker(declaredVariables, featureSet);
for (var constant in constants) {
var node = walker._getNode(constant);
@@ -47,10 +47,10 @@
/// [graph.DependencyWalker] for computing constants and detecting cycles.
class _ConstantWalker extends graph.DependencyWalker<_ConstantNode> {
final DeclaredVariables declaredVariables;
- final ExperimentStatus experimentStatus;
+ final FeatureSet featureSet;
final Map<ConstantEvaluationTarget, _ConstantNode> nodeMap = {};
- _ConstantWalker(this.declaredVariables, this.experimentStatus);
+ _ConstantWalker(this.declaredVariables, this.featureSet);
@override
void evaluate(_ConstantNode node) {
@@ -79,7 +79,7 @@
ConstantEvaluationEngine _getEvaluationEngine(_ConstantNode node) {
return ConstantEvaluationEngine(
declaredVariables: declaredVariables,
- isNonNullableByDefault: experimentStatus.non_nullable,
+ isNonNullableByDefault: featureSet.isEnabled(Feature.non_nullable),
);
}
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 4a949fb..d491590 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -34,8 +34,7 @@
show Namespace, NamespaceBuilder;
import 'package:analyzer/src/dart/resolver/variance.dart';
import 'package:analyzer/src/generated/element_type_provider.dart';
-import 'package:analyzer/src/generated/engine.dart'
- show AnalysisContext, AnalysisOptionsImpl;
+import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
import 'package:analyzer/src/generated/source.dart';
@@ -1572,9 +1571,8 @@
/// of formal parameters, are evaluated.
void computeConstantDependencies() {
if (!isConstantEvaluated) {
- var analysisOptions = context.analysisOptions as AnalysisOptionsImpl;
computeConstants(library.typeProvider, library.typeSystem,
- context.declaredVariables, [this], analysisOptions.experimentStatus);
+ context.declaredVariables, [this], library.featureSet);
}
}
}
@@ -1650,9 +1648,8 @@
/// of this variable could not be computed because of errors.
DartObject? computeConstantValue() {
if (evaluationResult == null) {
- var analysisOptions = context.analysisOptions as AnalysisOptionsImpl;
computeConstants(library!.typeProvider, library!.typeSystem,
- context.declaredVariables, [this], analysisOptions.experimentStatus);
+ context.declaredVariables, [this], library!.featureSet);
}
return evaluationResult?.value;
}
@@ -1982,10 +1979,9 @@
@override
DartObject? computeConstantValue() {
if (evaluationResult == null) {
- var analysisOptions = context.analysisOptions as AnalysisOptionsImpl;
var library = compilationUnit.library;
computeConstants(library.typeProvider, library.typeSystem,
- context.declaredVariables, [this], analysisOptions.experimentStatus);
+ context.declaredVariables, [this], library.featureSet);
}
return evaluationResult?.value;
}
diff --git a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
index e904ee0..0b096be 100644
--- a/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/micro/library_analyzer.dart
@@ -197,7 +197,7 @@
/// Compute [_constants] in all units.
void _computeConstants() {
computeConstants(_typeProvider, _typeSystem, _declaredVariables,
- _constants.toList(), _analysisOptions.experimentStatus);
+ _constants.toList(), _libraryElement.featureSet);
}
void _computeDiagnostics({
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index 95f08a1..8b32896 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -16,7 +16,6 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/file_system/file_system.dart' as file_system;
-import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/constant/compute.dart';
@@ -29,11 +28,7 @@
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart'
- show
- AnalysisErrorInfo,
- AnalysisErrorInfoImpl,
- AnalysisOptions,
- AnalysisOptionsImpl;
+ show AnalysisErrorInfo, AnalysisErrorInfoImpl, AnalysisOptions;
import 'package:analyzer/src/generated/resolver.dart' show ScopeResolverVisitor;
import 'package:analyzer/src/generated/source.dart' show LineInfo;
import 'package:analyzer/src/lint/analysis.dart';
@@ -384,7 +379,7 @@
typeSystem,
declaredVariables,
dependencies,
- libraryElement.featureSet as ExperimentStatus,
+ libraryElement.featureSet,
);
var visitor = ConstantVisitor(
@@ -492,7 +487,7 @@
typeSystem,
declaredVariables,
dependenciesFinder.dependencies.toList(),
- (analysisOptions as AnalysisOptionsImpl).experimentStatus,
+ libraryElement.featureSet,
);
var listener = _ConstantAnalysisErrorListener();
diff --git a/pkg/analyzer/lib/src/workspace/bazel.dart b/pkg/analyzer/lib/src/workspace/bazel.dart
index 13f0edb..e8f24d5 100644
--- a/pkg/analyzer/lib/src/workspace/bazel.dart
+++ b/pkg/analyzer/lib/src/workspace/bazel.dart
@@ -140,7 +140,7 @@
String pathInLib = components.skip(4).join('/');
return [packageName, pathInLib];
} else {
- for (int i = 2; i < components.length - 1; i++) {
+ for (int i = components.length - 2; i >= 2; i--) {
String component = components[i];
if (component == 'lib') {
String packageName = components.getRange(0, i).join('.');
diff --git a/pkg/analyzer/test/src/dart/analysis/index_test.dart b/pkg/analyzer/test/src/dart/analysis/index_test.dart
index cecd83d..29798f2 100644
--- a/pkg/analyzer/test/src/dart/analysis/index_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/index_test.dart
@@ -1155,6 +1155,18 @@
assertThat(element)..isReferencedAt('test: 0', true);
}
+ test_isReferencedBy_ParameterElement_optionalNamed_ofTopFunction_anywhere() async {
+ await _indexTestUnit('''
+void foo(int a, int b, {int? test}) {}
+
+void() {
+ foo(1, test: 0, 2);
+}
+''');
+ Element element = findElement.parameter('test');
+ assertThat(element)..isReferencedAt('test: 0', true);
+ }
+
test_isReferencedBy_ParameterElement_optionalPositional() async {
await _indexTestUnit('''
foo([p]) {
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index 2140a33..612ac02 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -1417,6 +1417,25 @@
await _verifyReferences(element, expected);
}
+ test_searchReferences_ParameterElement_optionalNamed_anywhere() async {
+ await resolveTestCode('''
+foo(int a, int b, {p}) {
+ p;
+}
+main() {
+ foo(0, p: 1, 2);
+}
+''');
+ var element = findElement.parameter('p');
+ var foo = findElement.function('foo');
+ var main = findElement.function('main');
+ var expected = [
+ _expectId(foo, SearchResultKind.READ, 'p;'),
+ _expectIdQ(main, SearchResultKind.REFERENCE, 'p: 1')
+ ];
+ await _verifyReferences(element, expected);
+ }
+
test_searchReferences_ParameterElement_optionalPositional() async {
await resolveTestCode('''
foo([p]) {
diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
index 652108c..09360c4 100644
--- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
@@ -1524,11 +1524,7 @@
'c',
errorCodes: [CompileTimeErrorCode.INVALID_CONSTANT],
);
- if (analysisOptions.experimentStatus.constant_update_2018) {
- expect(result.toIntValue(), 1);
- } else {
- expect(result, isNull);
- }
+ expect(result.toIntValue(), 1);
}
test_visitConditionalExpression_eager_true_invalid_int() async {
diff --git a/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_num_string_test.dart b/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_num_string_test.dart
index 8acf4e9..b4bcb41 100644
--- a/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_num_string_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/const_eval_type_bool_num_string_test.dart
@@ -2,7 +2,6 @@
// 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:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -17,21 +16,14 @@
@reflectiveTest
class ConstEvalTypeBoolNumStringTest extends PubPackageResolutionTest {
test_equal() async {
- await assertErrorsInCode(
- r'''
+ await assertNoErrorsInCode(r'''
class A {
const A();
}
const num a = 0;
const b = a == const A();
-''',
- IsEnabledByDefault.constant_update_2018
- ? []
- : [
- error(CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING, 53,
- 14),
- ]);
+''');
}
test_notEqual() async {
diff --git a/pkg/analyzer/test/src/workspace/bazel_test.dart b/pkg/analyzer/test/src/workspace/bazel_test.dart
index 0177638..bdfa730 100644
--- a/pkg/analyzer/test/src/workspace/bazel_test.dart
+++ b/pkg/analyzer/test/src/workspace/bazel_test.dart
@@ -545,6 +545,15 @@
'package:third_party.something/foo.dart');
}
+ void test_restoreAbsolute_workspace_nestedLib() {
+ _addResources([
+ '/workspace/WORKSPACE',
+ '/workspace/my/components/lib/src/foo/lib/foo.dart',
+ ]);
+ _assertRestore('/workspace/my/components/lib/src/foo/lib/foo.dart',
+ 'package:my.components.lib.src.foo/foo.dart');
+ }
+
void _addResources(List<String> paths,
{String workspacePath = '/workspace'}) {
for (String path in paths) {
diff --git a/runtime/vm/BUILD.gn b/runtime/vm/BUILD.gn
index 69dfc4b..1b03265 100644
--- a/runtime/vm/BUILD.gn
+++ b/runtime/vm/BUILD.gn
@@ -56,6 +56,9 @@
if (!is_android) {
libs += [ "pthread" ]
}
+ if (!is_mac) {
+ libs += [ "atomic" ]
+ }
}
}
diff --git a/tools/VERSION b/tools/VERSION
index aaeea35..02dcfb9 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 16
PATCH 0
-PRERELEASE 73
+PRERELEASE 74
PRERELEASE_PATCH 0
\ No newline at end of file
diff --git a/tools/bots/flutter/analyze_flutter_flutter.sh b/tools/bots/flutter/analyze_flutter_flutter.sh
index d040021..cd50561 100755
--- a/tools/bots/flutter/analyze_flutter_flutter.sh
+++ b/tools/bots/flutter/analyze_flutter_flutter.sh
@@ -36,9 +36,7 @@
$dart --enable-asserts dev/bots/analyze.dart --dart-sdk $sdk
# Test flutter's use of data-driven fixes.
-pushd packages/flutter/test_fixes
-../../../bin/dart fix --compare-to-golden
-popd
+$dart fix packages/flutter/test_fixes --compare-to-golden
# Analyze the sample code in dartdoc snippets.
-./bin/dart dev/bots/analyze_sample_code.dart
+$dart dev/bots/analyze_sample_code.dart