| 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.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return new Future.value(result); | 49 return new Future.value(result); |
| 50 } | 50 } |
| 51 | 51 |
| 52 @override | 52 @override |
| 53 Future<RefactoringStatus> checkInitialConditions() { | 53 Future<RefactoringStatus> checkInitialConditions() { |
| 54 RefactoringStatus result = new RefactoringStatus(); | 54 RefactoringStatus result = new RefactoringStatus(); |
| 55 return new Future.value(result); | 55 return new Future.value(result); |
| 56 } | 56 } |
| 57 | 57 |
| 58 @override | 58 @override |
| 59 Future<SourceChange> createChange() { | 59 Future<SourceChange> createChange() async { |
| 60 change = new SourceChange('Update File References'); | 60 change = new SourceChange('Update File References'); |
| 61 List<Source> librarySources = context.getLibrariesContaining(source); | 61 List<Source> librarySources = context.getLibrariesContaining(source); |
| 62 return Future.forEach(librarySources, (Source librarySource) { | 62 await Future.forEach(librarySources, (Source librarySource) async { |
| 63 CompilationUnitElement unitElement = | 63 CompilationUnitElement unitElement = |
| 64 context.getCompilationUnitElement(source, librarySource); | 64 context.getCompilationUnitElement(source, librarySource); |
| 65 if (unitElement != null) { | 65 if (unitElement != null) { |
| 66 // if a defining unit, update outgoing references | 66 // if a defining unit, update outgoing references |
| 67 library = unitElement.library; | 67 library = unitElement.library; |
| 68 if (library.definingCompilationUnit == unitElement) { | 68 if (library.definingCompilationUnit == unitElement) { |
| 69 oldLibraryDir = pathContext.dirname(oldFile); | 69 oldLibraryDir = pathContext.dirname(oldFile); |
| 70 newLibraryDir = pathContext.dirname(newFile); | 70 newLibraryDir = pathContext.dirname(newFile); |
| 71 _updateUriReferences(library.imports); | 71 _updateUriReferences(library.imports); |
| 72 _updateUriReferences(library.exports); | 72 _updateUriReferences(library.exports); |
| 73 _updateUriReferences(library.parts); | 73 _updateUriReferences(library.parts); |
| 74 } | 74 } |
| 75 // update reference to the unit | 75 // update reference to the unit |
| 76 return searchEngine.searchReferences(unitElement).then((matches) { | 76 List<SearchMatch> matches = |
| 77 List<SourceReference> references = getSourceReferences(matches); | 77 await searchEngine.searchReferences(unitElement); |
| 78 for (SourceReference reference in references) { | 78 List<SourceReference> references = getSourceReferences(matches); |
| 79 String newUri = _computeNewUri(reference); | 79 for (SourceReference reference in references) { |
| 80 reference.addEdit(change, "'$newUri'"); | 80 String newUri = _computeNewUri(reference); |
| 81 } | 81 reference.addEdit(change, "'$newUri'"); |
| 82 }); | 82 } |
| 83 } | 83 } |
| 84 }).then((_) { | |
| 85 return change; | |
| 86 }); | 84 }); |
| 85 return change; |
| 87 } | 86 } |
| 88 | 87 |
| 89 @override | 88 @override |
| 90 bool requiresPreview() => false; | 89 bool requiresPreview() => false; |
| 91 | 90 |
| 92 /** | 91 /** |
| 93 * Computes the URI to use to reference [newFile] from [reference]. | 92 * Computes the URI to use to reference [newFile] from [reference]. |
| 94 */ | 93 */ |
| 95 String _computeNewUri(SourceReference reference) { | 94 String _computeNewUri(SourceReference reference) { |
| 96 String refDir = pathContext.dirname(reference.file); | 95 String refDir = pathContext.dirname(reference.file); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 } | 155 } |
| 157 | 156 |
| 158 void _updateUriReferences(List<UriReferencedElement> elements) { | 157 void _updateUriReferences(List<UriReferencedElement> elements) { |
| 159 for (UriReferencedElement element in elements) { | 158 for (UriReferencedElement element in elements) { |
| 160 _updateUriReference(element); | 159 _updateUriReference(element); |
| 161 } | 160 } |
| 162 } | 161 } |
| 163 } | 162 } |
| OLD | NEW |