Skip to content

Commit 8022910

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ConvertIntoIsNotEmpty.
Change-Id: I4e41db2de0ab39f969945582ebbc63bedbc90e30 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389763 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5e0f044 commit 8022910

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ lib/src/services/correction/dart/convert_into_final_field.dart
269269
lib/src/services/correction/dart/convert_into_for_index.dart
270270
lib/src/services/correction/dart/convert_into_getter.dart
271271
lib/src/services/correction/dart/convert_into_is_not.dart
272+
lib/src/services/correction/dart/convert_into_is_not_empty.dart
272273
lib/src/services/correction/dart/convert_map_from_iterable_to_for_literal.dart
273274
lib/src/services/correction/dart/convert_part_of_to_uri.dart
274275
lib/src/services/correction/dart/convert_quotes.dart
@@ -1515,4 +1516,4 @@ tool/spec/codegen_protocol_constants.dart
15151516
tool/spec/from_html.dart
15161517
tool/spec/generate_all.dart
15171518
tool/spec/implied_types.dart
1518-
tool/spec/to_html.dart
1519+
tool/spec/to_html.dart

pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not_empty.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class ConvertIntoIsNotEmpty extends ResolvedCorrectionProducer {
4545
return;
4646
}
4747
// should be "isEmpty"
48-
var propertyElement = isEmptyIdentifier.staticElement;
48+
var propertyElement = isEmptyIdentifier.element;
4949
if (propertyElement == null || 'isEmpty' != propertyElement.name) {
5050
return;
5151
}
5252
// should have "isNotEmpty"
53-
var propertyTarget = propertyElement.enclosingElement3;
53+
var propertyTarget = propertyElement.enclosingElement2;
5454
if (propertyTarget == null ||
55-
getChildren(propertyTarget, 'isNotEmpty').isEmpty) {
55+
getChildren2(propertyTarget, 'isNotEmpty').isEmpty) {
5656
return;
5757
}
5858
// should be in PrefixExpression

pkg/analysis_server/lib/src/services/search/hierarchy.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ List<Element> getChildren(Element parent, [String? name]) {
2222
return children;
2323
}
2424

25+
/// Returns direct children of [parent].
26+
List<Element2> getChildren2(Element2 parent, [String? name]) {
27+
var children = <Element2>[];
28+
visitChildren2(parent, (element) {
29+
if (name == null || _getBaseName2(element) == name) {
30+
children.add(element);
31+
}
32+
return false;
33+
});
34+
return children;
35+
}
36+
2537
/// Returns direct non-synthetic children of the given [InterfaceElement].
2638
///
2739
/// Includes: fields, accessors and methods.
@@ -311,3 +323,11 @@ String? _getBaseName(Element element) {
311323
}
312324
return element.name;
313325
}
326+
327+
String? _getBaseName2(Element2 element) {
328+
if (element is SetterElement) {
329+
var name = element.name;
330+
return name.substring(0, name.length - 1);
331+
}
332+
return element.name;
333+
}

0 commit comments

Comments
 (0)