| 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 services.src.refactoring.extract_local; | 5 library services.src.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol2.dart' show SourceEdit; | 9 import 'package:analysis_server/src/protocol2.dart' show Location, SourceEdit; |
| 10 import 'package:analysis_server/src/services/correction/change.dart'; | 10 import 'package:analysis_server/src/services/correction/change.dart'; |
| 11 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; | 11 import 'package:analysis_server/src/services/correction/name_suggestion.dart'; |
| 12 import 'package:analysis_server/src/services/correction/selection_analyzer.dart'
; | 12 import 'package:analysis_server/src/services/correction/selection_analyzer.dart'
; |
| 13 import 'package:analysis_server/src/services/correction/source_range.dart'; | 13 import 'package:analysis_server/src/services/correction/source_range.dart'; |
| 14 import 'package:analysis_server/src/services/correction/status.dart'; | 14 import 'package:analysis_server/src/services/correction/status.dart'; |
| 15 import 'package:analysis_server/src/services/correction/strings.dart'; | 15 import 'package:analysis_server/src/services/correction/strings.dart'; |
| 16 import 'package:analysis_server/src/services/correction/util.dart'; | 16 import 'package:analysis_server/src/services/correction/util.dart'; |
| 17 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; | 17 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; |
| 18 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 18 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 19 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; | 19 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 _invalidSelection(message, null); | 376 _invalidSelection(message, null); |
| 377 } | 377 } |
| 378 | 378 |
| 379 @override | 379 @override |
| 380 Object visitAssignmentExpression(AssignmentExpression node) { | 380 Object visitAssignmentExpression(AssignmentExpression node) { |
| 381 super.visitAssignmentExpression(node); | 381 super.visitAssignmentExpression(node); |
| 382 Expression lhs = node.leftHandSide; | 382 Expression lhs = node.leftHandSide; |
| 383 if (_isFirstSelectedNode(lhs)) { | 383 if (_isFirstSelectedNode(lhs)) { |
| 384 _invalidSelection( | 384 _invalidSelection( |
| 385 'Cannot extract the left-hand side of an assignment.', | 385 'Cannot extract the left-hand side of an assignment.', |
| 386 new RefactoringStatusContext.forNode(lhs)); | 386 createLocation_forNode(lhs)); |
| 387 } | 387 } |
| 388 return null; | 388 return null; |
| 389 } | 389 } |
| 390 | 390 |
| 391 @override | 391 @override |
| 392 Object visitSimpleIdentifier(SimpleIdentifier node) { | 392 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 393 super.visitSimpleIdentifier(node); | 393 super.visitSimpleIdentifier(node); |
| 394 if (_isFirstSelectedNode(node)) { | 394 if (_isFirstSelectedNode(node)) { |
| 395 // name of declaration | 395 // name of declaration |
| 396 if (node.inDeclarationContext()) { | 396 if (node.inDeclarationContext()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 407 invalidSelection('Cannot extract name part of a property access.'); | 407 invalidSelection('Cannot extract name part of a property access.'); |
| 408 } | 408 } |
| 409 if (parent is PropertyAccess && identical(parent.propertyName, node)) { | 409 if (parent is PropertyAccess && identical(parent.propertyName, node)) { |
| 410 invalidSelection('Cannot extract name part of a property access.'); | 410 invalidSelection('Cannot extract name part of a property access.'); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 return null; | 413 return null; |
| 414 } | 414 } |
| 415 | 415 |
| 416 /** | 416 /** |
| 417 * Records fatal error with given message and [RefactoringStatusContext]. | 417 * Records fatal error with given message and [Locatiom]. |
| 418 */ | 418 */ |
| 419 void _invalidSelection(String message, RefactoringStatusContext context) { | 419 void _invalidSelection(String message, Location location) { |
| 420 status.addFatalError(message, context); | 420 status.addFatalError(message, location); |
| 421 reset(); | 421 reset(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool _isFirstSelectedNode(AstNode node) => node == firstSelectedNode; | 424 bool _isFirstSelectedNode(AstNode node) => node == firstSelectedNode; |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 class _HasStatementVisitor extends GeneralizingAstVisitor { | 428 class _HasStatementVisitor extends GeneralizingAstVisitor { |
| 429 final List<bool> result; | 429 final List<bool> result; |
| 430 | 430 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 Token startToken = nodeTokens[startTokenIndex]; | 529 Token startToken = nodeTokens[startTokenIndex]; |
| 530 Token endToken = nodeTokens[endTokenIndex]; | 530 Token endToken = nodeTokens[endTokenIndex]; |
| 531 // add occurrence range | 531 // add occurrence range |
| 532 int occuStart = nodeOffset + startToken.offset; | 532 int occuStart = nodeOffset + startToken.offset; |
| 533 int occuEnd = nodeOffset + endToken.end; | 533 int occuEnd = nodeOffset + endToken.end; |
| 534 SourceRange occuRange = rangeStartEnd(occuStart, occuEnd); | 534 SourceRange occuRange = rangeStartEnd(occuStart, occuEnd); |
| 535 _addOccurrence(occuRange); | 535 _addOccurrence(occuRange); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 } | 538 } |
| OLD | NEW |