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

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

Issue 1010803003: Issue 22757. Update self references on package rename. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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/move_file_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.move_file; 5 library services.src.refactoring.move_file;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' hide Element; 9 import 'package:analysis_server/src/protocol_server.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/status.dart'; 10 import 'package:analysis_server/src/services/correction/status.dart';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 String newUri = _computeNewUri(reference); 126 String newUri = _computeNewUri(reference);
127 reference.addEdit(change, "'$newUri'"); 127 reference.addEdit(change, "'$newUri'");
128 } 128 }
129 } 129 }
130 }); 130 });
131 return change; 131 return change;
132 } 132 }
133 133
134 Future<SourceChange> _createProjectChange( 134 Future<SourceChange> _createProjectChange(
135 Folder project, File pubspecFile) async { 135 Folder project, File pubspecFile) async {
136 // prepare "name" field value location 136 change = new SourceChange('Rename project');
137 SourceSpan nameSpan; 137 String oldPackageName = pathContext.basename(oldFile);
138 String newPackageName = pathContext.basename(newFile);
139 // add pubspec.yaml change
138 { 140 {
139 String pubspecString = pubspecFile.readAsStringSync(); 141 // prepare "name" field value location
140 YamlMap pubspecNode = loadYamlNode(pubspecString); 142 SourceSpan nameSpan;
141 YamlNode nameNode = pubspecNode.nodes['name']; 143 {
142 nameSpan = nameNode.span; 144 String pubspecString = pubspecFile.readAsStringSync();
145 YamlMap pubspecNode = loadYamlNode(pubspecString);
146 YamlNode nameNode = pubspecNode.nodes['name'];
147 nameSpan = nameNode.span;
148 }
149 int nameOffset = nameSpan.start.offset;
150 int nameLength = nameSpan.length;
151 // add edit
152 change.addEdit(pubspecFile.path, pubspecFile.modificationStamp,
153 new SourceEdit(nameOffset, nameLength, newPackageName));
143 } 154 }
144 int nameOffset = nameSpan.start.offset; 155 // check all local libraries
145 int nameLength = nameSpan.length; 156 for (Source librarySource in context.librarySources) {
146 // create Change 157 // should be a local library
147 change = new SourceChange('Rename project'); 158 if (!project.contains(librarySource.fullName)) {
148 String newPackageName = pathContext.basename(newFile); 159 continue;
149 change.addEdit(pubspecFile.path, pubspecFile.modificationStamp, 160 }
150 new SourceEdit(nameOffset, nameLength, newPackageName)); 161 // we need LibraryElement
162 LibraryElement library = context.getLibraryElement(librarySource);
163 if (library == null) {
164 continue;
165 }
166 // update all imports
167 updateUriElements(List<UriReferencedElement> uriElements) {
168 for (UriReferencedElement element in uriElements) {
169 String uri = element.uri;
170 if (uri != null) {
171 String oldPrefix = 'package:$oldPackageName/';
172 if (uri.startsWith(oldPrefix)) {
173 doSourceChange_addElementEdit(change, library, new SourceEdit(
174 element.uriOffset + 1, oldPrefix.length,
175 'package:$newPackageName/'));
176 }
177 }
178 }
179 }
180 updateUriElements(library.imports);
181 updateUriElements(library.exports);
182 }
183 // done
151 return change; 184 return change;
152 } 185 }
153 186
154 String _getRelativeUri(String path, String from) { 187 String _getRelativeUri(String path, String from) {
155 String uri = pathContext.relative(path, from: from); 188 String uri = pathContext.relative(path, from: from);
156 List<String> parts = pathContext.split(uri); 189 List<String> parts = pathContext.split(uri);
157 return pathos.posix.joinAll(parts); 190 return pathos.posix.joinAll(parts);
158 } 191 }
159 192
160 bool _isPackageReference(SourceReference reference) { 193 bool _isPackageReference(SourceReference reference) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 230 }
198 } 231 }
199 } 232 }
200 233
201 void _updateUriReferences(List<UriReferencedElement> elements) { 234 void _updateUriReferences(List<UriReferencedElement> elements) {
202 for (UriReferencedElement element in elements) { 235 for (UriReferencedElement element in elements) {
203 _updateUriReference(element); 236 _updateUriReference(element);
204 } 237 }
205 } 238 }
206 } 239 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/move_file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698