| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 newAnalysisError_fromEngine(lineInfo, error); | 194 newAnalysisError_fromEngine(lineInfo, error); |
| 195 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError); | 195 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError); |
| 196 errorFixesList.add(errorFixes); | 196 errorFixesList.add(errorFixes); |
| 197 fixes.forEach((fix) { | 197 fixes.forEach((fix) { |
| 198 errorFixes.fixes.add(fix.change); | 198 errorFixes.fixes.add(fix.change); |
| 199 }); | 199 }); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 } else { | 203 } else { |
| 204 CompilationUnit unit = server.getResolvedCompilationUnit(file); | 204 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 205 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | 205 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); |
| 206 if (errorInfo != null) { | 206 if (errorInfo != null) { |
| 207 LineInfo lineInfo = errorInfo.lineInfo; | 207 LineInfo lineInfo = errorInfo.lineInfo; |
| 208 int requestLine = lineInfo.getLocation(offset).lineNumber; | 208 int requestLine = lineInfo.getLocation(offset).lineNumber; |
| 209 for (engine.AnalysisError error in errorInfo.errors) { | 209 for (engine.AnalysisError error in errorInfo.errors) { |
| 210 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | 210 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 211 if (errorLine == requestLine) { | 211 if (errorLine == requestLine) { |
| 212 List<Fix> fixes = await computeFixes(server.serverPlugin, | 212 List<Fix> fixes = await computeFixes(server.serverPlugin, |
| 213 server.resourceProvider, unit.element.context, error); | 213 server.resourceProvider, unit.element.context, error); |
| 214 if (fixes.isNotEmpty) { | 214 if (fixes.isNotEmpty) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 if (result == null) { | 278 if (result == null) { |
| 279 server.sendResponse(new Response.fileNotAnalyzed(request, file)); | 279 server.sendResponse(new Response.fileNotAnalyzed(request, file)); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 fileStamp = -1; | 282 fileStamp = -1; |
| 283 code = result.content; | 283 code = result.content; |
| 284 unit = result.unit; | 284 unit = result.unit; |
| 285 errors = result.errors; | 285 errors = result.errors; |
| 286 } else { | 286 } else { |
| 287 // prepare resolved unit | 287 // prepare resolved unit |
| 288 unit = server.getResolvedCompilationUnit(file); | 288 unit = await server.getResolvedCompilationUnit(file); |
| 289 if (unit == null) { | 289 if (unit == null) { |
| 290 server.sendResponse(new Response.fileNotAnalyzed(request, file)); | 290 server.sendResponse(new Response.fileNotAnalyzed(request, file)); |
| 291 return; | 291 return; |
| 292 } | 292 } |
| 293 // prepare context | 293 // prepare context |
| 294 engine.AnalysisContext context = unit.element.context; | 294 engine.AnalysisContext context = unit.element.context; |
| 295 Source source = unit.element.source; | 295 Source source = unit.element.source; |
| 296 errors = context.computeErrors(source); | 296 errors = context.computeErrors(source); |
| 297 // prepare code | 297 // prepare code |
| 298 fileStamp = context.getModificationStamp(source); | 298 fileStamp = context.getModificationStamp(source); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 int length = params.length; | 390 int length = params.length; |
| 391 // add refactoring kinds | 391 // add refactoring kinds |
| 392 List<RefactoringKind> kinds = <RefactoringKind>[]; | 392 List<RefactoringKind> kinds = <RefactoringKind>[]; |
| 393 // try EXTRACT_* | 393 // try EXTRACT_* |
| 394 if (length != 0) { | 394 if (length != 0) { |
| 395 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); | 395 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); |
| 396 kinds.add(RefactoringKind.EXTRACT_METHOD); | 396 kinds.add(RefactoringKind.EXTRACT_METHOD); |
| 397 } | 397 } |
| 398 // check elements | 398 // check elements |
| 399 { | 399 { |
| 400 Element element = server.getElementAtOffset(file, offset); | 400 Element element = await server.getElementAtOffset(file, offset); |
| 401 if (element != null) { | 401 if (element != null) { |
| 402 // try CONVERT_METHOD_TO_GETTER | 402 // try CONVERT_METHOD_TO_GETTER |
| 403 if (element is ExecutableElement) { | 403 if (element is ExecutableElement) { |
| 404 Refactoring refactoring = | 404 Refactoring refactoring = |
| 405 new ConvertMethodToGetterRefactoring(searchEngine, element); | 405 new ConvertMethodToGetterRefactoring(searchEngine, element); |
| 406 RefactoringStatus status = await refactoring.checkInitialConditions(); | 406 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 407 if (!status.hasFatalError) { | 407 if (!status.hasFatalError) { |
| 408 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); | 408 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); |
| 409 } | 409 } |
| 410 } | 410 } |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 this.kind = kind; | 697 this.kind = kind; |
| 698 this.file = file; | 698 this.file = file; |
| 699 this.offset = offset; | 699 this.offset = offset; |
| 700 this.length = length; | 700 this.length = length; |
| 701 // simulate an exception | 701 // simulate an exception |
| 702 if (test_simulateRefactoringException_init) { | 702 if (test_simulateRefactoringException_init) { |
| 703 throw 'A simulated refactoring exception - init.'; | 703 throw 'A simulated refactoring exception - init.'; |
| 704 } | 704 } |
| 705 // create a new Refactoring instance | 705 // create a new Refactoring instance |
| 706 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) { | 706 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) { |
| 707 Element element = server.getElementAtOffset(file, offset); | 707 Element element = await server.getElementAtOffset(file, offset); |
| 708 if (element != null) { | 708 if (element != null) { |
| 709 if (element is ExecutableElement) { | 709 if (element is ExecutableElement) { |
| 710 _resetOnAnalysisStarted(); | 710 _resetOnAnalysisStarted(); |
| 711 refactoring = | 711 refactoring = |
| 712 new ConvertGetterToMethodRefactoring(searchEngine, element); | 712 new ConvertGetterToMethodRefactoring(searchEngine, element); |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 } | 715 } |
| 716 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { | 716 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { |
| 717 Element element = server.getElementAtOffset(file, offset); | 717 Element element = await server.getElementAtOffset(file, offset); |
| 718 if (element != null) { | 718 if (element != null) { |
| 719 if (element is ExecutableElement) { | 719 if (element is ExecutableElement) { |
| 720 _resetOnAnalysisStarted(); | 720 _resetOnAnalysisStarted(); |
| 721 refactoring = | 721 refactoring = |
| 722 new ConvertMethodToGetterRefactoring(searchEngine, element); | 722 new ConvertMethodToGetterRefactoring(searchEngine, element); |
| 723 } | 723 } |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 726 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 727 CompilationUnit unit = server.getResolvedCompilationUnit(file); | 727 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 728 if (unit != null) { | 728 if (unit != null) { |
| 729 _resetOnFileResolutionChanged(file); | 729 _resetOnFileResolutionChanged(file); |
| 730 refactoring = new ExtractLocalRefactoring(unit, offset, length); | 730 refactoring = new ExtractLocalRefactoring(unit, offset, length); |
| 731 feedback = new ExtractLocalVariableFeedback( | 731 feedback = new ExtractLocalVariableFeedback( |
| 732 <String>[], <int>[], <int>[], | 732 <String>[], <int>[], <int>[], |
| 733 coveringExpressionOffsets: <int>[], | 733 coveringExpressionOffsets: <int>[], |
| 734 coveringExpressionLengths: <int>[]); | 734 coveringExpressionLengths: <int>[]); |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 if (kind == RefactoringKind.EXTRACT_METHOD) { | 737 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 738 CompilationUnit unit = server.getResolvedCompilationUnit(file); | 738 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 739 if (unit != null) { | 739 if (unit != null) { |
| 740 _resetOnAnalysisStarted(); | 740 _resetOnAnalysisStarted(); |
| 741 refactoring = | 741 refactoring = |
| 742 new ExtractMethodRefactoring(searchEngine, unit, offset, length); | 742 new ExtractMethodRefactoring(searchEngine, unit, offset, length); |
| 743 feedback = new ExtractMethodFeedback(offset, length, '', <String>[], | 743 feedback = new ExtractMethodFeedback(offset, length, '', <String>[], |
| 744 false, <RefactoringMethodParameter>[], <int>[], <int>[]); | 744 false, <RefactoringMethodParameter>[], <int>[], <int>[]); |
| 745 } | 745 } |
| 746 } | 746 } |
| 747 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { | 747 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { |
| 748 CompilationUnit unit = server.getResolvedCompilationUnit(file); | 748 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 749 if (unit != null) { | 749 if (unit != null) { |
| 750 _resetOnFileResolutionChanged(file); | 750 _resetOnFileResolutionChanged(file); |
| 751 refactoring = new InlineLocalRefactoring(searchEngine, unit, offset); | 751 refactoring = new InlineLocalRefactoring(searchEngine, unit, offset); |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 if (kind == RefactoringKind.INLINE_METHOD) { | 754 if (kind == RefactoringKind.INLINE_METHOD) { |
| 755 CompilationUnit unit = server.getResolvedCompilationUnit(file); | 755 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 756 if (unit != null) { | 756 if (unit != null) { |
| 757 _resetOnAnalysisStarted(); | 757 _resetOnAnalysisStarted(); |
| 758 refactoring = new InlineMethodRefactoring(searchEngine, unit, offset); | 758 refactoring = new InlineMethodRefactoring(searchEngine, unit, offset); |
| 759 } | 759 } |
| 760 } | 760 } |
| 761 if (kind == RefactoringKind.MOVE_FILE) { | 761 if (kind == RefactoringKind.MOVE_FILE) { |
| 762 _resetOnAnalysisStarted(); | 762 _resetOnAnalysisStarted(); |
| 763 ContextSourcePair contextSource = server.getContextSourcePair(file); | 763 ContextSourcePair contextSource = server.getContextSourcePair(file); |
| 764 engine.AnalysisContext context = contextSource.context; | 764 engine.AnalysisContext context = contextSource.context; |
| 765 Source source = contextSource.source; | 765 Source source = contextSource.source; |
| 766 refactoring = new MoveFileRefactoring( | 766 refactoring = new MoveFileRefactoring( |
| 767 server.resourceProvider, searchEngine, context, source, file); | 767 server.resourceProvider, searchEngine, context, source, file); |
| 768 } | 768 } |
| 769 if (kind == RefactoringKind.RENAME) { | 769 if (kind == RefactoringKind.RENAME) { |
| 770 AstNode node = server.getNodeAtOffset(file, offset); | 770 AstNode node = await server.getNodeAtOffset(file, offset); |
| 771 Element element = server.getElementOfNode(node); | 771 Element element = server.getElementOfNode(node); |
| 772 if (node != null && element != null) { | 772 if (node != null && element != null) { |
| 773 if (element is FieldFormalParameterElement) { | 773 if (element is FieldFormalParameterElement) { |
| 774 element = (element as FieldFormalParameterElement).field; | 774 element = (element as FieldFormalParameterElement).field; |
| 775 } | 775 } |
| 776 // climb from "Class" in "new Class.named()" to "Class.named" | 776 // climb from "Class" in "new Class.named()" to "Class.named" |
| 777 if (node.parent is TypeName && node.parent.parent is ConstructorName) { | 777 if (node.parent is TypeName && node.parent.parent is ConstructorName) { |
| 778 ConstructorName constructor = node.parent.parent; | 778 ConstructorName constructor = node.parent.parent; |
| 779 node = constructor; | 779 node = constructor; |
| 780 element = constructor.staticElement; | 780 element = constructor.staticElement; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 } | 934 } |
| 935 return new RefactoringStatus(); | 935 return new RefactoringStatus(); |
| 936 } | 936 } |
| 937 } | 937 } |
| 938 | 938 |
| 939 /** | 939 /** |
| 940 * [_RefactoringManager] throws instances of this class internally to stop | 940 * [_RefactoringManager] throws instances of this class internally to stop |
| 941 * processing in a manager that was reset. | 941 * processing in a manager that was reset. |
| 942 */ | 942 */ |
| 943 class _ResetError {} | 943 class _ResetError {} |
| OLD | NEW |