@@ -10,14 +10,13 @@ import 'package:analysis_server/src/utilities/extensions/element.dart';
1010import 'package:analysis_server_plugin/edit/dart/correction_producer.dart' ;
1111import 'package:analyzer/dart/ast/ast.dart' ;
1212import 'package:analyzer/dart/ast/token.dart' ;
13- import 'package:analyzer/dart/element/element .dart' ;
13+ import 'package:analyzer/dart/element/element2 .dart' ;
1414import 'package:analyzer/dart/element/type.dart' ;
1515import 'package:analyzer/dart/element/type_system.dart' ;
1616import 'package:analyzer/source/source_range.dart' ;
1717import 'package:analyzer/src/dart/ast/extensions.dart' ;
1818import 'package:analyzer/src/dart/element/inheritance_manager3.dart' ;
1919import 'package:analyzer/src/dart/resolver/applicable_extensions.dart' ;
20- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2120import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_dart.dart' ;
2221import 'package:analyzer_plugin/src/utilities/library.dart' ;
2322import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
@@ -71,7 +70,7 @@ class ImportLibrary extends MultiCorrectionProducer {
7170 }
7271
7372 List <ResolvedCorrectionProducer > _importExtensionInLibrary (
74- LibraryElement libraryToImport,
73+ LibraryElement2 libraryToImport,
7574 DartType targetType,
7675 Name memberName,
7776 ) {
@@ -80,19 +79,16 @@ class ImportLibrary extends MultiCorrectionProducer {
8079 // additional analysis.
8180 var foundImport = false ;
8281 var producers = < ResolvedCorrectionProducer > [];
83- for (var import in libraryElement.definingCompilationUnit.libraryImports ) {
82+ for (var import in unitResult.libraryFragment.libraryImports2 ) {
8483 // prepare element
85- var importedLibrary = import.importedLibrary ;
84+ var importedLibrary = import.importedLibrary2 ;
8685 if (importedLibrary == null || importedLibrary != libraryToImport) {
8786 continue ;
8887 }
8988 foundImport = true ;
90- var instantiatedExtensions = importedLibrary.asElement2. exportedExtensions
89+ var instantiatedExtensions = importedLibrary.exportedExtensions
9190 .havingMemberWithBaseName (memberName)
92- .applicableTo (
93- targetLibrary: libraryElement2,
94- targetType: targetType,
95- );
91+ .applicableTo (targetLibrary: libraryElement2, targetType: targetType);
9692 for (var instantiatedExtension in instantiatedExtensions) {
9793 // If the import has a combinator that needs to be updated, then offer
9894 // to update it.
@@ -102,7 +98,7 @@ class ImportLibrary extends MultiCorrectionProducer {
10298 if (combinator is HideElementCombinator ) {
10399 producers.add (
104100 _ImportLibraryCombinator (
105- libraryToImport.source. uri.toString (),
101+ libraryToImport.uri.toString (),
106102 combinator,
107103 instantiatedExtension.extension .name3! ,
108104 context: context,
@@ -111,7 +107,7 @@ class ImportLibrary extends MultiCorrectionProducer {
111107 } else if (combinator is ShowElementCombinator ) {
112108 producers.add (
113109 _ImportLibraryCombinator (
114- libraryToImport.source. uri.toString (),
110+ libraryToImport.uri.toString (),
115111 combinator,
116112 instantiatedExtension.extension .name3! ,
117113 context: context,
@@ -224,19 +220,19 @@ class ImportLibrary extends MultiCorrectionProducer {
224220 var producers = < ResolvedCorrectionProducer > [];
225221 // Maybe there is an existing import, but it is with prefix and we don't use
226222 // this prefix.
227- var alreadyImportedWithPrefix = < LibraryElement > {};
228- for (var import in libraryElement.definingCompilationUnit.libraryImports ) {
223+ var alreadyImportedWithPrefix = < LibraryElement2 > {};
224+ for (var import in unitResult.libraryFragment.libraryImports2 ) {
229225 // Prepare the element.
230- var libraryElement = import.importedLibrary ;
226+ var libraryElement = import.importedLibrary2 ;
231227 if (libraryElement == null ) {
232228 continue ;
233229 }
234- var element = getExportedElement (libraryElement, name);
230+ var element = getExportedElement2 (libraryElement, name);
235231 if (element == null ) {
236232 continue ;
237233 }
238- if (element is PropertyAccessorElement ) {
239- element = element.variable2 ;
234+ if (element is PropertyAccessorElement2 ) {
235+ element = element.variable3 ;
240236 if (element == null ) {
241237 continue ;
242238 }
@@ -245,16 +241,12 @@ class ImportLibrary extends MultiCorrectionProducer {
245241 continue ;
246242 }
247243 _ImportLibraryCombinator ? combinatorProducer;
248- var importPrefix = import.prefix ? .element;
244+ var importPrefix = import.prefix2 ? .element;
249245 // Maybe update a "show"/"hide" directive.
250246 var combinators = import.combinators;
251247 if (combinators.length == 1 ) {
252248 // Prepare library name - unit name or 'dart:name' for SDK library.
253- var libraryName =
254- libraryElement.definingCompilationUnit.source.uri.toString ();
255- if (libraryElement.isInSdk) {
256- libraryName = libraryElement.source.shortName;
257- }
249+ var libraryName = libraryElement.uri.toString ();
258250 var combinator = combinators.first;
259251 if (combinator is HideElementCombinator ) {
260252 // Don't add this library again.
@@ -295,11 +287,11 @@ class ImportLibrary extends MultiCorrectionProducer {
295287 }
296288 }
297289 // Find new top-level declarations.
298- var librariesWithElements = await getTopLevelDeclarations (name);
290+ var librariesWithElements = await getTopLevelDeclarations2 (name);
299291 for (var libraryEntry in librariesWithElements.entries) {
300292 var libraryElement = libraryEntry.key;
301293 var declaration = libraryEntry.value;
302- var librarySource = libraryElement.source;
294+ var librarySource = libraryElement.firstFragment. source;
303295 // Check the kind.
304296 if (! kinds.contains (declaration.kind)) {
305297 continue ;
@@ -334,7 +326,7 @@ class ImportLibrary extends MultiCorrectionProducer {
334326 prefix.isEmptyOrNull
335327 ? DartFixKind .IMPORT_LIBRARY_PROJECT3_SHOW
336328 : DartFixKind .IMPORT_LIBRARY_PROJECT3_PREFIXED_SHOW ;
337- } else if (declaration.library != libraryElement) {
329+ } else if (declaration.library2 != libraryElement) {
338330 // Ugly: exports.
339331 fixKind =
340332 prefix.isEmptyOrNull
@@ -359,7 +351,7 @@ class ImportLibrary extends MultiCorrectionProducer {
359351 // relative import.
360352 var includeRelativeUri = canBeRelativeImport (
361353 librarySource.uri,
362- this .libraryElement.librarySource .uri,
354+ libraryElement2 .uri,
363355 );
364356 // Add the fix(es).
365357 producers.addAll (
@@ -429,12 +421,12 @@ class ImportLibrary extends MultiCorrectionProducer {
429421 return const [];
430422 }
431423
432- var name = Name (
433- dartFixContext.unitResult.libraryElement.source.uri ,
424+ var name = Name . forLibrary (
425+ dartFixContext.unitResult.libraryElement2 ,
434426 memberName,
435427 );
436428 var producers = < ResolvedCorrectionProducer > [];
437- await for (var libraryToImport in librariesWithExtensions (memberName)) {
429+ await for (var libraryToImport in librariesWithExtensions2 (memberName)) {
438430 producers.addAll (
439431 _importExtensionInLibrary (libraryToImport, targetType, name),
440432 );
@@ -527,7 +519,7 @@ class ImportLibrary extends MultiCorrectionProducer {
527519 prefix = prefixed.prefix.name;
528520 }
529521 if (targetNode case Annotation (: var name)) {
530- if (name.staticElement == null ) {
522+ if (name.element == null ) {
531523 if (targetNode.arguments != null ) {
532524 return const [];
533525 }
@@ -557,7 +549,7 @@ class ImportLibrary extends MultiCorrectionProducer {
557549 }
558550 var targetNode = node;
559551 if (targetNode case Annotation (: var name)) {
560- if (name.staticElement == null ) {
552+ if (name.element == null ) {
561553 if (targetNode.period != null && targetNode.arguments == null ) {
562554 return const [];
563555 }
@@ -701,8 +693,8 @@ class _ImportLibraryCombinator extends ResolvedCorrectionProducer {
701693 if (finalNames.isNotEmpty) {
702694 newCombinatorCode = ' ${keyword .lexeme } ${finalNames .join (', ' )}' ;
703695 }
704- var libraryFile = unitResult.libraryElement .source.fullName;
705- await builder.addDartFileEdit (libraryFile , (builder) {
696+ var libraryPath = unitResult.libraryElement2.firstFragment .source.fullName;
697+ await builder.addDartFileEdit (libraryPath , (builder) {
706698 builder.addSimpleReplacement (
707699 SourceRange (offset - 1 , length + 1 ),
708700 newCombinatorCode,
@@ -729,7 +721,7 @@ class _ImportLibraryCombinator extends ResolvedCorrectionProducer {
729721/// extension, but which does so only if the extension applies to a given type.
730722class _ImportLibraryContainingExtension extends ResolvedCorrectionProducer {
731723 /// The library defining the extension.
732- LibraryElement library;
724+ LibraryElement2 library;
733725
734726 /// The type of the target that the extension must apply to.
735727 DartType targetType;
@@ -761,12 +753,12 @@ class _ImportLibraryContainingExtension extends ResolvedCorrectionProducer {
761753
762754 @override
763755 Future <void > compute (ChangeBuilder builder) async {
764- var instantiatedExtensions = library.asElement2. exportedExtensions
756+ var instantiatedExtensions = library.exportedExtensions
765757 .havingMemberWithBaseName (memberName)
766758 .applicableTo (targetLibrary: libraryElement2, targetType: targetType);
767759 if (instantiatedExtensions.isNotEmpty) {
768760 await builder.addDartFileEdit (file, (builder) {
769- _uriText = builder.importLibrary (library.source. uri);
761+ _uriText = builder.importLibrary (library.uri);
770762 });
771763 }
772764 }
@@ -775,8 +767,8 @@ class _ImportLibraryContainingExtension extends ResolvedCorrectionProducer {
775767/// A correction processor that can add a prefix to an identifier defined in a
776768/// library that is already imported but that is imported with a prefix.
777769class _ImportLibraryPrefix extends ResolvedCorrectionProducer {
778- final LibraryElement _importedLibrary;
779- final PrefixElement _importPrefix;
770+ final LibraryElement2 _importedLibrary;
771+ final PrefixElement2 _importPrefix;
780772 final String ? _nodePrefix;
781773 final _ImportLibraryCombinator ? _editCombinator;
782774
@@ -796,14 +788,14 @@ class _ImportLibraryPrefix extends ResolvedCorrectionProducer {
796788
797789 @override
798790 List <String > get fixArguments {
799- var uriStr = _importedLibrary.source. uri.toString ();
791+ var uriStr = _importedLibrary.uri.toString ();
800792 return [uriStr, _prefixName];
801793 }
802794
803795 @override
804796 FixKind get fixKind => DartFixKind .IMPORT_LIBRARY_PREFIX ;
805797
806- String get _prefixName => _importPrefix.name ;
798+ String get _prefixName => _importPrefix.name3 ! ;
807799
808800 @override
809801 Future <void > compute (ChangeBuilder builder) async {
@@ -945,11 +937,11 @@ extension on SimpleIdentifier {
945937 DartType ? enclosingThisType (AstNode node) {
946938 var parent = node.parent;
947939 if (parent is ClassDeclaration ) {
948- return parent.declaredElement ? .thisType;
940+ return parent.declaredFragment ? .element .thisType;
949941 } else if (parent is ExtensionDeclaration ) {
950942 return parent.onClause? .extendedType.type;
951943 } else if (parent is MixinDeclaration ) {
952- return parent.declaredElement ? .thisType;
944+ return parent.declaredFragment ? .element .thisType;
953945 } else {
954946 return null ;
955947 }
0 commit comments