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_import; | 5 library services.src.refactoring.rename_import; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/protocol_server.dart'; | 9 import 'package:analysis_server/src/protocol_server.dart'; |
10 import 'package:analysis_server/src/services/correction/source_range.dart'; | 10 import 'package:analysis_server/src/services/correction/source_range.dart'; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // update references | 75 // update references |
76 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 76 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
77 List<SourceReference> references = getSourceReferences(matches); | 77 List<SourceReference> references = getSourceReferences(matches); |
78 for (SourceReference reference in references) { | 78 for (SourceReference reference in references) { |
79 if (newName.isEmpty) { | 79 if (newName.isEmpty) { |
80 reference.addEdit(change, ''); | 80 reference.addEdit(change, ''); |
81 } else { | 81 } else { |
82 SimpleIdentifier interpolationIdentifier = | 82 SimpleIdentifier interpolationIdentifier = |
83 _getInterpolationIdentifier(reference); | 83 _getInterpolationIdentifier(reference); |
84 if (interpolationIdentifier != null) { | 84 if (interpolationIdentifier != null) { |
85 doSourceChange_addElementEdit(change, reference.element, | 85 doSourceChange_addElementEdit( |
86 new SourceEdit(interpolationIdentifier.offset, | 86 change, |
| 87 reference.element, |
| 88 new SourceEdit( |
| 89 interpolationIdentifier.offset, |
87 interpolationIdentifier.length, | 90 interpolationIdentifier.length, |
88 '{$newName.${interpolationIdentifier.name}}')); | 91 '{$newName.${interpolationIdentifier.name}}')); |
89 } else { | 92 } else { |
90 reference.addEdit(change, '$newName.'); | 93 reference.addEdit(change, '$newName.'); |
91 } | 94 } |
92 } | 95 } |
93 } | 96 } |
94 } | 97 } |
95 | 98 |
96 /** | 99 /** |
97 * If the given [reference] is before an interpolated [SimpleIdentifier] in | 100 * If the given [reference] is before an interpolated [SimpleIdentifier] in |
98 * an [InterpolationExpression] without surrounding curly brackets, return it. | 101 * an [InterpolationExpression] without surrounding curly brackets, return it. |
99 * Otherwise return `null`. | 102 * Otherwise return `null`. |
100 */ | 103 */ |
101 SimpleIdentifier _getInterpolationIdentifier(SourceReference reference) { | 104 SimpleIdentifier _getInterpolationIdentifier(SourceReference reference) { |
102 Source source = reference.element.source; | 105 Source source = reference.element.source; |
103 CompilationUnit unit = context.parseCompilationUnit(source); | 106 CompilationUnit unit = context.parseCompilationUnit(source); |
104 NodeLocator nodeLocator = new NodeLocator(reference.range.offset); | 107 NodeLocator nodeLocator = new NodeLocator(reference.range.offset); |
105 AstNode node = nodeLocator.searchWithin(unit); | 108 AstNode node = nodeLocator.searchWithin(unit); |
106 if (node is SimpleIdentifier) { | 109 if (node is SimpleIdentifier) { |
107 AstNode parent = node.parent; | 110 AstNode parent = node.parent; |
108 if (parent is InterpolationExpression && parent.rightBracket == null) { | 111 if (parent is InterpolationExpression && parent.rightBracket == null) { |
109 return node; | 112 return node; |
110 } | 113 } |
111 } | 114 } |
112 return null; | 115 return null; |
113 } | 116 } |
114 } | 117 } |
OLD | NEW |