Skip to content

Commit 52dc876

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes extension instance member occurrences
Fixes: #60626 Change-Id: Ia1050fe54f9c2ff208092b00ecccce678b7e616a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424688 Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 08c541a commit 52dc876

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
306306
Element? canonicalElement = element;
307307
if (canonicalElement is FieldFormalParameterElement) {
308308
canonicalElement = canonicalElement.field2;
309-
} else if (canonicalElement is PropertyAccessorElement) {
310-
canonicalElement = canonicalElement.variable3;
309+
} else if (canonicalElement case PropertyAccessorElement(
310+
:var variable3?,
311+
) when !variable3.isSynthetic) {
312+
canonicalElement = variable3;
311313
}
312314
return canonicalElement?.baseElement;
313315
}

pkg/analysis_server/test/analysis/notification_occurrences_test.dart

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void f(E e) {
177177
}
178178

179179
Future<void> test_enum_getter() async {
180-
await assertOccurrences(kind: ElementKind.FIELD, '''
180+
await assertOccurrences(kind: ElementKind.GETTER, '''
181181
enum E {
182182
v;
183183
int get /*[0*/foo/*0]*/ => 0;
@@ -203,7 +203,7 @@ void f(E e) {
203203
}
204204

205205
Future<void> test_enum_setter() async {
206-
await assertOccurrences(kind: ElementKind.FIELD, '''
206+
await assertOccurrences(kind: ElementKind.SETTER, '''
207207
enum E {
208208
v;
209209
set /*[0*/foo/*0]*/(int _) {}
@@ -227,6 +227,35 @@ extension /*[1*/E/*1]*/<ThisType> on ThisType {
227227
''');
228228
}
229229

230+
Future<void> test_extensionMember() async {
231+
await assertOccurrences(kind: ElementKind.GETTER, '''
232+
extension on int {
233+
int get /*[0*/foo/*0]*/ => 0;
234+
}
235+
236+
void f(int v) {
237+
v./*[1*/foo/*1]*/;
238+
}
239+
''');
240+
}
241+
242+
Future<void> test_extensionMember_diferenciation() async {
243+
await assertOccurrences(kind: ElementKind.GETTER, '''
244+
extension on String {
245+
int get foo => 0;
246+
}
247+
248+
extension on int {
249+
int get /*[0*/foo/*0]*/ => 0;
250+
}
251+
252+
void f(int v, String s) {
253+
v./*[1*/foo/*1]*/;
254+
s.foo;
255+
}
256+
''');
257+
}
258+
230259
Future<void> test_extensionType() async {
231260
await assertOccurrences(kind: ElementKind.EXTENSION_TYPE, '''
232261
extension type /*[0*/E/*0]*/(int it) {}
@@ -266,7 +295,7 @@ void f() {
266295
}
267296

268297
Future<void> test_extensionType_getter() async {
269-
await assertOccurrences(kind: ElementKind.FIELD, '''
298+
await assertOccurrences(kind: ElementKind.GETTER, '''
270299
extension type E(int it) {
271300
int get /*[0*/foo/*0]*/ => 0;
272301
}
@@ -290,7 +319,7 @@ void f(E e) {
290319
}
291320

292321
Future<void> test_extensionType_setter() async {
293-
await assertOccurrences(kind: ElementKind.FIELD, '''
322+
await assertOccurrences(kind: ElementKind.SETTER, '''
294323
extension type E(int it) {
295324
set /*[0*/foo/*0]*/(int _) {}
296325
}
@@ -524,7 +553,7 @@ void f() {
524553
}
525554

526555
Future<void> test_pattern_object_fieldName() async {
527-
await assertOccurrences(kind: ElementKind.FIELD, '''
556+
await assertOccurrences(kind: ElementKind.GETTER, '''
528557
double calculateArea(Shape shape) =>
529558
switch (shape) {
530559
Square(/*[0*/length/*0]*/: var l) => l * l,

0 commit comments

Comments
 (0)