Skip to content

Commit 139a560

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate lib/src/services/search/hierarchy.dart
Change-Id: I4917d439dd5db00799958109505a6f2d88df26d6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399203 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent d74ead2 commit 139a560

19 files changed

+172
-265
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ lib/src/services/refactoring/legacy/rename_unit_member.dart
4545
lib/src/services/refactoring/legacy/visible_ranges_computer.dart
4646
lib/src/services/refactoring/move_top_level_to_file.dart
4747
lib/src/services/search/element_visitors.dart
48-
lib/src/services/search/hierarchy.dart
4948
lib/src/services/search/search_engine.dart
5049
lib/src/services/search/search_engine_internal.dart
5150
test/abstract_single_unit.dart

pkg/analysis_server/lib/src/cider/rename.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ class CanRenameResponse {
8383
);
8484
}
8585
// check if there are members with "newName" in the same ClassElement
86-
for (var newNameMember in getChildren(parentClass, newName)) {
86+
for (var newNameMember in getChildren(parentClass.asElement2, newName)) {
8787
var message = format(
8888
"Class '{0}' already declares {1} with name '{2}'.",
8989
parentClass.displayName,
90-
getElementKindName(newNameMember.asElement2!),
90+
getElementKindName(newNameMember),
9191
newName,
9292
);
93-
result.addError(message, newLocation_fromElement(newNameMember));
93+
result.addError(
94+
message,
95+
newLocation_fromElement(newNameMember.asElement),
96+
);
9497
}
9598
}
9699

pkg/analysis_server/lib/src/search/element_references.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:analysis_server/src/services/search/hierarchy.dart';
88
import 'package:analysis_server/src/services/search/search_engine.dart';
99
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:analyzer/src/util/performance/operation_performance.dart';
11+
import 'package:analyzer/src/utilities/extensions/element.dart';
1112

