| 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 'package:analysis_server/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; | 8 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; |
| 9 import 'package:analysis_server/src/services/correction/fix.dart'; | 9 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 main() { | 534 main() { |
| 535 Test v = null; | 535 Test v = null; |
| 536 } | 536 } |
| 537 | 537 |
| 538 class Test { | 538 class Test { |
| 539 } | 539 } |
| 540 '''); | 540 '''); |
| 541 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 541 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 542 } | 542 } |
| 543 | 543 |
| 544 void test_createClass_BAD_hasUnresolvedPrefix() { |
| 545 resolveTestUnit(''' |
| 546 main() { |
| 547 prefix.Test v = null; |
| 548 } |
| 549 '''); |
| 550 assertNoFix(DartFixKind.CREATE_CLASS); |
| 551 } |
| 552 |
| 544 void test_createClass_inLibraryOfPrefix() { | 553 void test_createClass_inLibraryOfPrefix() { |
| 545 String libCode = r''' | 554 String libCode = r''' |
| 546 library my.lib; | 555 library my.lib; |
| 547 | 556 |
| 548 class A {} | 557 class A {} |
| 549 '''; | 558 '''; |
| 550 addSource('/lib.dart', libCode); | 559 addSource('/lib.dart', libCode); |
| 551 resolveTestUnit(''' | 560 resolveTestUnit(''' |
| 552 import 'lib.dart' as lib; | 561 import 'lib.dart' as lib; |
| 553 | 562 |
| (...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2605 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2614 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2606 ''' | 2615 ''' |
| 2607 import 'package:my_pkg/my_lib.dart'; | 2616 import 'package:my_pkg/my_lib.dart'; |
| 2608 | 2617 |
| 2609 main() { | 2618 main() { |
| 2610 Test test = null; | 2619 Test test = null; |
| 2611 } | 2620 } |
| 2612 '''); | 2621 '''); |
| 2613 } | 2622 } |
| 2614 | 2623 |
| 2615 void test_importLibraryPrefix_withClass() { | |
| 2616 resolveTestUnit(''' | |
| 2617 import 'dart:async' as pref; | |
| 2618 main() { | |
| 2619 pref.Stream s = null; | |
| 2620 Future f = null; | |
| 2621 } | |
| 2622 '''); | |
| 2623 assertHasFix( | |
| 2624 DartFixKind.IMPORT_LIBRARY_PREFIX, | |
| 2625 ''' | |
| 2626 import 'dart:async' as pref; | |
| 2627 main() { | |
| 2628 pref.Stream s = null; | |
| 2629 pref.Future f = null; | |
| 2630 } | |
| 2631 '''); | |
| 2632 } | |
| 2633 | |
| 2634 void test_importLibraryPrefix_withTopLevelVariable() { | |
| 2635 resolveTestUnit(''' | |
| 2636 import 'dart:math' as pref; | |
| 2637 main() { | |
| 2638 print(pref.E); | |
| 2639 print(PI); | |
| 2640 } | |
| 2641 '''); | |
| 2642 assertHasFix( | |
| 2643 DartFixKind.IMPORT_LIBRARY_PREFIX, | |
| 2644 ''' | |
| 2645 import 'dart:math' as pref; | |
| 2646 main() { | |
| 2647 print(pref.E); | |
| 2648 print(pref.PI); | |
| 2649 } | |
| 2650 '''); | |
| 2651 } | |
| 2652 | |
| 2653 void test_importLibraryProject_withClass_annotation() { | 2624 void test_importLibraryProject_withClass_annotation() { |
| 2654 addSource( | 2625 addSource( |
| 2655 '/lib.dart', | 2626 '/lib.dart', |
| 2656 ''' | 2627 ''' |
| 2657 library lib; | 2628 library lib; |
| 2658 class Test { | 2629 class Test { |
| 2659 const Test(int p); | 2630 const Test(int p); |
| 2660 } | 2631 } |
| 2661 '''); | 2632 '''); |
| 2662 resolveTestUnit(''' | 2633 resolveTestUnit(''' |
| (...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4357 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, | 4328 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, |
| 4358 ''' | 4329 ''' |
| 4359 main() { | 4330 main() { |
| 4360 var a = 5; | 4331 var a = 5; |
| 4361 var b = 2; | 4332 var b = 2; |
| 4362 print(a ~/ b); | 4333 print(a ~/ b); |
| 4363 } | 4334 } |
| 4364 '''); | 4335 '''); |
| 4365 } | 4336 } |
| 4366 | 4337 |
| 4338 void test_useImportPrefix_withClass() { |
| 4339 resolveTestUnit(''' |
| 4340 import 'dart:async' as pref; |
| 4341 main() { |
| 4342 pref.Stream s = null; |
| 4343 Future f = null; |
| 4344 } |
| 4345 '''); |
| 4346 assertHasFix( |
| 4347 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 4348 ''' |
| 4349 import 'dart:async' as pref; |
| 4350 main() { |
| 4351 pref.Stream s = null; |
| 4352 pref.Future f = null; |
| 4353 } |
| 4354 '''); |
| 4355 } |
| 4356 |
| 4357 void test_useImportPrefix_withTopLevelVariable() { |
| 4358 resolveTestUnit(''' |
| 4359 import 'dart:math' as pref; |
| 4360 main() { |
| 4361 print(pref.E); |
| 4362 print(PI); |
| 4363 } |
| 4364 '''); |
| 4365 assertHasFix( |
| 4366 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 4367 ''' |
| 4368 import 'dart:math' as pref; |
| 4369 main() { |
| 4370 print(pref.E); |
| 4371 print(pref.PI); |
| 4372 } |
| 4373 '''); |
| 4374 } |
| 4375 |
| 4367 /** | 4376 /** |
| 4368 * Computes fixes and verifies that there is a fix of the given kind. | 4377 * Computes fixes and verifies that there is a fix of the given kind. |
| 4369 */ | 4378 */ |
| 4370 Fix _assertHasFix(FixKind kind, AnalysisError error) { | 4379 Fix _assertHasFix(FixKind kind, AnalysisError error) { |
| 4371 List<Fix> fixes = _computeFixes(error); | 4380 List<Fix> fixes = _computeFixes(error); |
| 4372 for (Fix fix in fixes) { | 4381 for (Fix fix in fixes) { |
| 4373 if (fix.kind == kind) { | 4382 if (fix.kind == kind) { |
| 4374 return fix; | 4383 return fix; |
| 4375 } | 4384 } |
| 4376 } | 4385 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4426 int offset = resultCode.indexOf(search); | 4435 int offset = resultCode.indexOf(search); |
| 4427 positions.add(new Position(testFile, offset)); | 4436 positions.add(new Position(testFile, offset)); |
| 4428 } | 4437 } |
| 4429 return positions; | 4438 return positions; |
| 4430 } | 4439 } |
| 4431 | 4440 |
| 4432 void _performAnalysis() { | 4441 void _performAnalysis() { |
| 4433 while (context.performAnalysisTask().hasMoreWork); | 4442 while (context.performAnalysisTask().hasMoreWork); |
| 4434 } | 4443 } |
| 4435 } | 4444 } |
| OLD | NEW |