@@ -9,10 +9,9 @@ import 'package:analysis_server/src/utilities/extensions/string.dart';
99import 'package:analysis_server/src/utilities/import_analyzer.dart' ;
1010import 'package:analyzer/dart/ast/ast.dart' ;
1111import 'package:analyzer/dart/ast/token.dart' ;
12- import 'package:analyzer/dart/element/element .dart' ;
12+ import 'package:analyzer/dart/element/element2 .dart' ;
1313import 'package:analyzer/source/line_info.dart' ;
1414import 'package:analyzer/source/source_range.dart' ;
15- import 'package:analyzer/src/utilities/extensions/element.dart' ;
1615import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
1716import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart' ;
1817import 'package:analyzer_plugin/utilities/range_factory.dart' ;
@@ -151,31 +150,33 @@ class MoveTopLevelToFile extends RefactoringProducer {
151150 builder.addDeletion (sourceRange);
152151 }
153152 });
154- var libraries = < LibraryElement , Set <Element >> {};
153+ var libraries = < LibraryElement2 , Set <Element2 >> {};
155154 for (var element2 in analyzer.movingDeclarations) {
156- var element = element2.asElement ! ;
157- var matches = await searchEngine.searchReferences (element);
155+ var element = element2;
156+ var matches = await searchEngine.searchReferences2 (element);
158157 for (var match in matches) {
159158 if (match.isResolved) {
160- libraries.putIfAbsent (match.libraryElement , () => {}).add (element );
159+ libraries.putIfAbsent (match.libraryElement2 , () => {}).add (element2 );
161160 }
162161 }
163162 }
164163
165164 /// Don't update the library from which the code is being moved because
166165 /// that's already been done.
167- libraries.remove (libraryResult.element );
166+ libraries.remove (libraryResult.element2 );
168167 for (var entry in libraries.entries) {
169168 var library = entry.key;
170169 var prefixes = < String > {};
171170 for (var element in entry.value) {
172- var prefixList = await searchEngine.searchPrefixesUsedInLibrary (
171+ var prefixList = await searchEngine.searchPrefixesUsedInLibrary2 (
173172 library,
174173 element,
175174 );
176175 prefixes.addAll (prefixList);
177176 }
178- await builder.addDartFileEdit (library.source.fullName, (builder) {
177+ await builder.addDartFileEdit (library.firstFragment.source.fullName, (
178+ builder,
179+ ) {
179180 for (var prefix in prefixes) {
180181 builder.importLibrary (destinationImportUri, prefix: prefix);
181182 }
@@ -284,7 +285,7 @@ class MoveTopLevelToFile extends RefactoringProducer {
284285 unitResult.unit,
285286 candidateElements:
286287 candidateMembers.keys
287- .map ((member) => member.declaredElement )
288+ .map ((member) => member.declaredFragment ? .element )
288289 .nonNulls
289290 .toSet (),
290291 );
@@ -333,8 +334,8 @@ class MoveTopLevelToFile extends RefactoringProducer {
333334 .expand ((unit) => unit.unit.declarations)
334335 .expand ((declaration) => declaration.sealedSuperclassElements)
335336 // Check if any of them are in the source file.
336- .map ((element) => element.enclosingElement3 )
337- .contains (unitResult.unit.declaredElement );
337+ .map ((element) => element.enclosingElement2 )
338+ .contains (unitResult.unit.declaredFragment ? .element );
338339 }
339340
340341 /// Return a list containing the top-level declarations that are selected, or
@@ -486,10 +487,10 @@ class _SealedSubclassIndex {
486487 final CompilationUnit unit;
487488
488489 /// The set of initial candidate elements.
489- final Set <Element > candidateElements;
490+ final Set <Element2 > candidateElements;
490491
491492 /// A map of sealed named classes/mixin elements to a set of their subclasses.
492- final Map <Element , Set <CompilationUnitMember >> sealedTypeSubclasses = {};
493+ final Map <Element2 , Set <CompilationUnitMember >> sealedTypeSubclasses = {};
493494
494495 /// Whether or not the candidate set is invalid.
495496 ///
@@ -515,7 +516,7 @@ class _SealedSubclassIndex {
515516
516517 // If this declaration is a candidate but it's sealed super is not,
517518 // we have an invalid selection.
518- if (isCandidate (declaration.declaredElement ) &&
519+ if (isCandidate (declaration.declaredFragment ? .element ) &&
519520 ! isCandidate (superElement)) {
520521 hasInvalidCandidateSet = true ;
521522 return ;
@@ -536,7 +537,7 @@ class _SealedSubclassIndex {
536537 ...members,
537538 ...members.whereType <NamedCompilationUnitMember >().expand (
538539 (member) => findSubclassesOfSealedRecursively (
539- sealedTypeSubclasses[member.declaredElement ] ?? const {},
540+ sealedTypeSubclasses[member.declaredFragment ? .element ] ?? const {},
540541 ),
541542 ),
542543 };
@@ -545,10 +546,10 @@ class _SealedSubclassIndex {
545546
546547extension on CompilationUnitMember {
547548 /// Gets all sealed [ClassElement] s that are superclasses of this member.
548- Iterable <ClassElement > get sealedSuperclassElements {
549+ Iterable <ClassElement2 > get sealedSuperclassElements {
549550 return superclasses
550- .map ((type) => type? .element )
551- .whereType <ClassElement >()
551+ .map ((type) => type? .element2 )
552+ .whereType <ClassElement2 >()
552553 .where ((element) => element.isSealed);
553554 }
554555
0 commit comments