@@ -74,18 +74,18 @@ class ImportLibrary extends MultiCorrectionProducer {
7474 }
7575 return [
7676 for (var name in names)
77- if (await name.getProducers () case var producers? ) ...producers,
77+ if (await name.producers case var producers? ) ...producers,
7878 ];
7979 }
8080
8181 /// A map of all the error codes that this fix can be applied to and the
8282 /// generators that can be used to apply the fix.
8383 Map <ErrorCode , List <MultiProducerGenerator >> get _errorCodesWhereThisIsValid {
84- var constructors = _ImportKind .values.map ((key) => key.fn).toList ();
84+ var producerGenerators = _ImportKind .values.map ((key) => key.fn).toList ();
8585 var nonLintMultiProducers = registeredFixGenerators.nonLintMultiProducers;
8686 return {
8787 for (var MapEntry (: key, : value) in nonLintMultiProducers.entries)
88- if (value.containsAny (constructors )) key: value,
88+ if (value.containsAny (producerGenerators )) key: value,
8989 };
9090 }
9191
@@ -162,22 +162,27 @@ class ImportLibrary extends MultiCorrectionProducer {
162162 return (importCombinator, importCombinatorMultiple);
163163 }
164164
165- /// Returns a list of one or two import corrections .
165+ /// Returns a list of two or four import correction producers .
166166 ///
167- /// If [includeRelativeFix] is `false` , only one correction, with an absolute
168- /// import path, is returned. Otherwise, a correction with an absolute import
169- /// path and a correction with a relative path are returned.
170- /// If the `always_use_package_imports` lint rule is active then only the
171- /// package import is returned.
172- /// If `prefer_relative_imports` is active then the relative path is returned.
173- /// Otherwise, both are returned in the order: absolute, relative.
167+ /// For each import path used in the return values, one returned correction
168+ /// producer uses a 'show' combinator, and one does not.
169+ ///
170+ /// If [includeRelativeFix] is `false` , only two correction producers, with
171+ /// absolute import paths, are returned. Otherwise, correction producers with
172+ /// absolute import paths and correction producers with relative paths are
173+ /// returned. If the `always_use_package_imports` lint rule is enabled then
174+ /// only correction producers using the package import are returned. If the
175+ /// `prefer_relative_imports` lint rule is enabled then only correction
176+ /// producers using the relative path are returned. Otherwise, correction
177+ /// producers using both types of paths are returned in the order: absolute
178+ /// imports, relative imports.
174179 List <ResolvedCorrectionProducer > _importLibrary (
175180 FixKind fixKind,
176181 FixKind fixKindShow,
177182 Uri library,
178183 String name, {
179- String ? prefix,
180- bool includeRelativeFix = false ,
184+ required String ? prefix,
185+ required bool includeRelativeFix,
181186 }) {
182187 if (! includeRelativeFix) {
183188 return [
@@ -564,10 +569,10 @@ class ImportLibrary extends MultiCorrectionProducer {
564569 ///
565570 /// If we have unresolved code like `foo.bar()` then we have two options:
566571 /// - Import of some library, prefixed with `foo` , that contains a top-level
567- /// function called bar;
568- /// - Import of some library that contains a top-level propriety or class
569- /// called `foo` that has a method called `bar` (has to be static for a
570- /// _class_ with that name).
572+ /// function called ` bar` .
573+ /// - Import of some library that contains a top-level propriety or class-like
574+ /// member called `foo` that has a method called `bar` (has to be static for
575+ /// a class-like member with that name).
571576 List <_PrefixedName > _namesForMethodInvocation (
572577 String name,
573578 AstNode ? parent,
@@ -711,8 +716,9 @@ class ImportLibrary extends MultiCorrectionProducer {
711716 ),
712717 ];
713718 }
714- if (targetNode.mightBeImplicitConstructor) {
715- var typeName = (targetNode as SimpleIdentifier ).name;
719+ if (targetNode is SimpleIdentifier &&
720+ targetNode.mightBeImplicitConstructor) {
721+ var typeName = targetNode.name;
716722 return [
717723 _PrefixedName (
718724 name: typeName,
@@ -729,8 +735,8 @@ class ImportLibrary extends MultiCorrectionProducer {
729735 return const [];
730736 }
731737
732- /// Runs the entire compilation unit to find all errors for unresolved names
733- /// where this fix can be applied besides the current diagnostic.
738+ /// Searches all diagnostics reported for this compilation unit for unresolved
739+ /// names where this fix can be applied besides the current diagnostic.
734740 Future <Set <String >> _otherUnresolvedNames (String ? prefix, String name) async {
735741 var errorsForThisFix = _errorCodesWhereThisIsValid;
736742 var errors =
@@ -802,9 +808,8 @@ class _ImportAbsoluteLibrary extends ResolvedCorrectionProducer {
802808
803809 @override
804810 CorrectionApplicability get applicability =>
805- // TODO(applicability): comment on why.
806- CorrectionApplicability
807- .singleLocation;
811+ // TODO(applicability): comment on why.
812+ CorrectionApplicability .singleLocation;
808813
809814 @override
810815 List <String > get fixArguments => [
@@ -882,9 +887,8 @@ class _ImportLibraryCombinatorMultiple extends ResolvedCorrectionProducer {
882887
883888 @override
884889 CorrectionApplicability get applicability =>
885- // TODO(applicability): comment on why.
886- CorrectionApplicability
887- .singleLocation;
890+ // TODO(applicability): comment on why.
891+ CorrectionApplicability .singleLocation;
888892
889893 @override
890894 List <String > get fixArguments {
@@ -973,9 +977,8 @@ class _ImportLibraryContainingExtension extends ResolvedCorrectionProducer {
973977
974978 @override
975979 CorrectionApplicability get applicability =>
976- // TODO(applicability): comment on why.
977- CorrectionApplicability
978- .singleLocation;
980+ // TODO(applicability): comment on why.
981+ CorrectionApplicability .singleLocation;
979982
980983 @override
981984 List <String > get fixArguments => [_uriText];
@@ -1017,9 +1020,8 @@ class _ImportLibraryPrefix extends ResolvedCorrectionProducer {
10171020
10181021 @override
10191022 CorrectionApplicability get applicability =>
1020- // TODO(applicability): comment on why.
1021- CorrectionApplicability
1022- .singleLocation;
1023+ // TODO(applicability): comment on why.
1024+ CorrectionApplicability .singleLocation;
10231025
10241026 @override
10251027 List <String > get fixArguments {
@@ -1081,9 +1083,8 @@ class _ImportRelativeLibrary extends ResolvedCorrectionProducer {
10811083
10821084 @override
10831085 CorrectionApplicability get applicability =>
1084- // TODO(applicability): comment on why.
1085- CorrectionApplicability
1086- .singleLocation;
1086+ // TODO(applicability): comment on why.
1087+ CorrectionApplicability .singleLocation;
10871088
10881089 @override
10891090 List <String > get fixArguments => [
@@ -1109,12 +1110,11 @@ class _ImportRelativeLibrary extends ResolvedCorrectionProducer {
11091110 }
11101111}
11111112
1112- /// This is a data class that holds the information needed to generate producers
1113- /// for a given name and prefix.
1113+ /// Information needed to generate producers for a given [name] and [prefix] .
11141114///
11151115/// This is used in normal cases simply to generate the producers, but for the
1116- /// [_ImportLibraryCombinatorMultiple] it is used to save the different names
1117- /// that are being added to the combinator.
1116+ /// [_ImportLibraryCombinatorMultiple] correction producer, it is used to save
1117+ /// the different names that are being added to the combinator.
11181118class _PrefixedName {
11191119 /// Whether to ignore the prefix.
11201120 ///
@@ -1123,32 +1123,33 @@ class _PrefixedName {
11231123 final bool ignorePrefix;
11241124 final String ? prefix;
11251125 final String name;
1126- final _ProducersGenerators ? _producerGenerators;
1126+ final _ProducersGenerators _producerGenerators;
11271127
11281128 _PrefixedName ({
11291129 required this .name,
11301130 this .prefix,
1131- required _ProducersGenerators ? producerGenerators,
1131+ required _ProducersGenerators producerGenerators,
11321132 this .ignorePrefix = false ,
11331133 }) : _producerGenerators = producerGenerators;
11341134
1135- Future <List <ResolvedCorrectionProducer >>? getProducers () =>
1136- _producerGenerators? . call (prefix, name);
1135+ Future <List <ResolvedCorrectionProducer >>? get producers =>
1136+ _producerGenerators (prefix, name);
11371137}
11381138
1139- extension on AstNode {
1139+ extension on SimpleIdentifier {
11401140 /// Whether this [AstNode] is in a location where an implicit constructor
11411141 /// invocation would be allowed.
11421142 bool get mightBeImplicitConstructor {
1143- if (this is SimpleIdentifier ) {
1144- var parent = this .parent;
1145- if (parent is MethodInvocation ) {
1146- return parent.realTarget == null ;
1147- }
1143+ var parent = this .parent;
1144+ if (parent is MethodInvocation ) {
1145+ return parent.realTarget == null ;
11481146 }
1147+
11491148 return false ;
11501149 }
1150+ }
11511151
1152+ extension on AstNode {
11521153 /// The "type name" of this node if it might represent a type, and `null`
11531154 /// otherwise.
11541155 String ? get nameOfType {
0 commit comments