| 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/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (errorInfo != null) { | 104 if (errorInfo != null) { |
| 105 LineInfo lineInfo = errorInfo.lineInfo; | 105 LineInfo lineInfo = errorInfo.lineInfo; |
| 106 int requestLine = lineInfo.getLocation(offset).lineNumber; | 106 int requestLine = lineInfo.getLocation(offset).lineNumber; |
| 107 for (engine.AnalysisError error in errorInfo.errors) { | 107 for (engine.AnalysisError error in errorInfo.errors) { |
| 108 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | 108 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 109 if (errorLine == requestLine) { | 109 if (errorLine == requestLine) { |
| 110 List<Fix> fixes = computeFixes(searchEngine, unit, error); | 110 List<Fix> fixes = computeFixes(searchEngine, unit, error); |
| 111 if (fixes.isNotEmpty) { | 111 if (fixes.isNotEmpty) { |
| 112 AnalysisError serverError = | 112 AnalysisError serverError = |
| 113 new AnalysisError.fromEngine(lineInfo, error); | 113 new AnalysisError.fromEngine(lineInfo, error); |
| 114 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError
); | 114 AnalysisErrorFixes errorFixes = |
| 115 new AnalysisErrorFixes(serverError); |
| 115 errorFixesList.add(errorFixes); | 116 errorFixesList.add(errorFixes); |
| 116 fixes.forEach((fix) { | 117 fixes.forEach((fix) { |
| 117 errorFixes.addFix(fix); | 118 errorFixes.addFix(fix); |
| 118 }); | 119 }); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 } | 124 } |
| 124 // respond | 125 // respond |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 this.offset = offset; | 241 this.offset = offset; |
| 241 this.length = length; | 242 this.length = length; |
| 242 // create a new Refactoring instance | 243 // create a new Refactoring instance |
| 243 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 244 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 244 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); | 245 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); |
| 245 if (units.isNotEmpty) { | 246 if (units.isNotEmpty) { |
| 246 refactoring = new ExtractLocalRefactoring(units[0], offset, length); | 247 refactoring = new ExtractLocalRefactoring(units[0], offset, length); |
| 247 feedback = new ExtractLocalVariableFeedback([], [], []); | 248 feedback = new ExtractLocalVariableFeedback([], [], []); |
| 248 } | 249 } |
| 249 } | 250 } |
| 251 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 252 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); |
| 253 if (units.isNotEmpty) { |
| 254 refactoring = |
| 255 new ExtractMethodRefactoring(searchEngine, units[0], offset, length)
; |
| 256 feedback = |
| 257 new ExtractMethodFeedback(offset, length, null, [], false, [], [], [
]); |
| 258 } |
| 259 } |
| 250 if (kind == RefactoringKind.RENAME) { | 260 if (kind == RefactoringKind.RENAME) { |
| 251 List<AstNode> nodes = server.getNodesAtOffset(file, offset); | 261 List<AstNode> nodes = server.getNodesAtOffset(file, offset); |
| 252 List<Element> elements = server.getElementsAtOffset(file, offset); | 262 List<Element> elements = server.getElementsAtOffset(file, offset); |
| 253 if (nodes.isNotEmpty && elements.isNotEmpty) { | 263 if (nodes.isNotEmpty && elements.isNotEmpty) { |
| 254 AstNode node = nodes[0]; | 264 AstNode node = nodes[0]; |
| 255 Element element = elements[0]; | 265 Element element = elements[0]; |
| 256 refactoring = new RenameRefactoring(searchEngine, element); | 266 refactoring = new RenameRefactoring(searchEngine, element); |
| 257 feedback = new RenameFeedback(node.offset, node.length); | 267 feedback = new RenameFeedback(node.offset, node.length); |
| 258 } | 268 } |
| 259 } | 269 } |
| 260 if (refactoring == null) { | 270 if (refactoring == null) { |
| 261 initStatus = | 271 initStatus = |
| 262 new RefactoringStatus.fatal('Unable to create a refactoring'); | 272 new RefactoringStatus.fatal('Unable to create a refactoring'); |
| 263 return new Future.value(initStatus); | 273 return new Future.value(initStatus); |
| 264 } | 274 } |
| 265 // check initial conditions | 275 // check initial conditions |
| 266 return refactoring.checkInitialConditions().then((status) { | 276 return refactoring.checkInitialConditions().then((status) { |
| 267 initStatus = status; | 277 initStatus = status; |
| 268 if (refactoring is ExtractLocalRefactoring) { | 278 if (refactoring is ExtractLocalRefactoring) { |
| 269 ExtractLocalRefactoring refactoring = this.refactoring; | 279 ExtractLocalRefactoring refactoring = this.refactoring; |
| 270 ExtractLocalVariableFeedback feedback = this.feedback; | 280 ExtractLocalVariableFeedback feedback = this.feedback; |
| 271 feedback.names = refactoring.names; | 281 feedback.names = refactoring.names; |
| 272 feedback.offsets = refactoring.offsets; | 282 feedback.offsets = refactoring.offsets; |
| 273 feedback.lengths = refactoring.lengths; | 283 feedback.lengths = refactoring.lengths; |
| 274 } | 284 } |
| 285 if (refactoring is ExtractMethodRefactoring) { |
| 286 ExtractMethodRefactoring refactoring = this.refactoring; |
| 287 ExtractMethodFeedback feedback = this.feedback; |
| 288 feedback.canCreateGetter = refactoring.canCreateGetter; |
| 289 feedback.returnType = refactoring.returnType; |
| 290 feedback.names = refactoring.names; |
| 291 feedback.parameters = refactoring.parameters; |
| 292 feedback.offsets = refactoring.offsets; |
| 293 feedback.lengths = refactoring.lengths; |
| 294 } |
| 275 return initStatus; | 295 return initStatus; |
| 276 }); | 296 }); |
| 277 } | 297 } |
| 278 | 298 |
| 279 void _reset() { | 299 void _reset() { |
| 280 refactoring = null; | 300 refactoring = null; |
| 281 feedback = null; | 301 feedback = null; |
| 282 initStatus = new RefactoringStatus(); | 302 initStatus = new RefactoringStatus(); |
| 283 optionsStatus = new RefactoringStatus(); | 303 optionsStatus = new RefactoringStatus(); |
| 284 finalStatus = new RefactoringStatus(); | 304 finalStatus = new RefactoringStatus(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 295 result.problems = status.problems; | 315 result.problems = status.problems; |
| 296 } | 316 } |
| 297 // send the response | 317 // send the response |
| 298 server.sendResponse(result.toResponse(requestId)); | 318 server.sendResponse(result.toResponse(requestId)); |
| 299 // done with this request | 319 // done with this request |
| 300 requestId = null; | 320 requestId = null; |
| 301 result = null; | 321 result = null; |
| 302 } | 322 } |
| 303 | 323 |
| 304 RefactoringStatus _setOptions(EditGetRefactoringParams params, | 324 RefactoringStatus _setOptions(EditGetRefactoringParams params, |
| 305 Request request) { | 325 Request request) { |
| 306 if (refactoring is ExtractLocalRefactoring) { | 326 if (refactoring is ExtractLocalRefactoring) { |
| 307 ExtractLocalRefactoring extractRefactoring = refactoring; | 327 ExtractLocalRefactoring extractRefactoring = refactoring; |
| 308 ExtractLocalVariableOptions extractOptions = | 328 ExtractLocalVariableOptions extractOptions = |
| 309 new ExtractLocalVariableOptions.fromRefactoringParams(params, request)
; | 329 new ExtractLocalVariableOptions.fromRefactoringParams(params, request)
; |
| 310 extractRefactoring.name = extractOptions.name; | 330 extractRefactoring.name = extractOptions.name; |
| 311 extractRefactoring.extractAll = extractOptions.extractAll; | 331 extractRefactoring.extractAll = extractOptions.extractAll; |
| 312 return extractRefactoring.checkName(); | 332 return extractRefactoring.checkName(); |
| 313 } | 333 } |
| 334 if (refactoring is ExtractMethodRefactoring) { |
| 335 ExtractMethodRefactoring extractRefactoring = this.refactoring; |
| 336 ExtractMethodOptions extractOptions = |
| 337 new ExtractMethodOptions.fromRefactoringParams(params, request); |
| 338 extractRefactoring.createGetter = extractOptions.createGetter; |
| 339 extractRefactoring.extractAll = extractOptions.extractAll; |
| 340 extractRefactoring.name = extractOptions.name; |
| 341 if (extractOptions.parameters != null) { |
| 342 extractRefactoring.parameters = extractOptions.parameters; |
| 343 } |
| 344 extractRefactoring.returnType = extractOptions.returnType; |
| 345 return extractRefactoring.checkName(); |
| 346 } |
| 314 if (refactoring is RenameRefactoring) { | 347 if (refactoring is RenameRefactoring) { |
| 315 RenameRefactoring renameRefactoring = refactoring; | 348 RenameRefactoring renameRefactoring = refactoring; |
| 316 RenameOptions renameOptions = | 349 RenameOptions renameOptions = |
| 317 new RenameOptions.fromRefactoringParams(params, request); | 350 new RenameOptions.fromRefactoringParams(params, request); |
| 318 renameRefactoring.newName = renameOptions.newName; | 351 renameRefactoring.newName = renameOptions.newName; |
| 319 return renameRefactoring.checkNewName(); | 352 return renameRefactoring.checkNewName(); |
| 320 } | 353 } |
| 321 return new RefactoringStatus(); | 354 return new RefactoringStatus(); |
| 322 } | 355 } |
| 323 } | 356 } |
| OLD | NEW |