@@ -26,11 +26,6 @@ import 'package:analyzer_plugin/utilities/range_factory.dart';
2626class ImportLibrary extends MultiCorrectionProducer {
2727 final _ImportKind _importKind;
2828
29- /// Initialize a newly created instance that will add an import of
30- /// `dart:async` .
31- ImportLibrary .dartAsync ({required super .context})
32- : _importKind = _ImportKind .dartAsync;
33-
3429 /// Initialize a newly created instance that will add an import for an
3530 /// extension.
3631 ImportLibrary .forExtension ({required super .context})
@@ -65,10 +60,6 @@ class ImportLibrary extends MultiCorrectionProducer {
6560 @override
6661 Future <List <ResolvedCorrectionProducer >> get producers async {
6762 return switch (_importKind) {
68- _ImportKind .dartAsync => _importLibrary (
69- DartFixKind .IMPORT_ASYNC ,
70- Uri .parse ('dart:async' ),
71- ),
7263 _ImportKind .forExtension => await _producersForExtension (),
7364 _ImportKind .forExtensionMember => await _producersForExtensionMember (),
7465 _ImportKind .forExtensionType => await _producersForExtensionType (),
@@ -154,29 +145,66 @@ class ImportLibrary extends MultiCorrectionProducer {
154145 /// Otherwise, both are returned in the order: absolute, relative.
155146 List <ResolvedCorrectionProducer > _importLibrary (
156147 FixKind fixKind,
157- Uri library, {
148+ FixKind fixKindShow,
149+ Uri library,
150+ String name, {
158151 String ? prefix,
159152 bool includeRelativeFix = false ,
160153 }) {
161154 if (! includeRelativeFix) {
162155 return [
163156 _ImportAbsoluteLibrary (fixKind, library, prefix, context: context),
157+ _ImportAbsoluteLibrary (
158+ fixKindShow,
159+ library,
160+ prefix,
161+ show: name,
162+ context: context,
163+ ),
164164 ];
165165 }
166166 var codeStyleOptions = getCodeStyleOptions (unitResult.file);
167167 if (codeStyleOptions.usePackageUris) {
168168 return [
169169 _ImportAbsoluteLibrary (fixKind, library, prefix, context: context),
170+ _ImportAbsoluteLibrary (
171+ fixKindShow,
172+ library,
173+ prefix,
174+ show: name,
175+ context: context,
176+ ),
170177 ];
171178 }
172179 if (codeStyleOptions.useRelativeUris) {
173180 return [
174181 _ImportRelativeLibrary (fixKind, library, prefix, context: context),
182+ _ImportRelativeLibrary (
183+ fixKindShow,
184+ library,
185+ prefix,
186+ show: name,
187+ context: context,
188+ ),
175189 ];
176190 }
177191 return [
178192 _ImportAbsoluteLibrary (fixKind, library, prefix, context: context),
193+ _ImportAbsoluteLibrary (
194+ fixKindShow,
195+ library,
196+ prefix,
197+ show: name,
198+ context: context,
199+ ),
179200 _ImportRelativeLibrary (fixKind, library, prefix, context: context),
201+ _ImportRelativeLibrary (
202+ fixKindShow,
203+ library,
204+ prefix,
205+ show: name,
206+ context: context,
207+ ),
180208 ];
181209 }
182210
@@ -282,29 +310,46 @@ class ImportLibrary extends MultiCorrectionProducer {
282310 }
283311 // Compute the fix kind.
284312 FixKind fixKind;
313+ FixKind fixKindShow;
285314 if (libraryElement.isInSdk) {
286315 fixKind =
287316 prefix.isEmptyOrNull
288317 ? DartFixKind .IMPORT_LIBRARY_SDK
289318 : DartFixKind .IMPORT_LIBRARY_SDK_PREFIXED ;
319+ fixKindShow =
320+ prefix.isEmptyOrNull
321+ ? DartFixKind .IMPORT_LIBRARY_SDK_SHOW
322+ : DartFixKind .IMPORT_LIBRARY_SDK_PREFIXED_SHOW ;
290323 } else if (_isLibSrcPath (librarySource.fullName)) {
291324 // Bad: non-API.
292325 fixKind =
293326 prefix.isEmptyOrNull
294327 ? DartFixKind .IMPORT_LIBRARY_PROJECT3
295328 : DartFixKind .IMPORT_LIBRARY_PROJECT3_PREFIXED ;
329+ fixKindShow =
330+ prefix.isEmptyOrNull
331+ ? DartFixKind .IMPORT_LIBRARY_PROJECT3_SHOW
332+ : DartFixKind .IMPORT_LIBRARY_PROJECT3_PREFIXED_SHOW ;
296333 } else if (declaration.library != libraryElement) {
297334 // Ugly: exports.
298335 fixKind =
299336 prefix.isEmptyOrNull
300337 ? DartFixKind .IMPORT_LIBRARY_PROJECT2
301338 : DartFixKind .IMPORT_LIBRARY_PROJECT2_PREFIXED ;
339+ fixKindShow =
340+ prefix.isEmptyOrNull
341+ ? DartFixKind .IMPORT_LIBRARY_PROJECT2_SHOW
342+ : DartFixKind .IMPORT_LIBRARY_PROJECT2_PREFIXED_SHOW ;
302343 } else {
303344 // Good: direct declaration.
304345 fixKind =
305346 prefix.isEmptyOrNull
306347 ? DartFixKind .IMPORT_LIBRARY_PROJECT1
307348 : DartFixKind .IMPORT_LIBRARY_PROJECT1_PREFIXED ;
349+ fixKindShow =
350+ prefix.isEmptyOrNull
351+ ? DartFixKind .IMPORT_LIBRARY_PROJECT1_SHOW
352+ : DartFixKind .IMPORT_LIBRARY_PROJECT1_PREFIXED_SHOW ;
308353 }
309354 // If both files are in the same package's 'lib' folder, also include a
310355 // relative import.
@@ -316,7 +361,9 @@ class ImportLibrary extends MultiCorrectionProducer {
316361 producers.addAll (
317362 _importLibrary (
318363 fixKind,
364+ fixKindShow,
319365 librarySource.uri,
366+ name,
320367 prefix: prefix,
321368 includeRelativeFix: includeRelativeUri,
322369 ),
@@ -543,15 +590,17 @@ class _ImportAbsoluteLibrary extends ResolvedCorrectionProducer {
543590 final FixKind _fixKind;
544591 final String ? _prefix;
545592 final Uri _library;
593+ final String ? _show;
546594
547595 String _uriText = '' ;
548596
549597 _ImportAbsoluteLibrary (
550598 this ._fixKind,
551599 this ._library,
552600 this ._prefix, {
601+ String ? show,
553602 required super .context,
554- });
603+ }) : _show = show ;
555604
556605 @override
557606 CorrectionApplicability get applicability =>
@@ -572,14 +621,18 @@ class _ImportAbsoluteLibrary extends ResolvedCorrectionProducer {
572621 Future <void > compute (ChangeBuilder builder) async {
573622 await builder.addDartFileEdit (file, (builder) {
574623 if (builder is DartFileEditBuilderImpl ) {
575- _uriText = builder.importLibraryWithAbsoluteUri (_library, _prefix);
624+ _uriText = builder.importLibraryWithAbsoluteUri (
625+ _library,
626+ prefix: _prefix,
627+ shownName: _show,
628+ useShow: _show != null ,
629+ );
576630 }
577631 });
578632 }
579633}
580634
581635enum _ImportKind {
582- dartAsync,
583636 forExtension,
584637 forExtensionMember,
585638 forExtensionType,
@@ -783,15 +836,17 @@ class _ImportRelativeLibrary extends ResolvedCorrectionProducer {
783836 final FixKind _fixKind;
784837 final String ? _prefix;
785838 final Uri _library;
839+ final String ? _show;
786840
787841 String _uriText = '' ;
788842
789843 _ImportRelativeLibrary (
790844 this ._fixKind,
791845 this ._library,
792846 this ._prefix, {
847+ String ? show,
793848 required super .context,
794- });
849+ }) : _show = show ;
795850
796851 @override
797852 CorrectionApplicability get applicability =>
@@ -812,7 +867,12 @@ class _ImportRelativeLibrary extends ResolvedCorrectionProducer {
812867 Future <void > compute (ChangeBuilder builder) async {
813868 await builder.addDartFileEdit (file, (builder) {
814869 if (builder is DartFileEditBuilderImpl ) {
815- _uriText = builder.importLibraryWithRelativeUri (_library, _prefix);
870+ _uriText = builder.importLibraryWithRelativeUri (
871+ _library,
872+ prefix: _prefix,
873+ shownName: _show,
874+ useShow: _show != null ,
875+ );
816876 }
817877 });
818878 }
0 commit comments