Skip to content

Commit 5d27e4f

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes occurrences for extension and type parameters
Fixes: #60449 Change-Id: Ie862deea3d3d37890f1f610c7c83509fe82b2a40 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419423 Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]>
1 parent d4cb7a4 commit 5d27e4f

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
123123
super.visitEnumDeclaration(node);
124124
}
125125

126+
@override
127+
void visitExtensionDeclaration(ExtensionDeclaration node) {
128+
if (node case ExtensionDeclaration(:var declaredFragment?, :var name?)) {
129+
_addOccurrence(declaredFragment.element, name);
130+
}
131+
132+
super.visitExtensionDeclaration(node);
133+
}
134+
135+
@override
136+
void visitExtensionOverride(ExtensionOverride node) {
137+
_addOccurrence(node.element2, node.name);
138+
139+
super.visitExtensionOverride(node);
140+
}
141+
126142
@override
127143
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
128144
_addOccurrence(node.declaredFragment!.element, node.name);
@@ -146,6 +162,7 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
146162
@override
147163
void visitFunctionDeclaration(FunctionDeclaration node) {
148164
_addOccurrence(node.declaredFragment!.element, node.name);
165+
149166
super.visitFunctionDeclaration(node);
150167
}
151168

@@ -173,6 +190,7 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
173190
@override
174191
void visitMethodDeclaration(MethodDeclaration node) {
175192
_addOccurrence(node.declaredFragment!.element, node.name);
193+
176194
super.visitMethodDeclaration(node);
177195
}
178196

@@ -252,6 +270,15 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
252270
super.visitSuperFormalParameter(node);
253271
}
254272

273+
@override
274+
void visitTypeParameter(TypeParameter node) {
275+
if (node case TypeParameter(:var declaredFragment?)) {
276+
_addOccurrence(declaredFragment.element, node.name);
277+
}
278+
279+
super.visitTypeParameter(node);
280+
}
281+
255282
@override
256283
void visitVariableDeclaration(VariableDeclaration node) {
257284
_addOccurrence(node.declaredFragment!.element, node.name);

pkg/analysis_server/test/analysis/notification_occurrences_test.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ void f(E e) {
215215
''');
216216
}
217217

218+
Future<void> test_extension() async {
219+
await assertOccurrences(kind: ElementKind.EXTENSION, '''
220+
void foo(int i) {
221+
/*[0*/E/*0]*/(i).self;
222+
}
223+
224+
extension /*[1*/E/*1]*/<ThisType> on ThisType {
225+
ThisType get self => this;
226+
}
227+
''');
228+
}
229+
218230
Future<void> test_extensionType() async {
219231
await assertOccurrences(kind: ElementKind.EXTENSION_TYPE, '''
220232
extension type /*[0*/E/*0]*/(int it) {}
@@ -734,4 +746,64 @@ void f() {
734746
var offset = findOffset('void f()');
735747
findRegion(offset, 'void'.length, exists: false);
736748
}
749+
750+
Future<void> test_typeParameter_class() async {
751+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
752+
abstract class A</*[0*/ThisType/*0]*/> {
753+
/*[1*/ThisType/*1]*/ f();
754+
}
755+
''');
756+
}
757+
758+
Future<void> test_typeParameter_enum() async {
759+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
760+
enum E</*[0*/ThisType/*0]*/> {
761+
a;
762+
763+
/*[1*/ThisType/*1]*/ get t => throw UnimplementedError();
764+
}
765+
''');
766+
}
767+
768+
Future<void> test_typeParameter_extension() async {
769+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
770+
extension E</*[0*/ThisType/*0]*/> on /*[1*/ThisType/*1]*/ {
771+
/*[2*/ThisType/*2]*/ f() => this;
772+
}
773+
''');
774+
}
775+
776+
Future<void> test_typeParameter_extensionType() async {
777+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
778+
extension type Et</*[0*/ThisType/*0]*/>(/*[1*/ThisType/*1]*/ value) {
779+
/*[2*/ThisType/*2]*/ get v => value;
780+
}
781+
''');
782+
}
783+
784+
Future<void> test_typeParameter_function() async {
785+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
786+
/*[0*/ThisType/*0]*/ f</*[1*/ThisType/*1]*/>() => 0 as /*[2*/ThisType/*2]*/;
787+
''');
788+
}
789+
790+
Future<void> test_typeParameter_functionParameter() async {
791+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
792+
void f(/*[0*/ThisType/*0]*/ Function</*[1*/ThisType/*1]*/>() f) => f();
793+
''');
794+
}
795+
796+
Future<void> test_typeParameter_mixin() async {
797+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
798+
mixin M</*[0*/ThisType/*0]*/> {
799+
/*[1*/ThisType/*1]*/ get t;
800+
}
801+
''');
802+
}
803+
804+
Future<void> test_typeParameter_typedef() async {
805+
await assertOccurrences(kind: ElementKind.TYPE_PARAMETER, '''
806+
typedef TypeDef</*[0*/ThisType/*0]*/> = /*[1*/ThisType/*1]*/ Function(/*[2*/ThisType/*2]*/);
807+
''');
808+
}
737809
}

0 commit comments

Comments
 (0)