@@ -152,13 +152,17 @@ import 'package:analyzer/src/generated/java_core.dart';
152
152
import 'package:analyzer/src/generated/parser.dart' ;
153
153
import 'package:analyzer_plugin/protocol/protocol_common.dart'
154
154
hide AnalysisError, Element, ElementKind;
155
+ import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_core.dart' ;
155
156
import 'package:analyzer_plugin/src/utilities/change_builder/change_builder_dart.dart' ;
156
157
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
157
158
import 'package:analyzer_plugin/utilities/fixes/fixes.dart' hide FixContributor;
158
159
159
160
/// A function that can be executed to create a multi-correction producer.
160
161
typedef MultiProducerGenerator = MultiCorrectionProducer Function ();
161
162
163
+ /// A function that can be executed to create a non-Dart correction producer.
164
+ typedef NonDartProducerGenerator = NonDartCorrectionProducer Function ();
165
+
162
166
/// A function that can be executed to create a correction producer.
163
167
typedef ProducerGenerator = CorrectionProducer Function ();
164
168
@@ -568,6 +572,40 @@ class FixProcessor extends BaseProcessor {
568
572
],
569
573
};
570
574
575
+ /// A map from error codes to a list of generators used to create the
576
+ /// correction producers used to build fixes for those diagnostics. The
577
+ /// generators used for lint rules are in the [lintProducerMap] .
578
+ static const Map <ErrorCode , List <NonDartProducerGenerator >>
579
+ nonDartProducerMap = {
580
+ HintCode .SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT : [
581
+ UpdateSdkConstraints .version_2_2_2,
582
+ ],
583
+ HintCode .SDK_VERSION_ASYNC_EXPORTED_FROM_CORE : [
584
+ UpdateSdkConstraints .version_2_1_0,
585
+ ],
586
+ HintCode .SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT : [
587
+ UpdateSdkConstraints .version_2_2_2,
588
+ ],
589
+ HintCode .SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT : [
590
+ UpdateSdkConstraints .version_2_2_2,
591
+ ],
592
+ HintCode .SDK_VERSION_EXTENSION_METHODS : [
593
+ UpdateSdkConstraints .version_2_6_0,
594
+ ],
595
+ HintCode .SDK_VERSION_GT_GT_GT_OPERATOR : [
596
+ UpdateSdkConstraints .version_2_2_2,
597
+ ],
598
+ HintCode .SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT : [
599
+ UpdateSdkConstraints .version_2_2_2,
600
+ ],
601
+ HintCode .SDK_VERSION_SET_LITERAL : [
602
+ UpdateSdkConstraints .version_2_2_0,
603
+ ],
604
+ HintCode .SDK_VERSION_UI_AS_CODE : [
605
+ UpdateSdkConstraints .version_2_2_2,
606
+ ],
607
+ };
608
+
571
609
/// A map from error codes to a list of generators used to create the
572
610
/// correction producers used to build fixes for those diagnostics. The
573
611
/// generators used for lint rules are in the [lintProducerMap] .
@@ -757,33 +795,6 @@ class FixProcessor extends BaseProcessor {
757
795
],
758
796
// TODO(brianwilkerson) Add a fix to normalize the path.
759
797
// HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT: [],
760
- HintCode .SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT : [
761
- UpdateSdkConstraints .version_2_2_2,
762
- ],
763
- HintCode .SDK_VERSION_ASYNC_EXPORTED_FROM_CORE : [
764
- UpdateSdkConstraints .version_2_1_0,
765
- ],
766
- HintCode .SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT : [
767
- UpdateSdkConstraints .version_2_2_2,
768
- ],
769
- HintCode .SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT : [
770
- UpdateSdkConstraints .version_2_2_2,
771
- ],
772
- HintCode .SDK_VERSION_EXTENSION_METHODS : [
773
- UpdateSdkConstraints .version_2_6_0,
774
- ],
775
- HintCode .SDK_VERSION_GT_GT_GT_OPERATOR : [
776
- UpdateSdkConstraints .version_2_2_2,
777
- ],
778
- HintCode .SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT : [
779
- UpdateSdkConstraints .version_2_2_2,
780
- ],
781
- HintCode .SDK_VERSION_SET_LITERAL : [
782
- UpdateSdkConstraints .version_2_2_0,
783
- ],
784
- HintCode .SDK_VERSION_UI_AS_CODE : [
785
- UpdateSdkConstraints .version_2_2_2,
786
- ],
787
798
HintCode .TYPE_CHECK_IS_NOT_NULL : [
788
799
UseNotEqNull .newInstance,
789
800
],
@@ -1050,6 +1061,14 @@ class FixProcessor extends BaseProcessor {
1050
1061
args: producer.fixArguments);
1051
1062
}
1052
1063
1064
+ Future <void > computeNonDart (NonDartCorrectionProducer producer) async {
1065
+ producer.configure (context);
1066
+ var builder = ChangeBuilderImpl ();
1067
+ await producer.compute (builder);
1068
+ _addFixFromBuilder (builder, producer.fixKind,
1069
+ args: producer.fixArguments);
1070
+ }
1071
+
1053
1072
var errorCode = error.errorCode;
1054
1073
if (errorCode is LintCode ) {
1055
1074
var generators = lintProducerMap[errorCode.name];
@@ -1065,6 +1084,12 @@ class FixProcessor extends BaseProcessor {
1065
1084
await compute (generator ());
1066
1085
}
1067
1086
}
1087
+ var nonDartGenerators = nonDartProducerMap[errorCode];
1088
+ if (nonDartGenerators != null ) {
1089
+ for (var generator in nonDartGenerators) {
1090
+ await computeNonDart (generator ());
1091
+ }
1092
+ }
1068
1093
var multiGenerators = nonLintMultiProducerMap[errorCode];
1069
1094
if (multiGenerators != null ) {
1070
1095
for (var multiGenerator in multiGenerators) {
0 commit comments