| 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.dart' show Location, SourceChange; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (element is FunctionTypeAliasElement) { | 88 if (element is FunctionTypeAliasElement) { |
| 89 result.addStatus(validateFunctionTypeAliasName(newName)); | 89 result.addStatus(validateFunctionTypeAliasName(newName)); |
| 90 } | 90 } |
| 91 if (element is ClassElement) { | 91 if (element is ClassElement) { |
| 92 result.addStatus(validateClassName(newName)); | 92 result.addStatus(validateClassName(newName)); |
| 93 } | 93 } |
| 94 return result; | 94 return result; |
| 95 } | 95 } |
| 96 | 96 |
| 97 @override | 97 @override |
| 98 Future<SourceChange> createChange() { | 98 Future fillChange() { |
| 99 SourceChange change = new SourceChange(refactoringName); | |
| 100 // prepare elements | 99 // prepare elements |
| 101 List<Element> elements = []; | 100 List<Element> elements = []; |
| 102 if (element is PropertyInducingElement && element.isSynthetic) { | 101 if (element is PropertyInducingElement && element.isSynthetic) { |
| 103 PropertyInducingElement property = element as PropertyInducingElement; | 102 PropertyInducingElement property = element as PropertyInducingElement; |
| 104 PropertyAccessorElement getter = property.getter; | 103 PropertyAccessorElement getter = property.getter; |
| 105 PropertyAccessorElement setter = property.setter; | 104 PropertyAccessorElement setter = property.setter; |
| 106 if (getter != null) { | 105 if (getter != null) { |
| 107 elements.add(getter); | 106 elements.add(getter); |
| 108 } | 107 } |
| 109 if (setter != null) { | 108 if (setter != null) { |
| 110 elements.add(setter); | 109 elements.add(setter); |
| 111 } | 110 } |
| 112 } else { | 111 } else { |
| 113 elements.add(element); | 112 elements.add(element); |
| 114 } | 113 } |
| 115 // update each element | 114 // update each element |
| 116 return Future.forEach(elements, (Element element) { | 115 return Future.forEach(elements, (Element element) { |
| 117 // update declaration | 116 addDeclarationEdit(element); |
| 118 addDeclarationEdit(change, element); | 117 return searchEngine.searchReferences(element).then(addReferenceEdits); |
| 119 // schedule updating references | |
| 120 return searchEngine.searchReferences(element).then((refMatches) { | |
| 121 List<SourceReference> references = getSourceReferences(refMatches); | |
| 122 for (SourceReference reference in references) { | |
| 123 addReferenceEdit(change, reference); | |
| 124 } | |
| 125 }); | |
| 126 }).then((_) { | |
| 127 return change; | |
| 128 }); | 118 }); |
| 129 } | 119 } |
| 130 } | 120 } |
| 131 | 121 |
| 132 | 122 |
| 133 /** | 123 /** |
| 134 * Helper to check if the created or renamed [Element] will cause any conflicts. | 124 * Helper to check if the created or renamed [Element] will cause any conflicts. |
| 135 */ | 125 */ |
| 136 class _RenameUnitMemberValidator { | 126 class _RenameUnitMemberValidator { |
| 137 final SearchEngine searchEngine; | 127 final SearchEngine searchEngine; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 elementKind.displayName, | 257 elementKind.displayName, |
| 268 getElementKindName(member), | 258 getElementKindName(member), |
| 269 getElementQualifiedName(member)); | 259 getElementQualifiedName(member)); |
| 270 result.addError(message, new Location.fromMatch(memberReference)); | 260 result.addError(message, new Location.fromMatch(memberReference)); |
| 271 } | 261 } |
| 272 }); | 262 }); |
| 273 }); | 263 }); |
| 274 }); | 264 }); |
| 275 } | 265 } |
| 276 } | 266 } |
| OLD | NEW |