Skip to content

Commit ba92b78

Browse files
committed
Move errors from StaticWarningCode to CompileTimeErrorCode.
Bug: #42821 Change-Id: I153c48d7a2e4a02026928e6203aacf8f2dc029ba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155849 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 0fcd35f commit ba92b78

File tree

367 files changed

+8590
-8649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

367 files changed

+8590
-8649
lines changed

pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ class StatementCompletionProcessor {
975975
if (catchNode.onKeyword != null) {
976976
if (catchNode.exceptionType.length == 0 ||
977977
null !=
978-
_findError(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE,
978+
_findError(CompileTimeErrorCode.NON_TYPE_IN_CATCH_CLAUSE,
979979
partialMatch: "name 'catch")) {
980980
var src = utils.getNodeText(catchNode);
981981
if (src.startsWith(RegExp(r'on[ \t]+'))) {

pkg/analysis_server/lib/src/services/correction/fix.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,29 @@ import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1414

1515
/// Return true if this [errorCode] is likely to have a fix associated with it.
1616
bool hasFix(ErrorCode errorCode) =>
17-
errorCode == StaticWarningCode.UNDEFINED_CLASS_BOOLEAN ||
18-
errorCode == StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER ||
19-
errorCode == StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR ||
17+
errorCode == CompileTimeErrorCode.UNDEFINED_CLASS_BOOLEAN ||
18+
errorCode == CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER ||
19+
errorCode == CompileTimeErrorCode.NEW_WITH_UNDEFINED_CONSTRUCTOR ||
2020
errorCode ==
21-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE ||
21+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE ||
2222
errorCode ==
23-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO ||
23+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO ||
2424
errorCode ==
25-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE ||
25+
CompileTimeErrorCode
26+
.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE ||
2627
errorCode ==
27-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR ||
28+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR ||
2829
errorCode ==
29-
StaticWarningCode
30+
CompileTimeErrorCode
3031
.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS ||
31-
errorCode == StaticWarningCode.CAST_TO_NON_TYPE ||
32-
errorCode == StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME ||
33-
errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED ||
34-
errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1 ||
35-
errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2 ||
36-
errorCode == StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS ||
37-
errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER ||
32+
errorCode == CompileTimeErrorCode.CAST_TO_NON_TYPE ||
33+
errorCode == CompileTimeErrorCode.TYPE_TEST_WITH_UNDEFINED_NAME ||
34+
errorCode == CompileTimeErrorCode.FINAL_NOT_INITIALIZED ||
35+
errorCode == CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1 ||
36+
errorCode == CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2 ||
37+
errorCode ==
38+
CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS ||
39+
errorCode == CompileTimeErrorCode.UNDEFINED_IDENTIFIER ||
3840
errorCode ==
3941
CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE ||
4042
errorCode == CompileTimeErrorCode.INTEGER_LITERAL_IMPRECISE_AS_DOUBLE ||

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 111 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ class FixProcessor extends BaseProcessor {
490490
/// generators used for lint rules are in the [lintMultiProducerMap].
491491
static const Map<ErrorCode, List<MultiProducerGenerator>>
492492
nonLintMultiProducerMap = {
493+
CompileTimeErrorCode.CAST_TO_NON_TYPE: [
494+
ImportLibrary.forType,
495+
],
493496
CompileTimeErrorCode.CONST_WITH_NON_TYPE: [
494497
ImportLibrary.forType,
495498
],
@@ -512,13 +515,25 @@ class FixProcessor extends BaseProcessor {
512515
CompileTimeErrorCode.MIXIN_OF_NON_CLASS: [
513516
ImportLibrary.forType,
514517
],
518+
CompileTimeErrorCode.NEW_WITH_NON_TYPE: [
519+
ImportLibrary.forType,
520+
],
515521
CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_EXPLICIT: [
516522
AddSuperConstructorInvocation.newInstance,
517523
],
518524
CompileTimeErrorCode.NO_DEFAULT_SUPER_CONSTRUCTOR_IMPLICIT: [
519525
AddSuperConstructorInvocation.newInstance,
520526
CreateConstructorSuper.newInstance,
521527
],
528+
CompileTimeErrorCode.NON_TYPE_IN_CATCH_CLAUSE: [
529+
ImportLibrary.forType,
530+
],
531+
CompileTimeErrorCode.NOT_A_TYPE: [
532+
ImportLibrary.forType,
533+
],
534+
CompileTimeErrorCode.TYPE_TEST_WITH_UNDEFINED_NAME: [
535+
ImportLibrary.forType,
536+
],
522537
CompileTimeErrorCode.UNDEFINED_ANNOTATION: [
523538
ImportLibrary.forTopLevelVariable,
524539
ImportLibrary.forType,
@@ -529,6 +544,12 @@ class FixProcessor extends BaseProcessor {
529544
CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER_DEFAULT: [
530545
AddSuperConstructorInvocation.newInstance,
531546
],
547+
CompileTimeErrorCode.UNDEFINED_IDENTIFIER: [
548+
ImportLibrary.forExtension,
549+
ImportLibrary.forFunction,
550+
ImportLibrary.forTopLevelVariable,
551+
ImportLibrary.forType,
552+
],
532553
CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER: [
533554
ChangeArgumentName.newInstance,
534555
],
@@ -541,27 +562,6 @@ class FixProcessor extends BaseProcessor {
541562
HintCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE: [
542563
ImportLibrary.dartAsync,
543564
],
544-
StaticWarningCode.CAST_TO_NON_TYPE: [
545-
ImportLibrary.forType,
546-
],
547-
StaticWarningCode.NEW_WITH_NON_TYPE: [
548-
ImportLibrary.forType,
549-
],
550-
StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE: [
551-
ImportLibrary.forType,
552-
],
553-
StaticWarningCode.NOT_A_TYPE: [
554-
ImportLibrary.forType,
555-
],
556-
StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME: [
557-
ImportLibrary.forType,
558-
],
559-
StaticWarningCode.UNDEFINED_IDENTIFIER: [
560-
ImportLibrary.forExtension,
561-
ImportLibrary.forFunction,
562-
ImportLibrary.forTopLevelVariable,
563-
ImportLibrary.forType,
564-
],
565565
StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT: [
566566
ImportLibrary.forType,
567567
],
@@ -584,12 +584,31 @@ class FixProcessor extends BaseProcessor {
584584
/// correction producers used to build fixes for those diagnostics. The
585585
/// generators used for lint rules are in the [lintProducerMap].
586586
static const Map<ErrorCode, List<ProducerGenerator>> nonLintProducerMap = {
587+
CompileTimeErrorCode.ASSIGNMENT_TO_FINAL: [
588+
MakeFieldNotFinal.newInstance,
589+
],
590+
CompileTimeErrorCode.ASSIGNMENT_TO_FINAL_LOCAL: [
591+
MakeVariableNotFinal.newInstance,
592+
],
593+
CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE: [
594+
WrapInText.newInstance,
595+
],
587596
CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT: [
588597
AddAsync.newInstance,
589598
],
590599
CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT: [
591600
AddAsync.newInstance,
592601
],
602+
CompileTimeErrorCode.CAST_TO_NON_TYPE: [
603+
ChangeTo.classOrMixin,
604+
CreateClass.newInstance,
605+
CreateMixin.newInstance,
606+
],
607+
CompileTimeErrorCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER: [
608+
CreateMissingOverrides.newInstance,
609+
CreateNoSuchMethod.newInstance,
610+
MakeClassAbstract.newInstance,
611+
],
593612
CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE: [
594613
UseConst.newInstance,
595614
],
@@ -619,6 +638,19 @@ class FixProcessor extends BaseProcessor {
619638
CreateConstructor.newInstance,
620639
ConvertToNamedArguments.newInstance,
621640
],
641+
CompileTimeErrorCode.FINAL_NOT_INITIALIZED: [
642+
AddLate.newInstance,
643+
CreateConstructorForFinalFields.newInstance,
644+
],
645+
CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1: [
646+
AddFieldFormalParameters.newInstance,
647+
],
648+
CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2: [
649+
AddFieldFormalParameters.newInstance,
650+
],
651+
CompileTimeErrorCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS: [
652+
AddFieldFormalParameters.newInstance,
653+
],
622654
CompileTimeErrorCode.IMPLEMENTS_NON_CLASS: [
623655
ChangeTo.classOrMixin,
624656
CreateClass.newInstance,
@@ -643,6 +675,43 @@ class FixProcessor extends BaseProcessor {
643675
ChangeTo.classOrMixin,
644676
CreateClass.newInstance,
645677
],
678+
CompileTimeErrorCode.NEW_WITH_NON_TYPE: [
679+
ChangeTo.classOrMixin,
680+
],
681+
CompileTimeErrorCode.NEW_WITH_UNDEFINED_CONSTRUCTOR: [
682+
CreateConstructor.newInstance,
683+
],
684+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS:
685+
[
686+
CreateMissingOverrides.newInstance,
687+
CreateNoSuchMethod.newInstance,
688+
MakeClassAbstract.newInstance,
689+
],
690+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR: [
691+
CreateMissingOverrides.newInstance,
692+
CreateNoSuchMethod.newInstance,
693+
MakeClassAbstract.newInstance,
694+
],
695+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE: [
696+
CreateMissingOverrides.newInstance,
697+
CreateNoSuchMethod.newInstance,
698+
MakeClassAbstract.newInstance,
699+
],
700+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE: [
701+
CreateMissingOverrides.newInstance,
702+
CreateNoSuchMethod.newInstance,
703+
MakeClassAbstract.newInstance,
704+
],
705+
CompileTimeErrorCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO: [
706+
CreateMissingOverrides.newInstance,
707+
CreateNoSuchMethod.newInstance,
708+
MakeClassAbstract.newInstance,
709+
],
710+
CompileTimeErrorCode.NOT_A_TYPE: [
711+
ChangeTo.classOrMixin,
712+
CreateClass.newInstance,
713+
CreateMixin.newInstance,
714+
],
646715
CompileTimeErrorCode.NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD: [
647716
AddLate.newInstance,
648717
],
@@ -658,6 +727,11 @@ class FixProcessor extends BaseProcessor {
658727
CompileTimeErrorCode.NULLABLE_TYPE_IN_WITH_CLAUSE: [
659728
RemoveQuestionMark.newInstance,
660729
],
730+
CompileTimeErrorCode.TYPE_TEST_WITH_UNDEFINED_NAME: [
731+
ChangeTo.classOrMixin,
732+
CreateClass.newInstance,
733+
CreateMixin.newInstance,
734+
],
661735
CompileTimeErrorCode.UNDEFINED_ANNOTATION: [
662736
ChangeTo.annotation,
663737
CreateClass.newInstance,
@@ -667,6 +741,9 @@ class FixProcessor extends BaseProcessor {
667741
CreateClass.newInstance,
668742
CreateMixin.newInstance,
669743
],
744+
CompileTimeErrorCode.UNDEFINED_CLASS_BOOLEAN: [
745+
ReplaceBooleanWithBool.newInstance,
746+
],
670747
CompileTimeErrorCode.UNDEFINED_EXTENSION_GETTER: [
671748
ChangeTo.getterOrSetter,
672749
CreateGetter.newInstance,
@@ -679,6 +756,19 @@ class FixProcessor extends BaseProcessor {
679756
ChangeTo.getterOrSetter,
680757
CreateSetter.newInstance,
681758
],
759+
CompileTimeErrorCode.UNDEFINED_IDENTIFIER: [
760+
ChangeTo.getterOrSetter,
761+
CreateClass.newInstance,
762+
CreateField.newInstance,
763+
CreateGetter.newInstance,
764+
CreateLocalVariable.newInstance,
765+
CreateMethodOrFunction.newInstance,
766+
CreateMixin.newInstance,
767+
CreateSetter.newInstance,
768+
],
769+
CompileTimeErrorCode.UNDEFINED_IDENTIFIER_AWAIT: [
770+
AddAsync.newInstance,
771+
],
682772
CompileTimeErrorCode.UNDEFINED_NAMED_PARAMETER: [
683773
AddMissingParameterNamed.newInstance,
684774
ConvertFlutterChild.newInstance,
@@ -908,101 +998,12 @@ class FixProcessor extends BaseProcessor {
908998
// updated so that only the appropriate subset is generated.
909999
QualifyReference.newInstance,
9101000
],
911-
StaticWarningCode.ASSIGNMENT_TO_FINAL: [
912-
MakeFieldNotFinal.newInstance,
913-
],
914-
StaticWarningCode.ASSIGNMENT_TO_FINAL_LOCAL: [
915-
MakeVariableNotFinal.newInstance,
916-
],
917-
StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE: [
918-
WrapInText.newInstance,
919-
],
920-
StaticWarningCode.CAST_TO_NON_TYPE: [
921-
ChangeTo.classOrMixin,
922-
CreateClass.newInstance,
923-
CreateMixin.newInstance,
924-
],
925-
StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER: [
926-
CreateMissingOverrides.newInstance,
927-
CreateNoSuchMethod.newInstance,
928-
MakeClassAbstract.newInstance,
929-
],
9301001
StaticWarningCode.DEAD_NULL_AWARE_EXPRESSION: [
9311002
RemoveDeadIfNull.newInstance,
9321003
],
933-
StaticWarningCode.FINAL_NOT_INITIALIZED: [
934-
AddLate.newInstance,
935-
CreateConstructorForFinalFields.newInstance,
936-
],
937-
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1: [
938-
AddFieldFormalParameters.newInstance,
939-
],
940-
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2: [
941-
AddFieldFormalParameters.newInstance,
942-
],
943-
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS: [
944-
AddFieldFormalParameters.newInstance,
945-
],
9461004
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH: [
9471005
AddMissingEnumCaseClauses.newInstance,
9481006
],
949-
StaticWarningCode.NEW_WITH_NON_TYPE: [
950-
ChangeTo.classOrMixin,
951-
],
952-
StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR: [
953-
CreateConstructor.newInstance,
954-
],
955-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FIVE_PLUS: [
956-
CreateMissingOverrides.newInstance,
957-
CreateNoSuchMethod.newInstance,
958-
MakeClassAbstract.newInstance,
959-
],
960-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR: [
961-
CreateMissingOverrides.newInstance,
962-
CreateNoSuchMethod.newInstance,
963-
MakeClassAbstract.newInstance,
964-
],
965-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE: [
966-
CreateMissingOverrides.newInstance,
967-
CreateNoSuchMethod.newInstance,
968-
MakeClassAbstract.newInstance,
969-
],
970-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_THREE: [
971-
CreateMissingOverrides.newInstance,
972-
CreateNoSuchMethod.newInstance,
973-
MakeClassAbstract.newInstance,
974-
],
975-
StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_TWO: [
976-
CreateMissingOverrides.newInstance,
977-
CreateNoSuchMethod.newInstance,
978-
MakeClassAbstract.newInstance,
979-
],
980-
StaticWarningCode.NOT_A_TYPE: [
981-
ChangeTo.classOrMixin,
982-
CreateClass.newInstance,
983-
CreateMixin.newInstance,
984-
],
985-
StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME: [
986-
ChangeTo.classOrMixin,
987-
CreateClass.newInstance,
988-
CreateMixin.newInstance,
989-
],
990-
StaticWarningCode.UNDEFINED_CLASS_BOOLEAN: [
991-
ReplaceBooleanWithBool.newInstance,
992-
],
993-
StaticWarningCode.UNDEFINED_IDENTIFIER: [
994-
ChangeTo.getterOrSetter,
995-
CreateClass.newInstance,
996-
CreateField.newInstance,
997-
CreateGetter.newInstance,
998-
CreateLocalVariable.newInstance,
999-
CreateMethodOrFunction.newInstance,
1000-
CreateMixin.newInstance,
1001-
CreateSetter.newInstance,
1002-
],
1003-
StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT: [
1004-
AddAsync.newInstance,
1005-
],
10061007
};
10071008

10081009
final DartFixContext fixContext;

pkg/analysis_server/test/analysis/notification_errors_test.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,17 +426,22 @@ version: 1.3.2
426426
Future<void> test_StaticWarning() async {
427427
createProject();
428428
addTestFile('''
429-
main() {
430-
final int foo;
431-
print(foo);
429+
enum E {e1, e2}
430+
431+
void f(E e) {
432+
switch (e) {
433+
case E.e1:
434+
print(0);
435+
break;
436+
}
432437
}
433438
''');
434439
await waitForTasksFinished();
435440
await pumpEventQueue(times: 5000);
436441
var errors = filesErrors[testFile];
437442
expect(errors, hasLength(1));
438443
var error = errors[0];
439-
expect(error.severity, AnalysisErrorSeverity.ERROR);
444+
expect(error.severity, AnalysisErrorSeverity.WARNING);
440445
expect(error.type, AnalysisErrorType.STATIC_WARNING);
441446
}
442447
}

0 commit comments

Comments
 (0)