Chromium Code Reviews| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol_server.dart'; | 7 import 'package:analysis_server/src/protocol_server.dart'; |
| 8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
| 9 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart '; | 9 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart '; |
| 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 // update references | 80 // update references |
| 81 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 81 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
| 82 List<SourceReference> references = getSourceReferences(matches); | 82 List<SourceReference> references = getSourceReferences(matches); |
| 83 for (SourceReference reference in references) { | 83 for (SourceReference reference in references) { |
| 84 if (newName.isEmpty) { | 84 if (newName.isEmpty) { |
| 85 reference.addEdit(change, ''); | 85 reference.addEdit(change, ''); |
| 86 } else { | 86 } else { |
| 87 SimpleIdentifier interpolationIdentifier = | 87 SimpleIdentifier interpolationIdentifier = |
| 88 _getInterpolationIdentifier(reference); | 88 await _getInterpolationIdentifier(reference); |
| 89 if (interpolationIdentifier != null) { | 89 if (interpolationIdentifier != null) { |
| 90 doSourceChange_addElementEdit( | 90 doSourceChange_addElementEdit( |
| 91 change, | 91 change, |
| 92 reference.element, | 92 reference.element, |
| 93 new SourceEdit( | 93 new SourceEdit( |
| 94 interpolationIdentifier.offset, | 94 interpolationIdentifier.offset, |
| 95 interpolationIdentifier.length, | 95 interpolationIdentifier.length, |
| 96 '{$newName.${interpolationIdentifier.name}}')); | 96 '{$newName.${interpolationIdentifier.name}}')); |
| 97 } else { | 97 } else { |
| 98 reference.addEdit(change, '$newName.'); | 98 reference.addEdit(change, '$newName.'); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 109 CompilationUnit unit = await astProvider.getParsedUnitForElement(library); | 109 CompilationUnit unit = await astProvider.getParsedUnitForElement(library); |
| 110 int index = library.imports.indexOf(element); | 110 int index = library.imports.indexOf(element); |
| 111 return unit.directives.where((d) => d is ImportDirective).toList()[index]; | 111 return unit.directives.where((d) => d is ImportDirective).toList()[index]; |
| 112 } | 112 } |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * If the given [reference] is before an interpolated [SimpleIdentifier] in | 115 * If the given [reference] is before an interpolated [SimpleIdentifier] in |
| 116 * an [InterpolationExpression] without surrounding curly brackets, return it. | 116 * an [InterpolationExpression] without surrounding curly brackets, return it. |
| 117 * Otherwise return `null`. | 117 * Otherwise return `null`. |
| 118 */ | 118 */ |
| 119 SimpleIdentifier _getInterpolationIdentifier(SourceReference reference) { | 119 Future<SimpleIdentifier> _getInterpolationIdentifier( |
| 120 SourceReference reference) async { | |
| 120 Source source = reference.element.source; | 121 Source source = reference.element.source; |
| 121 CompilationUnit unit = context.parseCompilationUnit(source); | 122 CompilationUnit unit = |
| 123 (await astProvider.driver.currentSession.getParsedAst(source.fullName)) | |
|
scheglov
2017/08/23 19:27:28
Ideally I would prefer to put each `await` into a
Brian Wilkerson
2017/08/23 19:56:52
Done
| |
| 124 .unit; | |
| 122 NodeLocator nodeLocator = new NodeLocator(reference.range.offset); | 125 NodeLocator nodeLocator = new NodeLocator(reference.range.offset); |
| 123 AstNode node = nodeLocator.searchWithin(unit); | 126 AstNode node = nodeLocator.searchWithin(unit); |
| 124 if (node is SimpleIdentifier) { | 127 if (node is SimpleIdentifier) { |
| 125 AstNode parent = node.parent; | 128 AstNode parent = node.parent; |
| 126 if (parent is InterpolationExpression && parent.rightBracket == null) { | 129 if (parent is InterpolationExpression && parent.rightBracket == null) { |
| 127 return node; | 130 return node; |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 return null; | 133 return null; |
| 131 } | 134 } |
| 132 } | 135 } |
| OLD | NEW |