Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: pkg/analysis_server/test/search/element_references_test.dart

Issue 2518183003: Stop returning declaration matches from search for references. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/search/element_references.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.search.element_references; 5 library test.search.element_references;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/services/index/index.dart'; 10 import 'package:analysis_server/src/services/index/index.dart';
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 main(A a) { 147 main(A a) {
148 a.fff = 20; 148 a.fff = 20;
149 a.fff += 30; 149 a.fff += 30;
150 print(a.fff); // in main() 150 print(a.fff); // in main()
151 a.fff(); // in main() 151 a.fff(); // in main()
152 } 152 }
153 '''); 153 ''');
154 await findElementReferences('fff; // declaration', false); 154 await findElementReferences('fff; // declaration', false);
155 expect(searchElement.kind, ElementKind.FIELD); 155 expect(searchElement.kind, ElementKind.FIELD);
156 expect(results, hasLength(11)); 156 expect(results, hasLength(10));
157 assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration');
158 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor'); 157 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
159 assertHasResult(SearchResultKind.WRITE, 'fff = 1;'); 158 assertHasResult(SearchResultKind.WRITE, 'fff = 1;');
160 // m() 159 // m()
161 assertHasResult(SearchResultKind.WRITE, 'fff = 2;'); 160 assertHasResult(SearchResultKind.WRITE, 'fff = 2;');
162 assertHasResult(SearchResultKind.WRITE, 'fff += 3;'); 161 assertHasResult(SearchResultKind.WRITE, 'fff += 3;');
163 assertHasResult(SearchResultKind.READ, 'fff); // in m()'); 162 assertHasResult(SearchResultKind.READ, 'fff); // in m()');
164 assertHasResult(SearchResultKind.INVOCATION, 'fff(); // in m()'); 163 assertHasResult(SearchResultKind.INVOCATION, 'fff(); // in m()');
165 // main() 164 // main()
166 assertHasResult(SearchResultKind.WRITE, 'fff = 20;'); 165 assertHasResult(SearchResultKind.WRITE, 'fff = 20;');
167 assertHasResult(SearchResultKind.WRITE, 'fff += 30;'); 166 assertHasResult(SearchResultKind.WRITE, 'fff += 30;');
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 var fff; // declaration 208 var fff; // declaration
210 A(this.fff); // in constructor 209 A(this.fff); // in constructor
211 m() { 210 m() {
212 fff = 2; 211 fff = 2;
213 print(fff); // in m() 212 print(fff); // in m()
214 } 213 }
215 } 214 }
216 '''); 215 ''');
217 await findElementReferences('fff); // in constructor', false); 216 await findElementReferences('fff); // in constructor', false);
218 expect(searchElement.kind, ElementKind.FIELD); 217 expect(searchElement.kind, ElementKind.FIELD);
219 expect(results, hasLength(4)); 218 expect(results, hasLength(3));
220 assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration');
221 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor'); 219 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor');
222 assertHasResult(SearchResultKind.WRITE, 'fff = 2;'); 220 assertHasResult(SearchResultKind.WRITE, 'fff = 2;');
223 assertHasResult(SearchResultKind.READ, 'fff); // in m()'); 221 assertHasResult(SearchResultKind.READ, 'fff); // in m()');
224 } 222 }
225 223
226 test_function() async { 224 test_function() async {
227 addTestFile(''' 225 addTestFile('''
228 fff(p) {} 226 fff(p) {}
229 main() { 227 main() {
230 fff(1); 228 fff(1);
(...skipping 19 matching lines...) Expand all
250 int fff; // in C 248 int fff; // in C
251 } 249 }
252 main(A a, B b, C c) { 250 main(A a, B b, C c) {
253 a.fff = 10; 251 a.fff = 10;
254 b.fff = 20; 252 b.fff = 20;
255 c.fff = 30; 253 c.fff = 30;
256 } 254 }
257 '''); 255 ''');
258 await findElementReferences('fff; // in B', false); 256 await findElementReferences('fff; // in B', false);
259 expect(searchElement.kind, ElementKind.FIELD); 257 expect(searchElement.kind, ElementKind.FIELD);
260 assertHasResult(SearchResultKind.DECLARATION, 'fff; // in A');
261 assertHasResult(SearchResultKind.DECLARATION, 'fff; // in B');
262 assertHasResult(SearchResultKind.DECLARATION, 'fff; // in C');
263 assertHasResult(SearchResultKind.WRITE, 'fff = 10;'); 258 assertHasResult(SearchResultKind.WRITE, 'fff = 10;');
264 assertHasResult(SearchResultKind.WRITE, 'fff = 20;'); 259 assertHasResult(SearchResultKind.WRITE, 'fff = 20;');
265 assertHasResult(SearchResultKind.WRITE, 'fff = 30;'); 260 assertHasResult(SearchResultKind.WRITE, 'fff = 30;');
266 } 261 }
267 262
268 test_hierarchy_method() async { 263 test_hierarchy_method() async {
269 addTestFile(''' 264 addTestFile('''
270 class A { 265 class A {
271 mmm(_) {} // in A 266 mmm(_) {} // in A
272 } 267 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 for (int i = 0; i < 10; i++) { 314 for (int i = 0; i < 10; i++) {
320 if (i == 2) { 315 if (i == 2) {
321 continue myLabel; // continue 316 continue myLabel; // continue
322 } 317 }
323 break myLabel; // break 318 break myLabel; // break
324 } 319 }
325 } 320 }
326 '''); 321 ''');
327 await findElementReferences('myLabel; // break', false); 322 await findElementReferences('myLabel; // break', false);
328 expect(searchElement.kind, ElementKind.LABEL); 323 expect(searchElement.kind, ElementKind.LABEL);
329 expect(results, hasLength(3)); 324 expect(results, hasLength(2));
330 assertHasResult(SearchResultKind.DECLARATION, 'myLabel:');
331 assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // continue'); 325 assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // continue');
332 assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // break'); 326 assertHasResult(SearchResultKind.REFERENCE, 'myLabel; // break');
333 } 327 }
334 328
335 test_localVariable() async { 329 test_localVariable() async {
336 addTestFile(''' 330 addTestFile('''
337 main() { 331 main() {
338 var vvv = 1; 332 var vvv = 1;
339 print(vvv); 333 print(vvv);
340 vvv += 3; 334 vvv += 3;
341 vvv = 2; 335 vvv = 2;
342 vvv(); 336 vvv();
343 } 337 }
344 '''); 338 ''');
345 await findElementReferences('vvv = 1', false); 339 await findElementReferences('vvv = 1', false);
346 expect(searchElement.kind, ElementKind.LOCAL_VARIABLE); 340 expect(searchElement.kind, ElementKind.LOCAL_VARIABLE);
347 expect(results, hasLength(5)); 341 expect(results, hasLength(4));
348 assertHasResult(SearchResultKind.DECLARATION, 'vvv = 1');
349 assertHasResult(SearchResultKind.READ, 'vvv);'); 342 assertHasResult(SearchResultKind.READ, 'vvv);');
350 assertHasResult(SearchResultKind.READ_WRITE, 'vvv += 3'); 343 assertHasResult(SearchResultKind.READ_WRITE, 'vvv += 3');
351 assertHasResult(SearchResultKind.WRITE, 'vvv = 2'); 344 assertHasResult(SearchResultKind.WRITE, 'vvv = 2');
352 assertHasResult(SearchResultKind.INVOCATION, 'vvv();'); 345 assertHasResult(SearchResultKind.INVOCATION, 'vvv();');
353 } 346 }
354 347
355 test_method() async { 348 test_method() async {
356 addTestFile(''' 349 addTestFile('''
357 class A { 350 class A {
358 mmm(p) {} 351 mmm(p) {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 addTestFile(''' 412 addTestFile('''
420 main(ppp) { 413 main(ppp) {
421 print(ppp); 414 print(ppp);
422 ppp += 3; 415 ppp += 3;
423 ppp = 2; 416 ppp = 2;
424 ppp(); 417 ppp();
425 } 418 }
426 '''); 419 ''');
427 await findElementReferences('ppp) {', false); 420 await findElementReferences('ppp) {', false);
428 expect(searchElement.kind, ElementKind.PARAMETER); 421 expect(searchElement.kind, ElementKind.PARAMETER);
429 expect(results, hasLength(5)); 422 expect(results, hasLength(4));
430 assertHasResult(SearchResultKind.DECLARATION, 'ppp) {');
431 assertHasResult(SearchResultKind.READ, 'ppp);'); 423 assertHasResult(SearchResultKind.READ, 'ppp);');
432 assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3'); 424 assertHasResult(SearchResultKind.READ_WRITE, 'ppp += 3');
433 assertHasResult(SearchResultKind.WRITE, 'ppp = 2'); 425 assertHasResult(SearchResultKind.WRITE, 'ppp = 2');
434 assertHasResult(SearchResultKind.INVOCATION, 'ppp();'); 426 assertHasResult(SearchResultKind.INVOCATION, 'ppp();');
435 } 427 }
436 428
437 test_path_inConstructor_named() async { 429 test_path_inConstructor_named() async {
438 addTestFile(''' 430 addTestFile('''
439 library my_lib; 431 library my_lib;
440 class A {} 432 class A {}
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 import 'dart:async' as ppp; 579 import 'dart:async' as ppp;
588 main() { 580 main() {
589 ppp.Future a; 581 ppp.Future a;
590 ppp.Stream b; 582 ppp.Stream b;
591 } 583 }
592 '''); 584 ''');
593 await findElementReferences("ppp;", false); 585 await findElementReferences("ppp;", false);
594 expect(searchElement.kind, ElementKind.PREFIX); 586 expect(searchElement.kind, ElementKind.PREFIX);
595 expect(searchElement.name, 'ppp'); 587 expect(searchElement.name, 'ppp');
596 expect(searchElement.location.startLine, 1); 588 expect(searchElement.location.startLine, 1);
597 expect(results, hasLength(3)); 589 expect(results, hasLength(2));
598 assertHasResult(SearchResultKind.DECLARATION, 'ppp;');
599 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future'); 590 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future');
600 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream'); 591 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream');
601 } 592 }
602 593
603 test_topLevelVariable_explicit() async { 594 test_topLevelVariable_explicit() async {
604 addTestFile(''' 595 addTestFile('''
605 var vvv = 1; 596 var vvv = 1;
606 main() { 597 main() {
607 print(vvv); 598 print(vvv);
608 vvv += 3; 599 vvv += 3;
609 vvv = 2; 600 vvv = 2;
610 vvv(); 601 vvv();
611 } 602 }
612 '''); 603 ''');
613 await findElementReferences('vvv = 1', false); 604 await findElementReferences('vvv = 1', false);
614 expect(searchElement.kind, ElementKind.TOP_LEVEL_VARIABLE); 605 expect(searchElement.kind, ElementKind.TOP_LEVEL_VARIABLE);
615 expect(results, hasLength(5)); 606 expect(results, hasLength(4));
616 assertHasResult(SearchResultKind.DECLARATION, 'vvv = 1;');
617 assertHasResult(SearchResultKind.READ, 'vvv);'); 607 assertHasResult(SearchResultKind.READ, 'vvv);');
618 assertHasResult(SearchResultKind.WRITE, 'vvv += 3'); 608 assertHasResult(SearchResultKind.WRITE, 'vvv += 3');
619 assertHasResult(SearchResultKind.WRITE, 'vvv = 2'); 609 assertHasResult(SearchResultKind.WRITE, 'vvv = 2');
620 assertHasResult(SearchResultKind.INVOCATION, 'vvv();'); 610 assertHasResult(SearchResultKind.INVOCATION, 'vvv();');
621 } 611 }
622 612
623 test_topLevelVariable_implicit() async { 613 test_topLevelVariable_implicit() async {
624 addTestFile(''' 614 addTestFile('''
625 get vvv => null; 615 get vvv => null;
626 set vvv(x) {} 616 set vvv(x) {}
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 print(vvv); 688 print(vvv);
699 } 689 }
700 '''); 690 ''');
701 Request request = new SearchFindElementReferencesParams(testFile, 0, false) 691 Request request = new SearchFindElementReferencesParams(testFile, 0, false)
702 .toRequest('0'); 692 .toRequest('0');
703 Response response = await waitResponse(request); 693 Response response = await waitResponse(request);
704 expect(response.error, isNotNull); 694 expect(response.error, isNotNull);
705 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); 695 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED);
706 } 696 }
707 } 697 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/element_references.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698