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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/refactoring/move_file_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/refactoring/move_file.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/move_file.dart b/pkg/analysis_server/lib/src/services/refactoring/move_file.dart
index 6547d184f576d75963dd2306ddf3e8c1f3e0b200..3f24fa942f121814a79c1b8909c53ede0241756b 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/move_file.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/move_file.dart
@@ -133,21 +133,54 @@ class MoveFileRefactoringImpl extends RefactoringImpl
Future<SourceChange> _createProjectChange(
Folder project, File pubspecFile) async {
- // prepare "name" field value location
- SourceSpan nameSpan;
- {
- String pubspecString = pubspecFile.readAsStringSync();
- YamlMap pubspecNode = loadYamlNode(pubspecString);
- YamlNode nameNode = pubspecNode.nodes['name'];
- nameSpan = nameNode.span;
- }
- int nameOffset = nameSpan.start.offset;
- int nameLength = nameSpan.length;
- // create Change
change = new SourceChange('Rename project');
+ String oldPackageName = pathContext.basename(oldFile);
String newPackageName = pathContext.basename(newFile);
- change.addEdit(pubspecFile.path, pubspecFile.modificationStamp,
- new SourceEdit(nameOffset, nameLength, newPackageName));
+ // add pubspec.yaml change
+ {
+ // prepare "name" field value location
+ SourceSpan nameSpan;
+ {
+ String pubspecString = pubspecFile.readAsStringSync();
+ YamlMap pubspecNode = loadYamlNode(pubspecString);
+ YamlNode nameNode = pubspecNode.nodes['name'];
+ nameSpan = nameNode.span;
+ }
+ int nameOffset = nameSpan.start.offset;
+ int nameLength = nameSpan.length;
+ // add edit
+ change.addEdit(pubspecFile.path, pubspecFile.modificationStamp,
+ new SourceEdit(nameOffset, nameLength, newPackageName));
+ }
+ // check all local libraries
+ for (Source librarySource in context.librarySources) {
+ // should be a local library
+ if (!project.contains(librarySource.fullName)) {
+ continue;
+ }
+ // we need LibraryElement
+ LibraryElement library = context.getLibraryElement(librarySource);
+ if (library == null) {
+ continue;
+ }
+ // update all imports
+ updateUriElements(List<UriReferencedElement> uriElements) {
+ for (UriReferencedElement element in uriElements) {
+ String uri = element.uri;
+ if (uri != null) {
+ String oldPrefix = 'package:$oldPackageName/';
+ if (uri.startsWith(oldPrefix)) {
+ doSourceChange_addElementEdit(change, library, new SourceEdit(
+ element.uriOffset + 1, oldPrefix.length,
+ 'package:$newPackageName/'));
+ }
+ }
+ }
+ }
+ updateUriElements(library.imports);
+ updateUriElements(library.exports);
+ }
+ // done
return change;
}
« 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