Skip to content

Commit edde039

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate element_visitors_test
Change-Id: I5eb336b52380de3ad49d0dd9bced1f0dc7fc1cb8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403720 Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 31d8adf commit edde039

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ lib/src/services/refactoring/legacy/rename.dart
1313
lib/src/services/refactoring/legacy/rename_import.dart
1414
lib/src/services/search/element_visitors.dart
1515
test/services/refactoring/legacy/abstract_rename.dart
16-
test/services/search/element_visitors_test.dart

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/element.dart';
66
import 'package:analyzer/dart/element/element2.dart';
77
import 'package:analyzer/dart/element/visitor.dart';
88
import 'package:analyzer/dart/element/visitor2.dart';
9+
import 'package:analyzer/src/utilities/extensions/element.dart';
910

1011
/// Return the [Element] that is either [root], or one of its direct or
1112
/// indirect children, and has the given [nameOffset].
@@ -22,6 +23,11 @@ Element? findElementByNameOffset(Element? root, int nameOffset) {
2223
return null;
2324
}
2425

26+
/// Return the [Element2] that is either [root], or one of its direct or
27+
/// indirect children, and has the given [nameOffset].
28+
Element2? findElementByNameOffset2(Element2? root, int nameOffset) =>
29+
findElementByNameOffset(root.asElement, nameOffset).asElement2;
30+
2531
/// Uses [processor] to visit all of the children of [element].
2632
/// If [processor] returns `true`, then children of a child are visited too.
2733
void visitChildren(Element element, BoolElementProcessor processor) {

pkg/analysis_server/test/services/search/element_visitors_test.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analysis_server/src/services/search/element_visitors.dart';
6-
import 'package:analyzer/dart/element/element.dart';
7-
import 'package:analyzer/src/utilities/extensions/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
87
import 'package:test/test.dart';
98
import 'package:test_reflective_loader/test_reflective_loader.dart';
109

@@ -18,7 +17,7 @@ void main() {
1817

1918
@reflectiveTest
2019
class FindElementByNameOffsetTest extends AbstractSingleUnitTest {
21-
Element get testUnitElement => testLibraryElement.asElement;
20+
Element2 get testUnitElement => testLibraryElement;
2221

2322
Future<void> test_class() async {
2423
await resolveTestCode(r'''
@@ -43,13 +42,13 @@ void bbb() {}
4342
class AAA {}
4443
class BBB {}
4544
''');
46-
expect(findElementByNameOffset(null, 0), isNull);
45+
expect(findElementByNameOffset2(null, 0), isNull);
4746

48-
expect(findElementByNameOffset(testUnitElement, 0), isNull);
49-
expect(findElementByNameOffset(testUnitElement, 1), isNull);
47+
expect(findElementByNameOffset2(testUnitElement, 0), isNull);
48+
expect(findElementByNameOffset2(testUnitElement, 1), isNull);
5049

51-
expect(findElementByNameOffset(testUnitElement, 5), isNull);
52-
expect(findElementByNameOffset(testUnitElement, 7), isNull);
50+
expect(findElementByNameOffset2(testUnitElement, 5), isNull);
51+
expect(findElementByNameOffset2(testUnitElement, 7), isNull);
5352
}
5453

5554
Future<void> test_topLevelVariable() async {
@@ -63,8 +62,8 @@ int? ccc;
6362
}
6463

6564
void _assertElement(int nameOffset, ElementKind kind, String name) {
66-
var element = findElementByNameOffset(testUnitElement, nameOffset)!;
65+
var element = findElementByNameOffset2(testUnitElement, nameOffset)!;
6766
expect(element.kind, kind);
68-
expect(element.name, name);
67+
expect(element.name3, name);
6968
}
7069
}

0 commit comments

Comments
 (0)