Skip to content

Commit 9d040aa

Browse files
bwilkersonCommit Queue
authored andcommitted
[Migrate] move_file.dart
Also removes an already migrated file from the list. Change-Id: I76b88802b7867abe77867713166b048ee7b8cb0a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402882 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 04de771 commit 9d040aa

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ lib/src/handler/legacy/edit_get_available_refactorings.dart
55
lib/src/handler/legacy/search_find_element_references.dart
66
lib/src/lsp/handlers/handler_completion.dart
77
lib/src/lsp/handlers/handler_completion_resolve.dart
8-
lib/src/lsp/handlers/handler_references.dart
98
lib/src/lsp/handlers/handler_rename.dart
109
lib/src/protocol_server.dart
1110
lib/src/services/correction/namespace.dart
1211
lib/src/services/kythe/kythe_visitors.dart
1312
lib/src/services/refactoring/legacy/extract_method.dart
14-
lib/src/services/refactoring/legacy/move_file.dart
1513
lib/src/services/refactoring/legacy/refactoring.dart
1614
lib/src/services/refactoring/legacy/refactoring_manager.dart
1715
lib/src/services/refactoring/legacy/rename.dart

pkg/analysis_server/lib/src/services/refactoring/legacy/move_file.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:analyzer/source/source_range.dart';
1616
import 'package:analyzer/src/dart/analysis/driver.dart';
1717
import 'package:analyzer/src/dart/analysis/search.dart';
1818
import 'package:analyzer/src/dart/ast/ast.dart';
19-
import 'package:analyzer/src/utilities/extensions/element.dart';
2019
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
2120
import 'package:analyzer_plugin/utilities/range_factory.dart';
2221
import 'package:path/path.dart' as path show posix, Context;
@@ -204,8 +203,8 @@ class MoveFileRefactoringImpl extends RefactoringImpl
204203
return;
205204
}
206205

207-
var element = resolvedUnit.unit.declaredElement;
208-
if (element == null) {
206+
var libraryFragment = resolvedUnit.unit.declaredFragment;
207+
if (libraryFragment == null) {
209208
return;
210209
}
211210

@@ -224,12 +223,12 @@ class MoveFileRefactoringImpl extends RefactoringImpl
224223
));
225224
}
226225

227-
var libraryElement = element.library;
226+
var libraryElement = libraryFragment.element;
228227

229228
// If this element is a library, handle inbound 'part of' directives which
230229
// are not included in `searchEngine.searchReferences` below.
231-
if (element == libraryElement.definingCompilationUnit) {
232-
var libraryResult = await _session.getResolvedLibraryByElement(
230+
if (libraryFragment == libraryElement.firstFragment) {
231+
var libraryResult = await _session.getResolvedLibraryByElement2(
233232
libraryElement,
234233
);
235234
if (libraryResult is! ResolvedLibraryResult) {
@@ -247,7 +246,7 @@ class MoveFileRefactoringImpl extends RefactoringImpl
247246
for (var uriString in partOfs) {
248247
recordReference(
249248
range: range.node(uriString),
250-
sourceFile: result.unit.declaredElement!.source.fullName,
249+
sourceFile: result.unit.declaredFragment!.source.fullName,
251250
targetFile: oldPath,
252251
quotedUriValue: uriString.literal.lexeme,
253252
);
@@ -271,7 +270,7 @@ class MoveFileRefactoringImpl extends RefactoringImpl
271270
if (uriValue == null) continue;
272271
recordReference(
273272
range: range.node(uriString),
274-
sourceFile: element.source.fullName,
273+
sourceFile: libraryFragment.source.fullName,
275274
targetFile: pathContext.normalize(
276275
pathContext.join(oldDir, _uriToPath(uriValue)),
277276
),
@@ -283,7 +282,7 @@ class MoveFileRefactoringImpl extends RefactoringImpl
283282

284283
// Finally, locate all other incoming references to this file.
285284
var references = await refactoringWorkspace.searchEngine
286-
.searchLibraryFragmentReferences(element.asElement2);
285+
.searchLibraryFragmentReferences(libraryFragment);
287286
for (var reference in references) {
288287
recordReference(
289288
range: reference.range,

0 commit comments

Comments
 (0)