| OLD | NEW |
| 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.services.correction.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 ''' | 470 ''' |
| 471 import 'package:meta/meta.dart'; | 471 import 'package:meta/meta.dart'; |
| 472 | 472 |
| 473 test({@required int a, @required int bcd}) {} | 473 test({@required int a, @required int bcd}) {} |
| 474 main() { | 474 main() { |
| 475 test(a: 3, bcd: null); | 475 test(a: 3, bcd: null); |
| 476 } | 476 } |
| 477 '''); | 477 '''); |
| 478 } | 478 } |
| 479 | 479 |
| 480 test_addMissingRequiredArg_multiple_2() async { |
| 481 _addMetaPackageSource(); |
| 482 |
| 483 await resolveTestUnit(''' |
| 484 import 'package:meta/meta.dart'; |
| 485 |
| 486 test({@required int a, @required int bcd}) {} |
| 487 main() { |
| 488 test(); |
| 489 } |
| 490 '''); |
| 491 |
| 492 // For now we expect one error per missing arg (dartbug.com/28830). |
| 493 List<AnalysisError> errors = await _computeErrors(); |
| 494 expect(errors, hasLength(2)); |
| 495 |
| 496 List<AnalysisError> filteredErrors = errors |
| 497 .where((e) => e.message == "The parameter 'a' is required.") |
| 498 .toList(); |
| 499 expect(filteredErrors, hasLength(1)); |
| 500 |
| 501 List<Fix> fixes = await _computeFixes(filteredErrors.first); |
| 502 |
| 503 List<Fix> filteredFixes = fixes |
| 504 .where((fix) => fix.change.message == "Add required argument 'a'") |
| 505 .toList(); |
| 506 expect(filteredFixes, hasLength(1)); |
| 507 change = filteredFixes.first.change; |
| 508 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 509 // verify |
| 510 expect( |
| 511 resultCode, |
| 512 ''' |
| 513 import 'package:meta/meta.dart'; |
| 514 |
| 515 test({@required int a, @required int bcd}) {} |
| 516 main() { |
| 517 test(a: null); |
| 518 } |
| 519 '''); |
| 520 } |
| 521 |
| 480 test_addMissingRequiredArg_single() async { | 522 test_addMissingRequiredArg_single() async { |
| 481 _addMetaPackageSource(); | 523 _addMetaPackageSource(); |
| 482 | 524 |
| 483 await resolveTestUnit(''' | 525 await resolveTestUnit(''' |
| 484 import 'package:meta/meta.dart'; | 526 import 'package:meta/meta.dart'; |
| 485 | 527 |
| 486 test({@required int abc}) {} | 528 test({@required int abc}) {} |
| 487 main() { | 529 main() { |
| 488 test(); | 530 test(); |
| 489 } | 531 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 516 ''' | 558 ''' |
| 517 import 'package:meta/meta.dart'; | 559 import 'package:meta/meta.dart'; |
| 518 | 560 |
| 519 test(String x, {@required int abc}) {} | 561 test(String x, {@required int abc}) {} |
| 520 main() { | 562 main() { |
| 521 test("foo", abc: null); | 563 test("foo", abc: null); |
| 522 } | 564 } |
| 523 '''); | 565 '''); |
| 524 } | 566 } |
| 525 | 567 |
| 568 test_addMissingRequiredArg_single_with_details() async { |
| 569 _addMetaPackageSource(); |
| 570 |
| 571 await resolveTestUnit(''' |
| 572 import 'package:meta/meta.dart'; |
| 573 |
| 574 test({@Required("Really who doesn't need an abc?") int abc}) {} |
| 575 main() { |
| 576 test(); |
| 577 } |
| 578 '''); |
| 579 await assertHasFix( |
| 580 DartFixKind.ADD_MISSING_REQUIRED_ARGUMENT, |
| 581 ''' |
| 582 import 'package:meta/meta.dart'; |
| 583 |
| 584 test({@Required("Really who doesn't need an abc?") int abc}) {} |
| 585 main() { |
| 586 test(abc: null); |
| 587 } |
| 588 '''); |
| 589 } |
| 590 |
| 526 test_addSync_asyncFor() async { | 591 test_addSync_asyncFor() async { |
| 527 await resolveTestUnit(''' | 592 await resolveTestUnit(''' |
| 528 import 'dart:async'; | 593 import 'dart:async'; |
| 529 void main(Stream<String> names) { | 594 void main(Stream<String> names) { |
| 530 await for (String name in names) { | 595 await for (String name in names) { |
| 531 print(name); | 596 print(name); |
| 532 } | 597 } |
| 533 } | 598 } |
| 534 '''); | 599 '''); |
| 535 await assertHasFix( | 600 await assertHasFix( |
| (...skipping 4891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5427 ''' | 5492 ''' |
| 5428 import 'dart:math' as pref; | 5493 import 'dart:math' as pref; |
| 5429 main() { | 5494 main() { |
| 5430 print(pref.E); | 5495 print(pref.E); |
| 5431 print(pref.PI); | 5496 print(pref.PI); |
| 5432 } | 5497 } |
| 5433 '''); | 5498 '''); |
| 5434 } | 5499 } |
| 5435 | 5500 |
| 5436 void _addMetaPackageSource() { | 5501 void _addMetaPackageSource() { |
| 5437 addPackageSource('meta', 'meta.dart', r''' | 5502 addPackageSource( |
| 5503 'meta', |
| 5504 'meta.dart', |
| 5505 r''' |
| 5438 library meta; | 5506 library meta; |
| 5439 | 5507 |
| 5440 const Required required = const Required(); | 5508 const Required required = const Required(); |
| 5441 | 5509 |
| 5442 class Required { | 5510 class Required { |
| 5443 final String reason; | 5511 final String reason; |
| 5444 const Required([this.reason]); | 5512 const Required([this.reason]); |
| 5445 } | 5513 } |
| 5446 '''); | 5514 '''); |
| 5447 } | 5515 } |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5763 | 5831 |
| 5764 @override | 5832 @override |
| 5765 final CompilationUnit unit; | 5833 final CompilationUnit unit; |
| 5766 | 5834 |
| 5767 @override | 5835 @override |
| 5768 final AnalysisError error; | 5836 final AnalysisError error; |
| 5769 | 5837 |
| 5770 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, | 5838 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, |
| 5771 this.analysisContext, this.astProvider, this.unit, this.error); | 5839 this.analysisContext, this.astProvider, this.unit, this.error); |
| 5772 } | 5840 } |
| OLD | NEW |