| 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_class_member; | 5 library services.src.refactoring.rename_class_member; |
| 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/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
| 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 13 import 'package:analysis_server/src/services/search/hierarchy.dart'; | 13 import 'package:analysis_server/src/services/search/hierarchy.dart'; |
| 14 import 'package:analysis_server/src/services/search/search_engine.dart'; | 14 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 15 import 'package:analysis_server/src/services/correction/util.dart'; | 15 import 'package:analysis_server/src/services/correction/util.dart'; |
| 16 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; | 16 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart
'; |
| 17 import 'package:analysis_server/src/services/refactoring/rename.dart'; | 17 import 'package:analysis_server/src/services/refactoring/rename.dart'; |
| 18 import 'package:analyzer/src/generated/element.dart'; | 18 import 'package:analyzer/src/generated/element.dart'; |
| 19 import 'package:analyzer/src/generated/java_core.dart'; | 19 import 'package:analyzer/src/generated/java_core.dart'; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 RefactoringStatus result = new RefactoringStatus(); | 142 RefactoringStatus result = new RefactoringStatus(); |
| 143 ClassElement elementClass = element.enclosingElement; | 143 ClassElement elementClass = element.enclosingElement; |
| 144 // check if there is a member with "newName" in the same ClassElement | 144 // check if there is a member with "newName" in the same ClassElement |
| 145 for (Element newNameMember in getChildren(elementClass, newName)) { | 145 for (Element newNameMember in getChildren(elementClass, newName)) { |
| 146 result.addError( | 146 result.addError( |
| 147 format( | 147 format( |
| 148 "Class '{0}' already declares {1} with name '{2}'.", | 148 "Class '{0}' already declares {1} with name '{2}'.", |
| 149 elementClass.displayName, | 149 elementClass.displayName, |
| 150 getElementKindName(newNameMember), | 150 getElementKindName(newNameMember), |
| 151 newName), | 151 newName), |
| 152 createLocation_forElement(newNameMember)); | 152 new Location.forElement(newNameMember)); |
| 153 } | 153 } |
| 154 // do chained computations | 154 // do chained computations |
| 155 Set<ClassElement> superClasses = getSuperClasses(elementClass); | 155 Set<ClassElement> superClasses = getSuperClasses(elementClass); |
| 156 Set<ClassElement> subClasses; | 156 Set<ClassElement> subClasses; |
| 157 return _prepareReferences().then((_) { | 157 return _prepareReferences().then((_) { |
| 158 return getSubClasses(searchEngine, elementClass).then((_subs) { | 158 return getSubClasses(searchEngine, elementClass).then((_subs) { |
| 159 subClasses = _subs; | 159 subClasses = _subs; |
| 160 }); | 160 }); |
| 161 }).then((_) { | 161 }).then((_) { |
| 162 // check shadowing in hierarchy | 162 // check shadowing in hierarchy |
| 163 return searchEngine.searchElementDeclarations(newName).then((decls) { | 163 return searchEngine.searchElementDeclarations(newName).then((decls) { |
| 164 for (SearchMatch decl in decls) { | 164 for (SearchMatch decl in decls) { |
| 165 Element nameElement = getSyntheticAccessorVariable(decl.element); | 165 Element nameElement = getSyntheticAccessorVariable(decl.element); |
| 166 Element nameClass = nameElement.enclosingElement; | 166 Element nameClass = nameElement.enclosingElement; |
| 167 // renamed Element shadows member of superclass | 167 // renamed Element shadows member of superclass |
| 168 if (superClasses.contains(nameClass)) { | 168 if (superClasses.contains(nameClass)) { |
| 169 result.addError( | 169 result.addError( |
| 170 format( | 170 format( |
| 171 "Renamed {0} will shadow {1} '{2}'.", | 171 "Renamed {0} will shadow {1} '{2}'.", |
| 172 getElementKindName(element), | 172 getElementKindName(element), |
| 173 getElementKindName(nameElement), | 173 getElementKindName(nameElement), |
| 174 getElementQualifiedName(nameElement)), | 174 getElementQualifiedName(nameElement)), |
| 175 createLocation_forElement(nameElement)); | 175 new Location.forElement(nameElement)); |
| 176 } | 176 } |
| 177 // renamed Element is shadowed by member of subclass | 177 // renamed Element is shadowed by member of subclass |
| 178 if (subClasses.contains(nameClass)) { | 178 if (subClasses.contains(nameClass)) { |
| 179 result.addError( | 179 result.addError( |
| 180 format( | 180 format( |
| 181 "Renamed {0} will be shadowed by {1} '{2}'.", | 181 "Renamed {0} will be shadowed by {1} '{2}'.", |
| 182 getElementKindName(element), | 182 getElementKindName(element), |
| 183 getElementKindName(nameElement), | 183 getElementKindName(nameElement), |
| 184 getElementQualifiedName(nameElement)), | 184 getElementQualifiedName(nameElement)), |
| 185 createLocation_forElement(nameElement)); | 185 new Location.forElement(nameElement)); |
| 186 } | 186 } |
| 187 // renamed Element is shadowed by local | 187 // renamed Element is shadowed by local |
| 188 if (nameElement is LocalElement) { | 188 if (nameElement is LocalElement) { |
| 189 LocalElement localElement = nameElement; | 189 LocalElement localElement = nameElement; |
| 190 ClassElement enclosingClass = | 190 ClassElement enclosingClass = |
| 191 nameElement.getAncestor((element) => element is ClassElement); | 191 nameElement.getAncestor((element) => element is ClassElement); |
| 192 if (enclosingClass == elementClass || | 192 if (enclosingClass == elementClass || |
| 193 subClasses.contains(enclosingClass)) { | 193 subClasses.contains(enclosingClass)) { |
| 194 for (SearchMatch reference in references) { | 194 for (SearchMatch reference in references) { |
| 195 if (isReferenceInLocalRange(localElement, reference)) { | 195 if (isReferenceInLocalRange(localElement, reference)) { |
| 196 result.addError( | 196 result.addError( |
| 197 format( | 197 format( |
| 198 "Usage of renamed {0} will be shadowed by {1} '{2}'.", | 198 "Usage of renamed {0} will be shadowed by {1} '{2}'.", |
| 199 getElementKindName(element), | 199 getElementKindName(element), |
| 200 getElementKindName(localElement), | 200 getElementKindName(localElement), |
| 201 localElement.displayName), | 201 localElement.displayName), |
| 202 createLocation_forMatch(reference)); | 202 new Location.forMatch(reference)); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 }); | 208 }); |
| 209 }).then((_) => result); | 209 }).then((_) => result); |
| 210 } | 210 } |
| 211 | 211 |
| 212 /** | 212 /** |
| (...skipping 18 matching lines...) Expand all Loading... |
| 231 Future _prepareReferences() { | 231 Future _prepareReferences() { |
| 232 return _prepareElements().then((_) { | 232 return _prepareElements().then((_) { |
| 233 return Future.forEach(elements, (Element element) { | 233 return Future.forEach(elements, (Element element) { |
| 234 return searchEngine.searchReferences(element).then((references) { | 234 return searchEngine.searchReferences(element).then((references) { |
| 235 this.references.addAll(references); | 235 this.references.addAll(references); |
| 236 }); | 236 }); |
| 237 }); | 237 }); |
| 238 }); | 238 }); |
| 239 } | 239 } |
| 240 } | 240 } |
| OLD | NEW |