| 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 edit.domain; | 5 library edit.domain; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/edit/assist/assist_core.dart'; | 9 import 'package:analysis_server/edit/assist/assist_core.dart'; |
| 10 import 'package:analysis_server/edit/fix/fix_core.dart'; | 10 import 'package:analysis_server/edit/fix/fix_core.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import 'package:analyzer/src/generated/error.dart' as engine; | 25 import 'package:analyzer/src/generated/error.dart' as engine; |
| 26 import 'package:analyzer/src/generated/parser.dart' as engine; | 26 import 'package:analyzer/src/generated/parser.dart' as engine; |
| 27 import 'package:analyzer/src/generated/scanner.dart' as engine; | 27 import 'package:analyzer/src/generated/scanner.dart' as engine; |
| 28 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
| 29 import 'package:dart_style/dart_style.dart'; | 29 import 'package:dart_style/dart_style.dart'; |
| 30 | 30 |
| 31 bool test_simulateRefactoringException_change = false; | 31 bool test_simulateRefactoringException_change = false; |
| 32 bool test_simulateRefactoringException_final = false; | 32 bool test_simulateRefactoringException_final = false; |
| 33 bool test_simulateRefactoringException_init = false; | 33 bool test_simulateRefactoringException_init = false; |
| 34 | 34 |
| 35 bool test_simulateRefactoringReset_afterCreateChange = false; |
| 36 bool test_simulateRefactoringReset_afterFinalConditions = false; |
| 37 bool test_simulateRefactoringReset_afterInitialConditions = false; |
| 38 |
| 35 /** | 39 /** |
| 36 * Instances of the class [EditDomainHandler] implement a [RequestHandler] | 40 * Instances of the class [EditDomainHandler] implement a [RequestHandler] |
| 37 * that handles requests in the edit domain. | 41 * that handles requests in the edit domain. |
| 38 */ | 42 */ |
| 39 class EditDomainHandler implements RequestHandler { | 43 class EditDomainHandler implements RequestHandler { |
| 40 /** | 44 /** |
| 41 * The analysis server that is using this handler to process requests. | 45 * The analysis server that is using this handler to process requests. |
| 42 */ | 46 */ |
| 43 final AnalysisServer server; | 47 final AnalysisServer server; |
| 44 | 48 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 finalStatus = new RefactoringStatus(); | 449 finalStatus = new RefactoringStatus(); |
| 446 _sendResultResponse(); | 450 _sendResultResponse(); |
| 447 return; | 451 return; |
| 448 } | 452 } |
| 449 // simulate an exception | 453 // simulate an exception |
| 450 if (test_simulateRefactoringException_final) { | 454 if (test_simulateRefactoringException_final) { |
| 451 throw 'A simulated refactoring exception - final.'; | 455 throw 'A simulated refactoring exception - final.'; |
| 452 } | 456 } |
| 453 // validation and create change | 457 // validation and create change |
| 454 finalStatus = await refactoring.checkFinalConditions(); | 458 finalStatus = await refactoring.checkFinalConditions(); |
| 459 _checkForReset_afterFinalConditions(); |
| 455 if (_hasFatalError) { | 460 if (_hasFatalError) { |
| 456 _sendResultResponse(); | 461 _sendResultResponse(); |
| 457 return; | 462 return; |
| 458 } | 463 } |
| 459 // simulate an exception | 464 // simulate an exception |
| 460 if (test_simulateRefactoringException_change) { | 465 if (test_simulateRefactoringException_change) { |
| 461 throw 'A simulated refactoring exception - change.'; | 466 throw 'A simulated refactoring exception - change.'; |
| 462 } | 467 } |
| 463 // create change | 468 // create change |
| 464 result.change = await refactoring.createChange(); | 469 result.change = await refactoring.createChange(); |
| 465 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); | 470 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); |
| 471 _checkForReset_afterCreateChange(); |
| 466 _sendResultResponse(); | 472 _sendResultResponse(); |
| 467 }, onError: (exception, stackTrace) { | 473 }, onError: (exception, stackTrace) { |
| 468 server.instrumentationService.logException(exception, stackTrace); | 474 if (exception is _ResetError) { |
| 469 server.sendResponse( | 475 cancel(); |
| 470 new Response.serverError(_request, exception, stackTrace)); | 476 } else { |
| 477 server.instrumentationService.logException(exception, stackTrace); |
| 478 server.sendResponse( |
| 479 new Response.serverError(_request, exception, stackTrace)); |
| 480 } |
| 471 _reset(); | 481 _reset(); |
| 472 }); | 482 }); |
| 473 } | 483 } |
| 474 | 484 |
| 485 void _checkForReset_afterCreateChange() { |
| 486 if (test_simulateRefactoringReset_afterCreateChange) { |
| 487 _reset(); |
| 488 } |
| 489 if (refactoring == null) { |
| 490 throw new _ResetError(); |
| 491 } |
| 492 } |
| 493 |
| 494 void _checkForReset_afterFinalConditions() { |
| 495 if (test_simulateRefactoringReset_afterFinalConditions) { |
| 496 _reset(); |
| 497 } |
| 498 if (refactoring == null) { |
| 499 throw new _ResetError(); |
| 500 } |
| 501 } |
| 502 |
| 503 void _checkForReset_afterInitialConditions() { |
| 504 if (test_simulateRefactoringReset_afterInitialConditions) { |
| 505 _reset(); |
| 506 } |
| 507 if (refactoring == null) { |
| 508 throw new _ResetError(); |
| 509 } |
| 510 } |
| 511 |
| 475 /** | 512 /** |
| 476 * Initializes this context to perform a refactoring with the specified | 513 * Initializes this context to perform a refactoring with the specified |
| 477 * parameters. The existing [Refactoring] is reused or created as needed. | 514 * parameters. The existing [Refactoring] is reused or created as needed. |
| 478 */ | 515 */ |
| 479 Future _init( | 516 Future _init( |
| 480 RefactoringKind kind, String file, int offset, int length) async { | 517 RefactoringKind kind, String file, int offset, int length) async { |
| 481 await server.onAnalysisComplete; | 518 await server.onAnalysisComplete; |
| 482 // check if we can continue with the existing Refactoring instance | 519 // check if we can continue with the existing Refactoring instance |
| 483 if (this.kind == kind && | 520 if (this.kind == kind && |
| 484 this.file == file && | 521 this.file == file && |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); | 611 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); |
| 575 } | 612 } |
| 576 } | 613 } |
| 577 if (refactoring == null) { | 614 if (refactoring == null) { |
| 578 initStatus = | 615 initStatus = |
| 579 new RefactoringStatus.fatal('Unable to create a refactoring'); | 616 new RefactoringStatus.fatal('Unable to create a refactoring'); |
| 580 return; | 617 return; |
| 581 } | 618 } |
| 582 // check initial conditions | 619 // check initial conditions |
| 583 initStatus = await refactoring.checkInitialConditions(); | 620 initStatus = await refactoring.checkInitialConditions(); |
| 621 _checkForReset_afterInitialConditions(); |
| 584 if (refactoring is ExtractLocalRefactoring) { | 622 if (refactoring is ExtractLocalRefactoring) { |
| 585 ExtractLocalRefactoring refactoring = this.refactoring; | 623 ExtractLocalRefactoring refactoring = this.refactoring; |
| 586 ExtractLocalVariableFeedback feedback = this.feedback; | 624 ExtractLocalVariableFeedback feedback = this.feedback; |
| 587 feedback.names = refactoring.names; | 625 feedback.names = refactoring.names; |
| 588 feedback.offsets = refactoring.offsets; | 626 feedback.offsets = refactoring.offsets; |
| 589 feedback.lengths = refactoring.lengths; | 627 feedback.lengths = refactoring.lengths; |
| 590 } | 628 } |
| 591 if (refactoring is ExtractMethodRefactoring) { | 629 if (refactoring is ExtractMethodRefactoring) { |
| 592 ExtractMethodRefactoring refactoring = this.refactoring; | 630 ExtractMethodRefactoring refactoring = this.refactoring; |
| 593 ExtractMethodFeedback feedback = this.feedback; | 631 ExtractMethodFeedback feedback = this.feedback; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 723 } |
| 686 if (refactoring is RenameRefactoring) { | 724 if (refactoring is RenameRefactoring) { |
| 687 RenameRefactoring renameRefactoring = refactoring; | 725 RenameRefactoring renameRefactoring = refactoring; |
| 688 RenameOptions renameOptions = params.options; | 726 RenameOptions renameOptions = params.options; |
| 689 renameRefactoring.newName = renameOptions.newName; | 727 renameRefactoring.newName = renameOptions.newName; |
| 690 return renameRefactoring.checkNewName(); | 728 return renameRefactoring.checkNewName(); |
| 691 } | 729 } |
| 692 return new RefactoringStatus(); | 730 return new RefactoringStatus(); |
| 693 } | 731 } |
| 694 } | 732 } |
| 733 |
| 734 /** |
| 735 * [_RefactoringManager] throws instances of this class internally to stop |
| 736 * processing in a manager that was reset. |
| 737 */ |
| 738 class _ResetError {} |
| OLD | NEW |