1213
/// A computer for `search.findElementReferences` request results.
1314
class ElementReferencesComputer {
@@ -85,23 +86,26 @@ class ElementReferencesComputer {
8586
OperationPerformanceImpl performance,
8687
) async {
8788
if (element is ParameterElement && element.isNamed) {
88-
return await performance.runAsync(
89+
return (await performance.runAsync(
8990
'getHierarchyNamedParameters',
90-
(_) => getHierarchyNamedParameters(searchEngine, element),
91-
);
91+
(_) => getHierarchyNamedParameters(searchEngine, element.asElement2),
92+
)).map((e) => e.asElement);
9293
}
9394
if (element is ClassMemberElement) {
9495
var (members, parameters) = await performance.runAsync(
9596
'getHierarchyMembers',
9697
(performance) => getHierarchyMembersAndParameters(
9798
searchEngine,
98-
element,
99+
element.asElement2!,
99100
performance: performance,
100101
includeParametersForFields: true,
101102
),
102103
);
103104

104-
return {...members, ...parameters};
105+
return {
106+
...members.map((e) => e.asElement!),
107+
...parameters.map((e) => e.asElement),
108+
};
105109
}
106110
return [element];
107111
}

pkg/analysis_server/lib/src/search/type_hierarchy.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:analysis_server/src/services/search/hierarchy.dart';
1010
import 'package:analysis_server/src/services/search/search_engine.dart';
1111
import 'package:analyzer/dart/element/element.dart';
1212
import 'package:analyzer/dart/element/type.dart';
13+
import 'package:analyzer/src/utilities/extensions/element.dart';
1314

1415
/// A computer for a type hierarchy of an [Element].
1516
class TypeHierarchyComputer {
@@ -54,23 +55,23 @@ class TypeHierarchyComputer {
5455
) async {
5556
var subElements = await getDirectSubClasses(
5657
_searchEngine,
57-
classElement,
58+
classElement.asElement2,
5859
searchEngineCache,
5960
);
6061
var subItemIds = <int>[];
6162
for (var subElement in subElements) {
6263
// check for recursion
63-
var subItem = _elementItemMap[subElement];
64+
var subItem = _elementItemMap[subElement.asElement];
6465
if (subItem != null) {
6566
var id = _items.indexOf(subItem);
6667
item.subclasses.add(id);
6768
continue;
6869
}
6970
// create a subclass item
70-
var subMemberElement = helper.findMemberElement(subElement);
71+
var subMemberElement = helper.findMemberElement(subElement.asElement);
7172
var subMemberElementDeclared = subMemberElement?.nonSynthetic;
7273
subItem = TypeHierarchyItem(
73-
convertElement(subElement),
74+
convertElement(subElement.asElement),
7475
memberElement:
7576
subMemberElementDeclared != null
7677
? convertElement(subMemberElementDeclared)
@@ -79,9 +80,9 @@ class TypeHierarchyComputer {
7980
);
8081
var subItemId = _items.length;
8182
// remember
82-
_elementItemMap[subElement] = subItem;
83+
_elementItemMap[subElement.asElement] = subItem;
8384
_items.add(subItem);
84-
_itemClassElements.add(subElement);
85+
_itemClassElements.add(subElement.asElement);
8586
// add to hierarchy
8687
item.subclasses.add(subItemId);
8788
subItemIds.add(subItemId);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class ChangeTo extends ResolvedCorrectionProducer {
357357
_ClosestElementFinder finder,
358358
InterfaceElement2 clazz,
359359
) {
360-
var members = getMembers2(clazz);
360+
var members = getMembers(clazz);
361361
finder._updateList(members);
362362
}
363363

@@ -366,7 +366,7 @@ class ChangeTo extends ResolvedCorrectionProducer {
366366
ExtensionElement2? element,
367367
) {
368368
if (element != null) {
369-
finder._updateList(getExtensionMembers2(element));
369+
finder._updateList(getExtensionMembers(element));
370370
}
371371
}
372372
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ConvertIntoIsNotEmpty extends ResolvedCorrectionProducer {
5353
// should have "isNotEmpty"
5454
var propertyTarget = propertyElement.enclosingElement2;
5555
if (propertyTarget == null ||
56-
getChildren2(propertyTarget, 'isNotEmpty').isEmpty) {
56+
getChildren(propertyTarget, 'isNotEmpty').isEmpty) {
5757
return;
5858
}
5959
// should be in PrefixExpression

pkg/analysis_server/lib/src/services/refactoring/agnostic/change_method_signature.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,11 @@ class _SignatureUpdater {
662662
Future<List<ExecutableElement>> computeElements() async {
663663
var element = selectionState.element;
664664
if (element case ClassMemberElement member) {
665-
var set = await getHierarchyMembers(searchEngine, member);
666-
return set.whereType<ExecutableElement>().toList();
665+
var set = await getHierarchyMembers(searchEngine, member.asElement2!);
666+
return set
667+
.whereType<ExecutableElement2>()
668+
.map((e) => e.asElement)
669+
.toList();
667670
}
668671
return [element];
669672
}

pkg/analysis_server/lib/src/services/refactoring/legacy/convert_getter_to_method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ConvertGetterToMethodRefactoringImpl extends RefactoringImpl
6060
if (field is FieldElement2 &&
6161
(field.enclosingElement2 is InterfaceElement2 ||
6262
field.enclosingElement2 is ExtensionElement2)) {
63-
var elements = await getHierarchyMembers2(searchEngine, field);
63+
var elements = await getHierarchyMembers(searchEngine, field);
6464
await Future.forEach(elements, (Element2 member) async {
6565
if (member is FieldElement2) {
6666
var getter = member.getter2;

pkg/analysis_server/lib/src/services/refactoring/legacy/convert_method_to_getter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
5959
}
6060
// MethodElement
6161
if (element is MethodElement2) {
62-
var elements = await getHierarchyMembers2(searchEngine, element);
62+
var elements = await getHierarchyMembers(searchEngine, element);
6363
await Future.forEach(elements, (Element2 element) async {
6464
await _updateElementDeclaration(element as ExecutableElement2);
6565
return _updateElementReferences(element);

pkg/analysis_server/lib/src/services/refactoring/legacy/inline_method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Set<String> _getNamesConflictingAt(AstNode node) {
182182
enclosingInterfaceElement,
183183
];
184184
for (var interfaceElement in elements) {
185-
var classMembers = getChildren2(interfaceElement);
185+
var classMembers = getChildren(interfaceElement);
186186
for (var classMemberElement in classMembers) {
187187
result.add(classMemberElement.displayName);
188188
}

0 commit comments

Comments
 (0)