| 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/collections.dart'; | 10 import 'package:analysis_server/src/collections.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 12 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| 13 import 'package:analysis_server/src/services/correction/assist.dart'; | 13 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 14 import 'package:analysis_server/src/services/correction/fix.dart'; | 14 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 15 import 'package:analysis_server/src/services/correction/sort_members.dart'; | 15 import 'package:analysis_server/src/services/correction/sort_members.dart'; |
| 16 import 'package:analysis_server/src/services/correction/status.dart'; | 16 import 'package:analysis_server/src/services/correction/status.dart'; |
| 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 18 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 19 import 'package:analyzer/src/generated/ast.dart'; | 19 import 'package:analyzer/src/generated/ast.dart'; |
| 20 import 'package:analyzer/src/generated/element.dart'; | 20 import 'package:analyzer/src/generated/element.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart' as engine; | 21 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 22 import 'package:analyzer/src/generated/error.dart' as engine; | 22 import 'package:analyzer/src/generated/error.dart' as engine; |
| 23 import 'package:analyzer/src/generated/parser.dart' as engine; | 23 import 'package:analyzer/src/generated/parser.dart' as engine; |
| 24 import 'package:analyzer/src/generated/scanner.dart' as engine; | 24 import 'package:analyzer/src/generated/scanner.dart' as engine; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 26 | 26 |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * This flag is used in tests to check behavior when an exception happens |
| 30 * inside a refactoring. |
| 31 */ |
| 32 bool test_simulateRefactoringException = false; |
| 33 |
| 34 |
| 35 /** |
| 29 * Instances of the class [EditDomainHandler] implement a [RequestHandler] | 36 * Instances of the class [EditDomainHandler] implement a [RequestHandler] |
| 30 * that handles requests in the edit domain. | 37 * that handles requests in the edit domain. |
| 31 */ | 38 */ |
| 32 class EditDomainHandler implements RequestHandler { | 39 class EditDomainHandler implements RequestHandler { |
| 33 /** | 40 /** |
| 34 * The analysis server that is using this handler to process requests. | 41 * The analysis server that is using this handler to process requests. |
| 35 */ | 42 */ |
| 36 final AnalysisServer server; | 43 final AnalysisServer server; |
| 37 | 44 |
| 38 /** | 45 /** |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 if (_hasFatalError) { | 286 if (_hasFatalError) { |
| 280 return _sendResultResponse(); | 287 return _sendResultResponse(); |
| 281 } | 288 } |
| 282 // create change | 289 // create change |
| 283 return refactoring.createChange().then((change) { | 290 return refactoring.createChange().then((change) { |
| 284 result.change = change; | 291 result.change = change; |
| 285 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); | 292 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); |
| 286 return _sendResultResponse(); | 293 return _sendResultResponse(); |
| 287 }); | 294 }); |
| 288 }); | 295 }); |
| 296 }).catchError((exception, stackTrace) { |
| 297 _reset(); |
| 298 server.sendResponse( |
| 299 new Response.serverError(request, exception, stackTrace)); |
| 289 }); | 300 }); |
| 290 } | 301 } |
| 291 | 302 |
| 292 /** | 303 /** |
| 293 * Initializes this context to perform a refactoring with the specified | 304 * Initializes this context to perform a refactoring with the specified |
| 294 * parameters. The existing [Refactoring] is reused or created as needed. | 305 * parameters. The existing [Refactoring] is reused or created as needed. |
| 295 */ | 306 */ |
| 296 Future<RefactoringStatus> _init(RefactoringKind kind, String file, int offset, | 307 Future<RefactoringStatus> _init(RefactoringKind kind, String file, int offset, |
| 297 int length) { | 308 int length) { |
| 298 // check if we can continue with the existing Refactoring instance | 309 // check if we can continue with the existing Refactoring instance |
| 299 if (this.kind == kind && | 310 if (this.kind == kind && |
| 300 this.file == file && | 311 this.file == file && |
| 301 this.offset == offset && | 312 this.offset == offset && |
| 302 this.length == length) { | 313 this.length == length) { |
| 303 return new Future.value(initStatus); | 314 return new Future.value(initStatus); |
| 304 } | 315 } |
| 305 _reset(); | 316 _reset(); |
| 306 this.kind = kind; | 317 this.kind = kind; |
| 307 this.file = file; | 318 this.file = file; |
| 308 this.offset = offset; | 319 this.offset = offset; |
| 309 this.length = length; | 320 this.length = length; |
| 321 // simulate an exception |
| 322 if (test_simulateRefactoringException) { |
| 323 throw 'A simulated refactoring exception.'; |
| 324 } |
| 310 // create a new Refactoring instance | 325 // create a new Refactoring instance |
| 311 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) { | 326 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) { |
| 312 List<Element> elements = server.getElementsAtOffset(file, offset); | 327 List<Element> elements = server.getElementsAtOffset(file, offset); |
| 313 if (elements.isNotEmpty) { | 328 if (elements.isNotEmpty) { |
| 314 Element element = elements[0]; | 329 Element element = elements[0]; |
| 315 if (element is ExecutableElement) { | 330 if (element is ExecutableElement) { |
| 316 refactoring = | 331 refactoring = |
| 317 new ConvertGetterToMethodRefactoring(searchEngine, element); | 332 new ConvertGetterToMethodRefactoring(searchEngine, element); |
| 318 } | 333 } |
| 319 } | 334 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 516 } |
| 502 if (refactoring is RenameRefactoring) { | 517 if (refactoring is RenameRefactoring) { |
| 503 RenameRefactoring renameRefactoring = refactoring; | 518 RenameRefactoring renameRefactoring = refactoring; |
| 504 RenameOptions renameOptions = params.options; | 519 RenameOptions renameOptions = params.options; |
| 505 renameRefactoring.newName = renameOptions.newName; | 520 renameRefactoring.newName = renameOptions.newName; |
| 506 return renameRefactoring.checkNewName(); | 521 return renameRefactoring.checkNewName(); |
| 507 } | 522 } |
| 508 return new RefactoringStatus(); | 523 return new RefactoringStatus(); |
| 509 } | 524 } |
| 510 } | 525 } |
| OLD | NEW |