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/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'; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 result = new EditGetRefactoringResult( | 301 result = new EditGetRefactoringResult( |
| 302 EMPTY_PROBLEM_LIST, | 302 EMPTY_PROBLEM_LIST, |
| 303 EMPTY_PROBLEM_LIST, | 303 EMPTY_PROBLEM_LIST, |
| 304 EMPTY_PROBLEM_LIST); | 304 EMPTY_PROBLEM_LIST); |
| 305 // process the request | 305 // process the request |
| 306 var params = new EditGetRefactoringParams.fromRequest(request); | 306 var params = new EditGetRefactoringParams.fromRequest(request); |
| 307 runZoned(() async { | 307 runZoned(() async { |
| 308 await _init(params.kind, params.file, params.offset, params.length); | 308 await _init(params.kind, params.file, params.offset, params.length); |
| 309 if (initStatus.hasFatalError) { | 309 if (initStatus.hasFatalError) { |
| 310 feedback = null; | 310 feedback = null; |
| 311 return _sendResultResponse(); | 311 _sendResultResponse(); |
| 312 return; | |
| 312 } | 313 } |
| 313 // set options | 314 // set options |
| 314 if (_requiresOptions) { | 315 if (_requiresOptions) { |
| 315 if (params.options == null) { | 316 if (params.options == null) { |
| 316 optionsStatus = new RefactoringStatus(); | 317 optionsStatus = new RefactoringStatus(); |
| 317 return _sendResultResponse(); | 318 _sendResultResponse(); |
| 319 return; | |
| 318 } | 320 } |
| 319 optionsStatus = _setOptions(params); | 321 optionsStatus = _setOptions(params); |
| 320 if (_hasFatalError) { | 322 if (_hasFatalError) { |
| 321 return _sendResultResponse(); | 323 _sendResultResponse(); |
| 324 return; | |
| 322 } | 325 } |
| 323 } | 326 } |
| 324 // done if just validation | 327 // done if just validation |
| 325 if (params.validateOnly) { | 328 if (params.validateOnly) { |
| 326 finalStatus = new RefactoringStatus(); | 329 finalStatus = new RefactoringStatus(); |
| 327 return _sendResultResponse(); | 330 _sendResultResponse(); |
| 331 return; | |
| 328 } | 332 } |
| 329 // simulate an exception | 333 // simulate an exception |
| 330 if (test_simulateRefactoringException_final) { | 334 if (test_simulateRefactoringException_final) { |
| 331 throw 'A simulated refactoring exception - final.'; | 335 throw 'A simulated refactoring exception - final.'; |
| 332 } | 336 } |
| 333 // validation and create change | 337 // validation and create change |
| 334 finalStatus = await refactoring.checkFinalConditions(); | 338 finalStatus = await refactoring.checkFinalConditions(); |
| 335 if (_hasFatalError) { | 339 if (_hasFatalError) { |
| 336 return _sendResultResponse(); | 340 _sendResultResponse(); |
| 341 return; | |
| 337 } | 342 } |
| 338 // simulate an exception | 343 // simulate an exception |
| 339 if (test_simulateRefactoringException_change) { | 344 if (test_simulateRefactoringException_change) { |
| 340 throw 'A simulated refactoring exception - change.'; | 345 throw 'A simulated refactoring exception - change.'; |
| 341 } | 346 } |
| 342 // create change | 347 // create change |
| 343 result.change = await refactoring.createChange(); | 348 result.change = await refactoring.createChange(); |
| 344 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); | 349 result.potentialEdits = nullIfEmpty(refactoring.potentialEditIds); |
| 345 _sendResultResponse(); | 350 _sendResultResponse(); |
| 346 }, onError: (exception, stackTrace) { | 351 }, onError: (exception, stackTrace) { |
| 347 server.instrumentationService.logException(exception, stackTrace); | 352 server.instrumentationService.logException(exception, stackTrace); |
| 348 server.sendResponse( | 353 server.sendResponse( |
| 349 new Response.serverError(request, exception, stackTrace)); | 354 new Response.serverError(request, exception, stackTrace)); |
| 350 _reset(); | 355 _reset(); |
| 351 }); | 356 }); |
| 352 } | 357 } |
| 353 | 358 |
| 354 /** | 359 /** |
| 355 * Initializes this context to perform a refactoring with the specified | 360 * Initializes this context to perform a refactoring with the specified |
| 356 * parameters. The existing [Refactoring] is reused or created as needed. | 361 * parameters. The existing [Refactoring] is reused or created as needed. |
| 357 */ | 362 */ |
| 358 _init(RefactoringKind kind, String file, | 363 Future _init(RefactoringKind kind, String file, |
| 359 int offset, int length) async { | 364 int offset, int length) async { |
| 360 await server.onAnalysisComplete; | 365 await server.onAnalysisComplete; |
| 361 // check if we can continue with the existing Refactoring instance | 366 // check if we can continue with the existing Refactoring instance |
| 362 if (this.kind == kind && | 367 if (this.kind == kind && |
| 363 this.file == file && | 368 this.file == file && |
| 364 this.offset == offset && | 369 this.offset == offset && |
| 365 this.length == length) { | 370 this.length == length) { |
| 366 return; | 371 return null; |
|
Paul Berry
2015/01/26 23:32:39
Aw, man, I didn't realize you would have to do thi
| |
| 367 } | 372 } |
| 368 _reset(); | 373 _reset(); |
| 369 this.kind = kind; | 374 this.kind = kind; |
| 370 this.file = file; | 375 this.file = file; |
| 371 this.offset = offset; | 376 this.offset = offset; |
| 372 this.length = length; | 377 this.length = length; |
| 373 // simulate an exception | 378 // simulate an exception |
| 374 if (test_simulateRefactoringException_init) { | 379 if (test_simulateRefactoringException_init) { |
| 375 throw 'A simulated refactoring exception - init.'; | 380 throw 'A simulated refactoring exception - init.'; |
| 376 } | 381 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 } | 458 } |
| 454 // do create the refactoring | 459 // do create the refactoring |
| 455 refactoring = new RenameRefactoring(searchEngine, element); | 460 refactoring = new RenameRefactoring(searchEngine, element); |
| 456 feedback = | 461 feedback = |
| 457 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); | 462 new RenameFeedback(node.offset, node.length, 'kind', 'oldName'); |
| 458 } | 463 } |
| 459 } | 464 } |
| 460 if (refactoring == null) { | 465 if (refactoring == null) { |
| 461 initStatus = | 466 initStatus = |
| 462 new RefactoringStatus.fatal('Unable to create a refactoring'); | 467 new RefactoringStatus.fatal('Unable to create a refactoring'); |
| 463 return; | 468 return null; |
| 464 } | 469 } |
| 465 // check initial conditions | 470 // check initial conditions |
| 466 initStatus = await refactoring.checkInitialConditions(); | 471 initStatus = await refactoring.checkInitialConditions(); |
| 467 if (refactoring is ExtractLocalRefactoring) { | 472 if (refactoring is ExtractLocalRefactoring) { |
| 468 ExtractLocalRefactoring refactoring = this.refactoring; | 473 ExtractLocalRefactoring refactoring = this.refactoring; |
| 469 ExtractLocalVariableFeedback feedback = this.feedback; | 474 ExtractLocalVariableFeedback feedback = this.feedback; |
| 470 feedback.names = refactoring.names; | 475 feedback.names = refactoring.names; |
| 471 feedback.offsets = refactoring.offsets; | 476 feedback.offsets = refactoring.offsets; |
| 472 feedback.lengths = refactoring.lengths; | 477 feedback.lengths = refactoring.lengths; |
| 473 } | 478 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 497 refactoring.isDeclaration, | 502 refactoring.isDeclaration, |
| 498 className: refactoring.className); | 503 className: refactoring.className); |
| 499 } | 504 } |
| 500 } | 505 } |
| 501 if (refactoring is RenameRefactoring) { | 506 if (refactoring is RenameRefactoring) { |
| 502 RenameRefactoring refactoring = this.refactoring; | 507 RenameRefactoring refactoring = this.refactoring; |
| 503 RenameFeedback feedback = this.feedback; | 508 RenameFeedback feedback = this.feedback; |
| 504 feedback.elementKindName = refactoring.elementKindName; | 509 feedback.elementKindName = refactoring.elementKindName; |
| 505 feedback.oldName = refactoring.oldName; | 510 feedback.oldName = refactoring.oldName; |
| 506 } | 511 } |
| 512 return null; | |
| 507 } | 513 } |
| 508 | 514 |
| 509 void _reset([engine.AnalysisContext context]) { | 515 void _reset([engine.AnalysisContext context]) { |
| 510 kind = null; | 516 kind = null; |
| 511 offset = null; | 517 offset = null; |
| 512 length = null; | 518 length = null; |
| 513 refactoring = null; | 519 refactoring = null; |
| 514 feedback = null; | 520 feedback = null; |
| 515 initStatus = new RefactoringStatus(); | 521 initStatus = new RefactoringStatus(); |
| 516 optionsStatus = new RefactoringStatus(); | 522 optionsStatus = new RefactoringStatus(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 } | 571 } |
| 566 if (refactoring is RenameRefactoring) { | 572 if (refactoring is RenameRefactoring) { |
| 567 RenameRefactoring renameRefactoring = refactoring; | 573 RenameRefactoring renameRefactoring = refactoring; |
| 568 RenameOptions renameOptions = params.options; | 574 RenameOptions renameOptions = params.options; |
| 569 renameRefactoring.newName = renameOptions.newName; | 575 renameRefactoring.newName = renameOptions.newName; |
| 570 return renameRefactoring.checkNewName(); | 576 return renameRefactoring.checkNewName(); |
| 571 } | 577 } |
| 572 return new RefactoringStatus(); | 578 return new RefactoringStatus(); |
| 573 } | 579 } |
| 574 } | 580 } |
| OLD | NEW |