| 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 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/computer/error.dart'; | 8 import 'package:analysis_server/src/computer/error.dart'; |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/edit/fix.dart'; | 10 import 'package:analysis_server/src/edit/fix.dart'; |
| 11 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
| 12 import 'package:analysis_server/src/services/constants.dart'; | 12 import 'package:analysis_server/src/services/constants.dart'; |
| 13 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 14 import 'package:analysis_server/src/services/correction/change.dart'; |
| 13 import 'package:analysis_server/src/services/correction/fix.dart'; | 15 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 16 import 'package:analysis_server/src/services/json.dart'; |
| 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 15 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 19 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/element.dart'; | 20 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart' as engine; | 21 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 19 import 'package:analyzer/src/generated/error.dart' as engine; | 22 import 'package:analyzer/src/generated/error.dart' as engine; |
| 20 | 23 |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * Instances of the class [EditDomainHandler] implement a [RequestHandler] | 26 * Instances of the class [EditDomainHandler] implement a [RequestHandler] |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 SearchEngine searchEngine; | 38 SearchEngine searchEngine; |
| 36 | 39 |
| 37 /** | 40 /** |
| 38 * Initialize a newly created handler to handle requests for the given [server
]. | 41 * Initialize a newly created handler to handle requests for the given [server
]. |
| 39 */ | 42 */ |
| 40 EditDomainHandler(this.server) { | 43 EditDomainHandler(this.server) { |
| 41 searchEngine = server.searchEngine; | 44 searchEngine = server.searchEngine; |
| 42 } | 45 } |
| 43 | 46 |
| 44 Response getAssists(Request request) { | 47 Response getAssists(Request request) { |
| 45 // file | 48 String file = request.getRequiredParameter(FILE).asString(); |
| 46 RequestDatum fileDatum = request.getRequiredParameter(FILE); | 49 int offset = request.getRequiredParameter(OFFSET).asInt(); |
| 47 String file = fileDatum.asString(); | 50 int length = request.getRequiredParameter(LENGTH).asInt(); |
| 48 // offset | 51 List<Change> changes = <Change>[]; |
| 49 RequestDatum offsetDatum = request.getRequiredParameter(OFFSET); | 52 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); |
| 50 int offset = offsetDatum.asInt(); | 53 if (units.isNotEmpty) { |
| 51 // length | 54 CompilationUnit unit = units[0]; |
| 52 RequestDatum lengthDatum = request.getRequiredParameter(LENGTH); | 55 List<Assist> assists = computeAssists(searchEngine, unit, offset, length); |
| 53 int length = lengthDatum.asInt(); | 56 assists.forEach((Assist assist) { |
| 54 // TODO(brianwilkerson) implement | 57 changes.add(assist.change); |
| 55 return null; | 58 }); |
| 59 } |
| 60 // respond |
| 61 Response response = new Response(request.id); |
| 62 response.setResult(ASSISTS, objectToJson(changes)); |
| 63 return response; |
| 56 } | 64 } |
| 57 | 65 |
| 58 Response getAvailableRefactorings(Request request) { | 66 Response getAvailableRefactorings(Request request) { |
| 59 String file = request.getRequiredParameter(FILE).asString(); | 67 String file = request.getRequiredParameter(FILE).asString(); |
| 60 int offset = request.getRequiredParameter(OFFSET).asInt(); | 68 int offset = request.getRequiredParameter(OFFSET).asInt(); |
| 61 int length = request.getRequiredParameter(LENGTH).asInt(); | 69 int length = request.getRequiredParameter(LENGTH).asInt(); |
| 62 List<String> kinds = <String>[]; | 70 List<String> kinds = <String>[]; |
| 63 List<Element> elements = server.getElementsAtOffset(file, offset); | 71 List<Element> elements = server.getElementsAtOffset(file, offset); |
| 64 if (elements.isNotEmpty) { | 72 if (elements.isNotEmpty) { |
| 65 Element element = elements[0]; | 73 Element element = elements[0]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 82 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | 90 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); |
| 83 if (errorInfo != null) { | 91 if (errorInfo != null) { |
| 84 for (engine.AnalysisError error in errorInfo.errors) { | 92 for (engine.AnalysisError error in errorInfo.errors) { |
| 85 List<Fix> fixes = computeFixes(searchEngine, unit, error); | 93 List<Fix> fixes = computeFixes(searchEngine, unit, error); |
| 86 if (fixes.isNotEmpty) { | 94 if (fixes.isNotEmpty) { |
| 87 AnalysisError serverError = | 95 AnalysisError serverError = |
| 88 new AnalysisError.fromEngine(errorInfo.lineInfo, error); | 96 new AnalysisError.fromEngine(errorInfo.lineInfo, error); |
| 89 ErrorFixes errorFixes = new ErrorFixes(serverError); | 97 ErrorFixes errorFixes = new ErrorFixes(serverError); |
| 90 errorFixesList.add(errorFixes); | 98 errorFixesList.add(errorFixes); |
| 91 fixes.forEach((fix) { | 99 fixes.forEach((fix) { |
| 92 return errorFixes.addFix(fix); | 100 errorFixes.addFix(fix); |
| 93 }); | 101 }); |
| 94 } | 102 } |
| 95 } | 103 } |
| 96 } | 104 } |
| 97 } | 105 } |
| 98 // respond | 106 // respond |
| 99 return new Response(request.id)..setResult(FIXES, errorFixesList); | 107 return new Response(request.id)..setResult(FIXES, errorFixesList); |
| 100 } | 108 } |
| 101 | 109 |
| 102 @override | 110 @override |
| (...skipping 17 matching lines...) Expand all Loading... |
| 120 | 128 |
| 121 class RefactoringKind { | 129 class RefactoringKind { |
| 122 static const String CONVERT_GETTER_TO_METHOD = 'CONVERT_GETTER_TO_METHOD'; | 130 static const String CONVERT_GETTER_TO_METHOD = 'CONVERT_GETTER_TO_METHOD'; |
| 123 static const String CONVERT_METHOD_TO_GETTER = 'CONVERT_METHOD_TO_GETTER'; | 131 static const String CONVERT_METHOD_TO_GETTER = 'CONVERT_METHOD_TO_GETTER'; |
| 124 static const String EXTRACT_LOCAL_VARIABLE = 'EXTRACT_LOCAL_VARIABLE'; | 132 static const String EXTRACT_LOCAL_VARIABLE = 'EXTRACT_LOCAL_VARIABLE'; |
| 125 static const String EXTRACT_METHOD = 'EXTRACT_METHOD'; | 133 static const String EXTRACT_METHOD = 'EXTRACT_METHOD'; |
| 126 static const String INLINE_LOCAL_VARIABLE = 'INLINE_LOCAL_VARIABLE'; | 134 static const String INLINE_LOCAL_VARIABLE = 'INLINE_LOCAL_VARIABLE'; |
| 127 static const String INLINE_METHOD = 'INLINE_METHOD'; | 135 static const String INLINE_METHOD = 'INLINE_METHOD'; |
| 128 static const String RENAME = 'RENAME'; | 136 static const String RENAME = 'RENAME'; |
| 129 } | 137 } |
| OLD | NEW |