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

Side by Side Diff: pkg/analyzer_plugin/test/utilities/completion/inherited_reference_contributor_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 years, 5 months 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 5 import 'package:analyzer_plugin/protocol/protocol_common.dart';
6 import 'package:analyzer_plugin/utilities/completion/completion_core.dart'; 6 import 'package:analyzer_plugin/utilities/completion/completion_core.dart';
7 import 'package:analyzer_plugin/utilities/completion/inherited_reference_contrib utor.dart'; 7 import 'package:analyzer_plugin/utilities/completion/inherited_reference_contrib utor.dart';
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; 9 import 'package:test_reflective_loader/test_reflective_loader.dart';
10 10
(...skipping 11 matching lines...) Expand all
22 bool get isNullExpectedReturnTypeConsideredDynamic => false; 22 bool get isNullExpectedReturnTypeConsideredDynamic => false;
23 23
24 @override 24 @override
25 CompletionContributor createContributor() { 25 CompletionContributor createContributor() {
26 return new InheritedReferenceContributor(); 26 return new InheritedReferenceContributor();
27 } 27 }
28 28
29 /// Sanity check. Permutations tested in local_ref_contributor. 29 /// Sanity check. Permutations tested in local_ref_contributor.
30 test_ArgDefaults_inherited_method_with_required_named() async { 30 test_ArgDefaults_inherited_method_with_required_named() async {
31 addMetaPackageSource(); 31 addMetaPackageSource();
32 resolveSource( 32 resolveSource('/testB.dart', '''
33 '/testB.dart',
34 '''
35 import 'package:meta/meta.dart'; 33 import 'package:meta/meta.dart';
36 34
37 lib libB; 35 lib libB;
38 class A { 36 class A {
39 bool foo(int bar, {bool boo, @required int baz}) => false; 37 bool foo(int bar, {bool boo, @required int baz}) => false;
40 }'''); 38 }''');
41 addTestSource(''' 39 addTestSource('''
42 import "testB.dart"; 40 import "testB.dart";
43 class B extends A { 41 class B extends A {
44 b() => f^ 42 b() => f^
45 } 43 }
46 '''); 44 ''');
47 await computeSuggestions(); 45 await computeSuggestions();
48 46
49 assertSuggestMethod('foo', 'A', 'bool', 47 assertSuggestMethod('foo', 'A', 'bool',
50 defaultArgListString: 'bar, baz: null'); 48 defaultArgListString: 'bar, baz: null');
51 } 49 }
52 50
53 test_AwaitExpression_inherited() async { 51 test_AwaitExpression_inherited() async {
54 // SimpleIdentifier AwaitExpression ExpressionStatement 52 // SimpleIdentifier AwaitExpression ExpressionStatement
55 resolveSource( 53 resolveSource('/testB.dart', '''
56 '/testB.dart',
57 '''
58 lib libB; 54 lib libB;
59 class A { 55 class A {
60 Future y() async {return 0;} 56 Future y() async {return 0;}
61 }'''); 57 }''');
62 addTestSource(''' 58 addTestSource('''
63 import "testB.dart"; 59 import "testB.dart";
64 class B extends A { 60 class B extends A {
65 Future a() async {return 0;} 61 Future a() async {return 0;}
66 foo() async {await ^} 62 foo() async {await ^}
67 } 63 }
68 '''); 64 ''');
69 65
70 await computeSuggestions(); 66 await computeSuggestions();
71 expect(replacementOffset, completionOffset); 67 expect(replacementOffset, completionOffset);
72 expect(replacementLength, 0); 68 expect(replacementLength, 0);
73 assertNotSuggested('a'); 69 assertNotSuggested('a');
74 assertNotSuggested('foo'); 70 assertNotSuggested('foo');
75 assertNotSuggested('B'); 71 assertNotSuggested('B');
76 assertNotSuggested('A'); 72 assertNotSuggested('A');
77 assertNotSuggested('Object'); 73 assertNotSuggested('Object');
78 assertSuggestMethod('y', 'A', 'dynamic'); 74 assertSuggestMethod('y', 'A', 'dynamic');
79 } 75 }
80 76
81 test_Block_inherited_imported() async { 77 test_Block_inherited_imported() async {
82 // Block BlockFunctionBody MethodDeclaration ClassDeclaration 78 // Block BlockFunctionBody MethodDeclaration ClassDeclaration
83 resolveSource( 79 resolveSource('/testB.dart', '''
84 '/testB.dart',
85 '''
86 lib B; 80 lib B;
87 class F { var f1; f2() { } get f3 => 0; set f4(fx) { } var _pf; } 81 class F { var f1; f2() { } get f3 => 0; set f4(fx) { } var _pf; }
88 class E extends F { var e1; e2() { } } 82 class E extends F { var e1; e2() { } }
89 class I { int i1; i2() { } } 83 class I { int i1; i2() { } }
90 class M { var m1; int m2() { } }'''); 84 class M { var m1; int m2() { } }''');
91 addTestSource(''' 85 addTestSource('''
92 import "testB.dart"; 86 import "testB.dart";
93 class A extends E implements I with M {a() {^}}'''); 87 class A extends E implements I with M {a() {^}}''');
94 await computeSuggestions(); 88 await computeSuggestions();
95 expect(replacementOffset, completionOffset); 89 expect(replacementOffset, completionOffset);
(...skipping 29 matching lines...) Expand all
125 assertSuggestField('m1', null); 119 assertSuggestField('m1', null);
126 assertSuggestGetter('f3', null); 120 assertSuggestGetter('f3', null);
127 assertSuggestSetter('f4'); 121 assertSuggestSetter('f4');
128 assertSuggestMethod('e2', 'E', null); 122 assertSuggestMethod('e2', 'E', null);
129 assertSuggestMethod('f2', 'F', null); 123 assertSuggestMethod('f2', 'F', null);
130 assertSuggestMethod('i2', 'I', null); 124 assertSuggestMethod('i2', 'I', null);
131 assertSuggestMethod('m2', 'M', 'int'); 125 assertSuggestMethod('m2', 'M', 'int');
132 } 126 }
133 127
134 test_inherited() async { 128 test_inherited() async {
135 resolveSource( 129 resolveSource('/testB.dart', '''
136 '/testB.dart',
137 '''
138 lib libB; 130 lib libB;
139 class A2 { 131 class A2 {
140 int x; 132 int x;
141 int y() {return 0;} 133 int y() {return 0;}
142 int x2; 134 int x2;
143 int y2() {return 0;} 135 int y2() {return 0;}
144 }'''); 136 }''');
145 addTestSource(''' 137 addTestSource('''
146 import "testB.dart"; 138 import "testB.dart";
147 class A1 { 139 class A1 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 class A { 171 class A {
180 void m(x, int y) {} 172 void m(x, int y) {}
181 main() {^} 173 main() {^}
182 } 174 }
183 '''); 175 ''');
184 await computeSuggestions(); 176 await computeSuggestions();
185 assertNotSuggested('m'); 177 assertNotSuggested('m');
186 } 178 }
187 179
188 test_method_parameters_mixed_required_and_named() async { 180 test_method_parameters_mixed_required_and_named() async {
189 resolveSource( 181 resolveSource('/libA.dart', '''
190 '/libA.dart',
191 '''
192 class A { 182 class A {
193 void m(x, {int y}) {} 183 void m(x, {int y}) {}
194 } 184 }
195 '''); 185 ''');
196 addTestSource(''' 186 addTestSource('''
197 import 'libA.dart'; 187 import 'libA.dart';
198 class B extends A { 188 class B extends A {
199 main() {^} 189 main() {^}
200 } 190 }
201 '''); 191 ''');
(...skipping 22 matching lines...) Expand all
224 expect(suggestion.parameterNames, hasLength(2)); 214 expect(suggestion.parameterNames, hasLength(2));
225 expect(suggestion.parameterNames[0], 'x'); 215 expect(suggestion.parameterNames[0], 'x');
226 expect(suggestion.parameterTypes[0], 'dynamic'); 216 expect(suggestion.parameterTypes[0], 'dynamic');
227 expect(suggestion.parameterNames[1], 'y'); 217 expect(suggestion.parameterNames[1], 'y');
228 expect(suggestion.parameterTypes[1], 'int'); 218 expect(suggestion.parameterTypes[1], 'int');
229 expect(suggestion.requiredParameterCount, 1); 219 expect(suggestion.requiredParameterCount, 1);
230 expect(suggestion.hasNamedParameters, true); 220 expect(suggestion.hasNamedParameters, true);
231 } 221 }
232 222
233 test_method_parameters_mixed_required_and_positional() async { 223 test_method_parameters_mixed_required_and_positional() async {
234 resolveSource( 224 resolveSource('/libA.dart', '''
235 '/libA.dart',
236 '''
237 class A { 225 class A {
238 void m(x, [int y]) {} 226 void m(x, [int y]) {}
239 } 227 }
240 '''); 228 ''');
241 addTestSource(''' 229 addTestSource('''
242 import 'libA.dart'; 230 import 'libA.dart';
243 class B extends A { 231 class B extends A {
244 main() {^} 232 main() {^}
245 } 233 }
246 '''); 234 ''');
(...skipping 22 matching lines...) Expand all
269 expect(suggestion.parameterNames, hasLength(2)); 257 expect(suggestion.parameterNames, hasLength(2));
270 expect(suggestion.parameterNames[0], 'x'); 258 expect(suggestion.parameterNames[0], 'x');
271 expect(suggestion.parameterTypes[0], 'dynamic'); 259 expect(suggestion.parameterTypes[0], 'dynamic');
272 expect(suggestion.parameterNames[1], 'y'); 260 expect(suggestion.parameterNames[1], 'y');
273 expect(suggestion.parameterTypes[1], 'int'); 261 expect(suggestion.parameterTypes[1], 'int');
274 expect(suggestion.requiredParameterCount, 1); 262 expect(suggestion.requiredParameterCount, 1);
275 expect(suggestion.hasNamedParameters, false); 263 expect(suggestion.hasNamedParameters, false);
276 } 264 }
277 265
278 test_method_parameters_named() async { 266 test_method_parameters_named() async {
279 resolveSource( 267 resolveSource('/libA.dart', '''
280 '/libA.dart',
281 '''
282 class A { 268 class A {
283 void m({x, int y}) {} 269 void m({x, int y}) {}
284 } 270 }
285 '''); 271 ''');
286 addTestSource(''' 272 addTestSource('''
287 import 'libA.dart'; 273 import 'libA.dart';
288 class B extends A { 274 class B extends A {
289 main() {^} 275 main() {^}
290 } 276 }
291 '''); 277 ''');
(...skipping 22 matching lines...) Expand all
314 expect(suggestion.parameterNames, hasLength(2)); 300 expect(suggestion.parameterNames, hasLength(2));
315 expect(suggestion.parameterNames[0], 'x'); 301 expect(suggestion.parameterNames[0], 'x');
316 expect(suggestion.parameterTypes[0], 'dynamic'); 302 expect(suggestion.parameterTypes[0], 'dynamic');
317 expect(suggestion.parameterNames[1], 'y'); 303 expect(suggestion.parameterNames[1], 'y');
318 expect(suggestion.parameterTypes[1], 'int'); 304 expect(suggestion.parameterTypes[1], 'int');
319 expect(suggestion.requiredParameterCount, 0); 305 expect(suggestion.requiredParameterCount, 0);
320 expect(suggestion.hasNamedParameters, true); 306 expect(suggestion.hasNamedParameters, true);
321 } 307 }
322 308
323 test_method_parameters_none() async { 309 test_method_parameters_none() async {
324 resolveSource( 310 resolveSource('/libA.dart', '''
325 '/libA.dart',
326 '''
327 class A { 311 class A {
328 void m() {} 312 void m() {}
329 } 313 }
330 '''); 314 ''');
331 addTestSource(''' 315 addTestSource('''
332 import 'libA.dart'; 316 import 'libA.dart';
333 class B extends A { 317 class B extends A {
334 main() {^} 318 main() {^}
335 } 319 }
336 '''); 320 ''');
(...skipping 16 matching lines...) Expand all
353 '''); 337 ''');
354 await computeSuggestions(); 338 await computeSuggestions();
355 CompletionSuggestion suggestion = assertSuggestMethod('m', 'A', 'void'); 339 CompletionSuggestion suggestion = assertSuggestMethod('m', 'A', 'void');
356 expect(suggestion.parameterNames, isEmpty); 340 expect(suggestion.parameterNames, isEmpty);
357 expect(suggestion.parameterTypes, isEmpty); 341 expect(suggestion.parameterTypes, isEmpty);
358 expect(suggestion.requiredParameterCount, 0); 342 expect(suggestion.requiredParameterCount, 0);
359 expect(suggestion.hasNamedParameters, false); 343 expect(suggestion.hasNamedParameters, false);
360 } 344 }
361 345
362 test_method_parameters_positional() async { 346 test_method_parameters_positional() async {
363 resolveSource( 347 resolveSource('/libA.dart', '''
364 '/libA.dart',
365 '''
366 class A { 348 class A {
367 void m([x, int y]) {} 349 void m([x, int y]) {}
368 } 350 }
369 '''); 351 ''');
370 addTestSource(''' 352 addTestSource('''
371 import 'libA.dart'; 353 import 'libA.dart';
372 class B extends A { 354 class B extends A {
373 main() {^} 355 main() {^}
374 } 356 }
375 '''); 357 ''');
(...skipping 22 matching lines...) Expand all
398 expect(suggestion.parameterNames, hasLength(2)); 380 expect(suggestion.parameterNames, hasLength(2));
399 expect(suggestion.parameterNames[0], 'x'); 381 expect(suggestion.parameterNames[0], 'x');
400 expect(suggestion.parameterTypes[0], 'dynamic'); 382 expect(suggestion.parameterTypes[0], 'dynamic');
401 expect(suggestion.parameterNames[1], 'y'); 383 expect(suggestion.parameterNames[1], 'y');
402 expect(suggestion.parameterTypes[1], 'int'); 384 expect(suggestion.parameterTypes[1], 'int');
403 expect(suggestion.requiredParameterCount, 0); 385 expect(suggestion.requiredParameterCount, 0);
404 expect(suggestion.hasNamedParameters, false); 386 expect(suggestion.hasNamedParameters, false);
405 } 387 }
406 388
407 test_method_parameters_required() async { 389 test_method_parameters_required() async {
408 resolveSource( 390 resolveSource('/libA.dart', '''
409 '/libA.dart',
410 '''
411 class A { 391 class A {
412 void m(x, int y) {} 392 void m(x, int y) {}
413 } 393 }
414 '''); 394 ''');
415 addTestSource(''' 395 addTestSource('''
416 import 'libA.dart'; 396 import 'libA.dart';
417 class B extends A { 397 class B extends A {
418 main() {^} 398 main() {^}
419 } 399 }
420 '''); 400 ''');
421 await computeSuggestions(); 401 await computeSuggestions();
422 CompletionSuggestion suggestion = assertSuggestMethod('m', 'A', 'void'); 402 CompletionSuggestion suggestion = assertSuggestMethod('m', 'A', 'void');
423 expect(suggestion.parameterNames, hasLength(2)); 403 expect(suggestion.parameterNames, hasLength(2));
424 expect(suggestion.parameterNames[0], 'x'); 404 expect(suggestion.parameterNames[0], 'x');
425 expect(suggestion.parameterTypes[0], 'dynamic'); 405 expect(suggestion.parameterTypes[0], 'dynamic');
426 expect(suggestion.parameterNames[1], 'y'); 406 expect(suggestion.parameterNames[1], 'y');
427 expect(suggestion.parameterTypes[1], 'int'); 407 expect(suggestion.parameterTypes[1], 'int');
428 expect(suggestion.requiredParameterCount, 2); 408 expect(suggestion.requiredParameterCount, 2);
429 expect(suggestion.hasNamedParameters, false); 409 expect(suggestion.hasNamedParameters, false);
430 } 410 }
431 411
432 test_mixin_ordering() async { 412 test_mixin_ordering() async {
433 resolveSource( 413 resolveSource('/libA.dart', '''
434 '/libA.dart',
435 '''
436 class B {} 414 class B {}
437 class M1 { 415 class M1 {
438 void m() {} 416 void m() {}
439 } 417 }
440 class M2 { 418 class M2 {
441 void m() {} 419 void m() {}
442 } 420 }
443 '''); 421 ''');
444 addTestSource(''' 422 addTestSource('''
445 import 'libA.dart'; 423 import 'libA.dart';
446 class C extends B with M1, M2 { 424 class C extends B with M1, M2 {
447 void f() { 425 void f() {
448 ^ 426 ^
449 } 427 }
450 } 428 }
451 '''); 429 ''');
452 await computeSuggestions(); 430 await computeSuggestions();
453 assertSuggestMethod('m', 'M1', 'void'); 431 assertSuggestMethod('m', 'M1', 'void');
454 } 432 }
455 433
456 test_no_parameters_field() async { 434 test_no_parameters_field() async {
457 resolveSource( 435 resolveSource('/libA.dart', '''
458 '/libA.dart',
459 '''
460 class A { 436 class A {
461 int x; 437 int x;
462 } 438 }
463 '''); 439 ''');
464 addTestSource(''' 440 addTestSource('''
465 import 'libA.dart'; 441 import 'libA.dart';
466 class B extends A { 442 class B extends A {
467 main() {^} 443 main() {^}
468 } 444 }
469 '''); 445 ''');
470 await computeSuggestions(); 446 await computeSuggestions();
471 CompletionSuggestion suggestion = assertSuggestField('x', 'int'); 447 CompletionSuggestion suggestion = assertSuggestField('x', 'int');
472 assertHasNoParameterInfo(suggestion); 448 assertHasNoParameterInfo(suggestion);
473 } 449 }
474 450
475 test_no_parameters_getter() async { 451 test_no_parameters_getter() async {
476 resolveSource( 452 resolveSource('/libA.dart', '''
477 '/libA.dart',
478 '''
479 class A { 453 class A {
480 int get x => null; 454 int get x => null;
481 } 455 }
482 '''); 456 ''');
483 addTestSource(''' 457 addTestSource('''
484 import 'libA.dart'; 458 import 'libA.dart';
485 class B extends A { 459 class B extends A {
486 main() {^} 460 main() {^}
487 } 461 }
488 '''); 462 ''');
489 await computeSuggestions(); 463 await computeSuggestions();
490 CompletionSuggestion suggestion = assertSuggestGetter('x', 'int'); 464 CompletionSuggestion suggestion = assertSuggestGetter('x', 'int');
491 assertHasNoParameterInfo(suggestion); 465 assertHasNoParameterInfo(suggestion);
492 } 466 }
493 467
494 test_no_parameters_setter() async { 468 test_no_parameters_setter() async {
495 resolveSource( 469 resolveSource('/libA.dart', '''
496 '/libA.dart',
497 '''
498 class A { 470 class A {
499 set x(int value) {}; 471 set x(int value) {};
500 } 472 }
501 '''); 473 ''');
502 addTestSource(''' 474 addTestSource('''
503 import 'libA.dart'; 475 import 'libA.dart';
504 class B extends A { 476 class B extends A {
505 main() {^} 477 main() {^}
506 } 478 }
507 '''); 479 ''');
508 await computeSuggestions(); 480 await computeSuggestions();
509 CompletionSuggestion suggestion = assertSuggestSetter('x'); 481 CompletionSuggestion suggestion = assertSuggestSetter('x');
510 assertHasNoParameterInfo(suggestion); 482 assertHasNoParameterInfo(suggestion);
511 } 483 }
512 484
513 test_outside_class() async { 485 test_outside_class() async {
514 resolveSource( 486 resolveSource('/testB.dart', '''
515 '/testB.dart',
516 '''
517 lib libB; 487 lib libB;
518 class A2 { 488 class A2 {
519 int x; 489 int x;
520 int y() {return 0;} 490 int y() {return 0;}
521 int x2; 491 int x2;
522 int y2() {return 0;} 492 int y2() {return 0;}
523 }'''); 493 }''');
524 addTestSource(''' 494 addTestSource('''
525 import "testB.dart"; 495 import "testB.dart";
526 class A1 { 496 class A1 {
(...skipping 20 matching lines...) Expand all
547 assertNotSuggested('A'); 517 assertNotSuggested('A');
548 assertNotSuggested('x'); 518 assertNotSuggested('x');
549 assertNotSuggested('y'); 519 assertNotSuggested('y');
550 assertNotSuggested('x1'); 520 assertNotSuggested('x1');
551 assertNotSuggested('y1'); 521 assertNotSuggested('y1');
552 assertNotSuggested('x2'); 522 assertNotSuggested('x2');
553 assertNotSuggested('y2'); 523 assertNotSuggested('y2');
554 } 524 }
555 525
556 test_static_field() async { 526 test_static_field() async {
557 resolveSource( 527 resolveSource('/testB.dart', '''
558 '/testB.dart',
559 '''
560 lib libB; 528 lib libB;
561 class A2 { 529 class A2 {
562 int x; 530 int x;
563 int y() {return 0;} 531 int y() {return 0;}
564 int x2; 532 int x2;
565 int y2() {return 0;} 533 int y2() {return 0;}
566 }'''); 534 }''');
567 addTestSource(''' 535 addTestSource('''
568 import "testB.dart"; 536 import "testB.dart";
569 class A1 { 537 class A1 {
(...skipping 20 matching lines...) Expand all
590 assertNotSuggested('A'); 558 assertNotSuggested('A');
591 assertNotSuggested('x'); 559 assertNotSuggested('x');
592 assertNotSuggested('y'); 560 assertNotSuggested('y');
593 assertNotSuggested('x1'); 561 assertNotSuggested('x1');
594 assertNotSuggested('y1'); 562 assertNotSuggested('y1');
595 assertNotSuggested('x2'); 563 assertNotSuggested('x2');
596 assertNotSuggested('y2'); 564 assertNotSuggested('y2');
597 } 565 }
598 566
599 test_static_method() async { 567 test_static_method() async {
600 resolveSource( 568 resolveSource('/testB.dart', '''
601 '/testB.dart',
602 '''
603 lib libB; 569 lib libB;
604 class A2 { 570 class A2 {
605 int x; 571 int x;
606 int y() {return 0;} 572 int y() {return 0;}
607 int x2; 573 int x2;
608 int y2() {return 0;} 574 int y2() {return 0;}
609 }'''); 575 }''');
610 addTestSource(''' 576 addTestSource('''
611 import "testB.dart"; 577 import "testB.dart";
612 class A1 { 578 class A1 {
(...skipping 19 matching lines...) Expand all
632 assertNotSuggested('foo'); 598 assertNotSuggested('foo');
633 assertNotSuggested('A'); 599 assertNotSuggested('A');
634 assertNotSuggested('x'); 600 assertNotSuggested('x');
635 assertNotSuggested('y'); 601 assertNotSuggested('y');
636 assertNotSuggested('x1'); 602 assertNotSuggested('x1');
637 assertNotSuggested('y1'); 603 assertNotSuggested('y1');
638 assertNotSuggested('x2'); 604 assertNotSuggested('x2');
639 assertNotSuggested('y2'); 605 assertNotSuggested('y2');
640 } 606 }
641 } 607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698