Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: pkg/analysis_server/lib/src/services/refactoring/rename_import.dart

Issue 1059133003: Issue 23091. Fix for adding import prefix before string-interpolated identifier. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for identifier in curly brackets. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_import_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
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/naming_conventions.dart '; 12 import 'package:analysis_server/src/services/refactoring/naming_conventions.dart ';
13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da rt'; 14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da rt';
15 import 'package:analysis_server/src/services/refactoring/rename.dart'; 15 import 'package:analysis_server/src/services/refactoring/rename.dart';
16 import 'package:analysis_server/src/services/search/search_engine.dart'; 16 import 'package:analysis_server/src/services/search/search_engine.dart';
17 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/element.dart'; 18 import 'package:analyzer/src/generated/element.dart';
18 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
19 20
20 /** 21 /**
21 * A [Refactoring] for renaming [ImportElement]s. 22 * A [Refactoring] for renaming [ImportElement]s.
22 */ 23 */
23 class RenameImportRefactoringImpl extends RenameRefactoringImpl { 24 class RenameImportRefactoringImpl extends RenameRefactoringImpl {
24 RenameImportRefactoringImpl(SearchEngine searchEngine, ImportElement element) 25 RenameImportRefactoringImpl(SearchEngine searchEngine, ImportElement element)
25 : super(searchEngine, element); 26 : super(searchEngine, element);
26 27
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 70 }
70 if (edit != null) { 71 if (edit != null) {
71 doSourceChange_addElementEdit(change, element, edit); 72 doSourceChange_addElementEdit(change, element, edit);
72 } 73 }
73 } 74 }
74 // update references 75 // update references
75 List<SearchMatch> matches = await searchEngine.searchReferences(element); 76 List<SearchMatch> matches = await searchEngine.searchReferences(element);
76 List<SourceReference> references = getSourceReferences(matches); 77 List<SourceReference> references = getSourceReferences(matches);
77 for (SourceReference reference in references) { 78 for (SourceReference reference in references) {
78 if (newName.isEmpty) { 79 if (newName.isEmpty) {
79 reference.addEdit(change, newName); 80 reference.addEdit(change, '');
80 } else { 81 } else {
81 reference.addEdit(change, "${newName}."); 82 SimpleIdentifier interpolationIdentifier =
83 _getInterpolationIdentifier(reference);
84 if (interpolationIdentifier != null) {
85 doSourceChange_addElementEdit(change, reference.element,
86 new SourceEdit(interpolationIdentifier.offset,
87 interpolationIdentifier.length,
88 '{$newName.${interpolationIdentifier.name}}'));
89 } else {
90 reference.addEdit(change, '$newName.');
91 }
82 } 92 }
83 } 93 }
84 } 94 }
95
96 /**
97 * If the given [reference] is before an interpolated [SimpleIdentifier] in
98 * an [InterpolationExpression] without surrounding curly brackets, return it.
99 * Otherwise return `null`.
100 */
101 SimpleIdentifier _getInterpolationIdentifier(SourceReference reference) {
102 Source source = reference.element.source;
103 CompilationUnit unit = context.parseCompilationUnit(source);
104 NodeLocator nodeLocator = new NodeLocator.con1(reference.range.offset);
105 AstNode node = nodeLocator.searchWithin(unit);
106 if (node is SimpleIdentifier) {
107 AstNode parent = node.parent;
108 if (parent is InterpolationExpression && parent.rightBracket == null) {
109 return node;
110 }
111 }
112 return null;
113 }
85 } 114 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/rename_import_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698