| 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.rename_local; | 5 library services.src.refactoring.rename_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol2.dart' show Location; |
| 9 import 'package:analysis_server/src/services/correction/change.dart'; | 10 import 'package:analysis_server/src/services/correction/change.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
| 12 import 'package:analysis_server/src/services/correction/util.dart'; |
| 13 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; |
| 11 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 15 import 'package:analysis_server/src/services/refactoring/rename.dart'; |
| 12 import 'package:analysis_server/src/services/search/hierarchy.dart'; | 16 import 'package:analysis_server/src/services/search/hierarchy.dart'; |
| 13 import 'package:analysis_server/src/services/search/search_engine.dart'; | 17 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 14 import 'package:analysis_server/src/services/correction/util.dart'; | |
| 15 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; | |
| 16 import 'package:analysis_server/src/services/refactoring/rename.dart'; | |
| 17 import 'package:analyzer/src/generated/ast.dart'; | 18 import 'package:analyzer/src/generated/ast.dart'; |
| 18 import 'package:analyzer/src/generated/element.dart'; | 19 import 'package:analyzer/src/generated/element.dart'; |
| 19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 20 | 21 |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * A [Refactoring] for renaming [LocalElement]s. | 24 * A [Refactoring] for renaming [LocalElement]s. |
| 24 */ | 25 */ |
| 25 class RenameLocalRefactoringImpl extends RenameRefactoringImpl { | 26 class RenameLocalRefactoringImpl extends RenameRefactoringImpl { |
| 26 RenameLocalRefactoringImpl(SearchEngine searchEngine, LocalElement element) | 27 RenameLocalRefactoringImpl(SearchEngine searchEngine, LocalElement element) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 113 |
| 113 @override | 114 @override |
| 114 Object visitSimpleIdentifier(SimpleIdentifier node) { | 115 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 115 Element nodeElement = node.bestElement; | 116 Element nodeElement = node.bestElement; |
| 116 String newName = refactoring.newName; | 117 String newName = refactoring.newName; |
| 117 if (nodeElement != null && nodeElement.name == newName) { | 118 if (nodeElement != null && nodeElement.name == newName) { |
| 118 // duplicate declaration | 119 // duplicate declaration |
| 119 if (haveIntersectingRanges(refactoring.element, nodeElement)) { | 120 if (haveIntersectingRanges(refactoring.element, nodeElement)) { |
| 120 String nodeKind = nodeElement.kind.displayName; | 121 String nodeKind = nodeElement.kind.displayName; |
| 121 String message = "Duplicate ${nodeKind} '$newName'."; | 122 String message = "Duplicate ${nodeKind} '$newName'."; |
| 122 result.addError( | 123 result.addError(message, new Location.fromElement(nodeElement)); |
| 123 message, | |
| 124 createLocation_forElement(nodeElement)); | |
| 125 return null; | 124 return null; |
| 126 } | 125 } |
| 127 // shadowing referenced element | 126 // shadowing referenced element |
| 128 if (elementRange.contains(node.offset) && !node.isQualified) { | 127 if (elementRange.contains(node.offset) && !node.isQualified) { |
| 129 nodeElement = getSyntheticAccessorVariable(nodeElement); | 128 nodeElement = getSyntheticAccessorVariable(nodeElement); |
| 130 String nodeKind = nodeElement.kind.displayName; | 129 String nodeKind = nodeElement.kind.displayName; |
| 131 String nodeName = getElementQualifiedName(nodeElement); | 130 String nodeName = getElementQualifiedName(nodeElement); |
| 132 String nameElementSourceName = nodeElement.source.shortName; | 131 String nameElementSourceName = nodeElement.source.shortName; |
| 133 String refKind = refactoring.element.kind.displayName; | 132 String refKind = refactoring.element.kind.displayName; |
| 134 String message = | 133 String message = |
| 135 'Usage of $nodeKind "$nodeName" declared in ' | 134 'Usage of $nodeKind "$nodeName" declared in ' |
| 136 '"$nameElementSourceName" will be shadowed by renamed $refKind.'
; | 135 '"$nameElementSourceName" will be shadowed by renamed $refKind.'
; |
| 137 result.addError(message, createLocation_forNode(node)); | 136 result.addError(message, new Location.fromNode(node)); |
| 138 } | 137 } |
| 139 } | 138 } |
| 140 return null; | 139 return null; |
| 141 } | 140 } |
| 142 } | 141 } |
| OLD | NEW |