Chromium Code Reviews| 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/plugin/edit/assist/assist_core.dart'; | 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; |
| 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 if (length != 0) { | 396 if (length != 0) { |
| 397 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); | 397 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); |
| 398 kinds.add(RefactoringKind.EXTRACT_METHOD); | 398 kinds.add(RefactoringKind.EXTRACT_METHOD); |
| 399 } | 399 } |
| 400 // check elements | 400 // check elements |
| 401 { | 401 { |
| 402 Element element = await server.getElementAtOffset(file, offset); | 402 Element element = await server.getElementAtOffset(file, offset); |
| 403 if (element != null) { | 403 if (element != null) { |
| 404 // try CONVERT_METHOD_TO_GETTER | 404 // try CONVERT_METHOD_TO_GETTER |
| 405 if (element is ExecutableElement) { | 405 if (element is ExecutableElement) { |
| 406 Refactoring refactoring = | 406 Refactoring refactoring = new ConvertMethodToGetterRefactoring( |
| 407 new ConvertMethodToGetterRefactoring(searchEngine, element); | 407 searchEngine, |
| 408 (element) => | |
| 409 throw new StateError('Unexpected resolved unit request.'), | |
|
Brian Wilkerson
2016/11/30 17:34:18
I guess this is fine, but I was thinking of passin
| |
| 410 element); | |
| 408 RefactoringStatus status = await refactoring.checkInitialConditions(); | 411 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 409 if (!status.hasFatalError) { | 412 if (!status.hasFatalError) { |
| 410 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); | 413 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); |
| 411 } | 414 } |
| 412 } | 415 } |
| 413 // try RENAME | 416 // try RENAME |
| 414 { | 417 { |
| 415 RenameRefactoring renameRefactoring = | 418 RenameRefactoring renameRefactoring = |
| 416 new RenameRefactoring(searchEngine, element); | 419 new RenameRefactoring(searchEngine, element); |
| 417 if (renameRefactoring != null) { | 420 if (renameRefactoring != null) { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 | 680 |
| 678 void _checkForReset_afterInitialConditions() { | 681 void _checkForReset_afterInitialConditions() { |
| 679 if (test_simulateRefactoringReset_afterInitialConditions) { | 682 if (test_simulateRefactoringReset_afterInitialConditions) { |
| 680 _reset(); | 683 _reset(); |
| 681 } | 684 } |
| 682 if (refactoring == null) { | 685 if (refactoring == null) { |
| 683 throw new _ResetError(); | 686 throw new _ResetError(); |
| 684 } | 687 } |
| 685 } | 688 } |
| 686 | 689 |
| 690 Future<CompilationUnit> _getResolvedUnit(Element element) { | |
| 691 String path = element.source.fullName; | |
| 692 return server.getResolvedCompilationUnit(path); | |
| 693 } | |
| 694 | |
| 687 /** | 695 /** |
| 688 * Initializes this context to perform a refactoring with the specified | 696 * Initializes this context to perform a refactoring with the specified |
| 689 * parameters. The existing [Refactoring] is reused or created as needed. | 697 * parameters. The existing [Refactoring] is reused or created as needed. |
| 690 */ | 698 */ |
| 691 Future _init( | 699 Future _init( |
| 692 RefactoringKind kind, String file, int offset, int length) async { | 700 RefactoringKind kind, String file, int offset, int length) async { |
| 693 await _analyzeForRefactoring(file, kind); | 701 await _analyzeForRefactoring(file, kind); |
| 694 // check if we can continue with the existing Refactoring instance | 702 // check if we can continue with the existing Refactoring instance |
| 695 if (this.kind == kind && | 703 if (this.kind == kind && |
| 696 this.file == file && | 704 this.file == file && |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 716 refactoring = | 724 refactoring = |
| 717 new ConvertGetterToMethodRefactoring(searchEngine, element); | 725 new ConvertGetterToMethodRefactoring(searchEngine, element); |
| 718 } | 726 } |
| 719 } | 727 } |
| 720 } | 728 } |
| 721 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { | 729 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { |
| 722 Element element = await server.getElementAtOffset(file, offset); | 730 Element element = await server.getElementAtOffset(file, offset); |
| 723 if (element != null) { | 731 if (element != null) { |
| 724 if (element is ExecutableElement) { | 732 if (element is ExecutableElement) { |
| 725 _resetOnAnalysisStarted(); | 733 _resetOnAnalysisStarted(); |
| 726 refactoring = | 734 refactoring = new ConvertMethodToGetterRefactoring( |
| 727 new ConvertMethodToGetterRefactoring(searchEngine, element); | 735 searchEngine, _getResolvedUnit, element); |
| 728 } | 736 } |
| 729 } | 737 } |
| 730 } | 738 } |
| 731 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 739 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 732 CompilationUnit unit = await server.getResolvedCompilationUnit(file); | 740 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 733 if (unit != null) { | 741 if (unit != null) { |
| 734 _resetOnFileResolutionChanged(file); | 742 _resetOnFileResolutionChanged(file); |
| 735 refactoring = new ExtractLocalRefactoring(unit, offset, length); | 743 refactoring = new ExtractLocalRefactoring(unit, offset, length); |
| 736 feedback = new ExtractLocalVariableFeedback( | 744 feedback = new ExtractLocalVariableFeedback( |
| 737 <String>[], <int>[], <int>[], | 745 <String>[], <int>[], <int>[], |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 753 CompilationUnit unit = await server.getResolvedCompilationUnit(file); | 761 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 754 if (unit != null) { | 762 if (unit != null) { |
| 755 _resetOnFileResolutionChanged(file); | 763 _resetOnFileResolutionChanged(file); |
| 756 refactoring = new InlineLocalRefactoring(searchEngine, unit, offset); | 764 refactoring = new InlineLocalRefactoring(searchEngine, unit, offset); |
| 757 } | 765 } |
| 758 } | 766 } |
| 759 if (kind == RefactoringKind.INLINE_METHOD) { | 767 if (kind == RefactoringKind.INLINE_METHOD) { |
| 760 CompilationUnit unit = await server.getResolvedCompilationUnit(file); | 768 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 761 if (unit != null) { | 769 if (unit != null) { |
| 762 _resetOnAnalysisStarted(); | 770 _resetOnAnalysisStarted(); |
| 763 refactoring = | 771 refactoring = new InlineMethodRefactoring( |
| 764 new InlineMethodRefactoring(searchEngine, (Element element) async { | 772 searchEngine, _getResolvedUnit, unit, offset); |
| 765 String elementPath = element.source.fullName; | |
| 766 return await server.getResolvedCompilationUnit(elementPath); | |
| 767 }, unit, offset); | |
| 768 } | 773 } |
| 769 } | 774 } |
| 770 if (kind == RefactoringKind.MOVE_FILE) { | 775 if (kind == RefactoringKind.MOVE_FILE) { |
| 771 _resetOnAnalysisStarted(); | 776 _resetOnAnalysisStarted(); |
| 772 ContextSourcePair contextSource = server.getContextSourcePair(file); | 777 ContextSourcePair contextSource = server.getContextSourcePair(file); |
| 773 engine.AnalysisContext context = contextSource.context; | 778 engine.AnalysisContext context = contextSource.context; |
| 774 Source source = contextSource.source; | 779 Source source = contextSource.source; |
| 775 refactoring = new MoveFileRefactoring( | 780 refactoring = new MoveFileRefactoring( |
| 776 server.resourceProvider, searchEngine, context, source, file); | 781 server.resourceProvider, searchEngine, context, source, file); |
| 777 } | 782 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 } | 951 } |
| 947 return new RefactoringStatus(); | 952 return new RefactoringStatus(); |
| 948 } | 953 } |
| 949 } | 954 } |
| 950 | 955 |
| 951 /** | 956 /** |
| 952 * [_RefactoringManager] throws instances of this class internally to stop | 957 * [_RefactoringManager] throws instances of this class internally to stop |
| 953 * processing in a manager that was reset. | 958 * processing in a manager that was reset. |
| 954 */ | 959 */ |
| 955 class _ResetError {} | 960 class _ResetError {} |
| OLD | NEW |