| 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_unit_member; | 5 library services.src.refactoring.rename_unit_member; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' show Location, SourceChange; | 9 import 'package:analysis_server/src/protocol_server.dart' show |
| 10 newLocation_fromElement, newLocation_fromMatch; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
| 11 import 'package:analysis_server/src/services/correction/util.dart'; | 12 import 'package:analysis_server/src/services/correction/util.dart'; |
| 12 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; | 13 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; |
| 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 14 import 'package:analysis_server/src/services/refactoring/rename.dart'; | 15 import 'package:analysis_server/src/services/refactoring/rename.dart'; |
| 15 import 'package:analysis_server/src/services/search/element_visitors.dart'; | 16 import 'package:analysis_server/src/services/search/element_visitors.dart'; |
| 16 import 'package:analysis_server/src/services/search/search_engine.dart'; | 17 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 17 import 'package:analyzer/src/generated/element.dart'; | 18 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/java_core.dart'; | 19 import 'package:analyzer/src/generated/java_core.dart'; |
| 19 | 20 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ClassElement refClass = | 194 ClassElement refClass = |
| 194 refElement.getAncestor((e) => e is ClassElement); | 195 refElement.getAncestor((e) => e is ClassElement); |
| 195 if (refClass != null) { | 196 if (refClass != null) { |
| 196 visitChildren(refClass, (shadow) { | 197 visitChildren(refClass, (shadow) { |
| 197 if (hasDisplayName(shadow, name)) { | 198 if (hasDisplayName(shadow, name)) { |
| 198 String message = format( | 199 String message = format( |
| 199 "Reference to renamed {0} will be shadowed by {1} '{2}'.", | 200 "Reference to renamed {0} will be shadowed by {1} '{2}'.", |
| 200 getElementKindName(element), | 201 getElementKindName(element), |
| 201 getElementKindName(shadow), | 202 getElementKindName(shadow), |
| 202 getElementQualifiedName(shadow)); | 203 getElementQualifiedName(shadow)); |
| 203 result.addError(message, new Location.fromElement(shadow)); | 204 result.addError(message, newLocation_fromElement(shadow)); |
| 204 } | 205 } |
| 205 }); | 206 }); |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 }); | 209 }); |
| 209 } | 210 } |
| 210 | 211 |
| 211 /** | 212 /** |
| 212 * Validates if [element] renamed to [name] will conflict with another | 213 * Validates if [element] renamed to [name] will conflict with another |
| 213 * top-level [Element] in the same library. | 214 * top-level [Element] in the same library. |
| 214 */ | 215 */ |
| 215 void _validateWillConflict() { | 216 void _validateWillConflict() { |
| 216 visitLibraryTopLevelElements(library, (element) { | 217 visitLibraryTopLevelElements(library, (element) { |
| 217 if (hasDisplayName(element, name)) { | 218 if (hasDisplayName(element, name)) { |
| 218 String message = format( | 219 String message = format( |
| 219 "Library already declares {0} with name '{1}'.", | 220 "Library already declares {0} with name '{1}'.", |
| 220 getElementKindName(element), | 221 getElementKindName(element), |
| 221 name); | 222 name); |
| 222 result.addError(message, new Location.fromElement(element)); | 223 result.addError(message, newLocation_fromElement(element)); |
| 223 } | 224 } |
| 224 }); | 225 }); |
| 225 } | 226 } |
| 226 | 227 |
| 227 /** | 228 /** |
| 228 * Validates if renamed [element] will shadow any [Element] named [name]. | 229 * Validates if renamed [element] will shadow any [Element] named [name]. |
| 229 */ | 230 */ |
| 230 Future _validateWillShadow() { | 231 Future _validateWillShadow() { |
| 231 return searchEngine.searchMemberDeclarations(name).then((declarations) { | 232 return searchEngine.searchMemberDeclarations(name).then((declarations) { |
| 232 return Future.forEach(declarations, (SearchMatch declaration) { | 233 return Future.forEach(declarations, (SearchMatch declaration) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 250 continue; | 251 continue; |
| 251 } | 252 } |
| 252 // OK, reference will be shadowed be the element being renamed | 253 // OK, reference will be shadowed be the element being renamed |
| 253 String message = format( | 254 String message = format( |
| 254 isRename ? | 255 isRename ? |
| 255 "Renamed {0} will shadow {1} '{2}'." : | 256 "Renamed {0} will shadow {1} '{2}'." : |
| 256 "Created {0} will shadow {1} '{2}'.", | 257 "Created {0} will shadow {1} '{2}'.", |
| 257 elementKind.displayName, | 258 elementKind.displayName, |
| 258 getElementKindName(member), | 259 getElementKindName(member), |
| 259 getElementQualifiedName(member)); | 260 getElementQualifiedName(member)); |
| 260 result.addError(message, new Location.fromMatch(memberReference)); | 261 result.addError(message, newLocation_fromMatch(memberReference)); |
| 261 } | 262 } |
| 262 }); | 263 }); |
| 263 }); | 264 }); |
| 264 }); | 265 }); |
| 265 } | 266 } |
| 266 } | 267 } |
| OLD | NEW |