new "modifier out of order" error code

This replaces the const-after-factory error code
with a more general modifier-out-of-order error code.

Change-Id: I71baf2c96656241475c344cb33b887d8e0d456fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99481
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index bdffa62..3b88ce1 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -496,6 +496,7 @@
   ParserErrorCode.MISSING_TYPEDEF_PARAMETERS,
   ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH,
   ParserErrorCode.MIXED_PARAMETER_GROUPS,
+  ParserErrorCode.MODIFIER_OUT_OF_ORDER,
   ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES,
   ParserErrorCode.MULTIPLE_ON_CLAUSES,
   ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES,
diff --git a/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart b/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
index 6e31a4b..de2684c 100644
--- a/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
+++ b/pkg/analyzer/lib/src/dart/error/syntactic_errors.dart
@@ -65,7 +65,8 @@
 
   static const ParserErrorCode COLON_IN_PLACE_OF_IN = _COLON_IN_PLACE_OF_IN;
 
-  static const ParserErrorCode CONST_AFTER_FACTORY = _CONST_AFTER_FACTORY;
+  // TODO(danrubel): Remove this unused error code
+  static const ParserErrorCode CONST_AFTER_FACTORY = _MODIFIER_OUT_OF_ORDER;
 
   static const ParserErrorCode CONST_AND_COVARIANT = _CONST_AND_COVARIANT;
 
@@ -521,6 +522,8 @@
       "Can't have both positional and named parameters in a single parameter list.",
       correction: "Try choosing a single style of optional parameters.");
 
+  static const ParserErrorCode MODIFIER_OUT_OF_ORDER = _MODIFIER_OUT_OF_ORDER;
+
   static const ParserErrorCode MULTIPLE_EXTENDS_CLAUSES =
       _MULTIPLE_EXTENDS_CLAUSES;
 
diff --git a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
index c3ca203..c02bde2 100644
--- a/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
+++ b/pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart
@@ -63,7 +63,7 @@
   _CLASS_IN_CLASS,
   _COLON_IN_PLACE_OF_IN,
   _CONSTRUCTOR_WITH_RETURN_TYPE,
-  _CONST_AFTER_FACTORY,
+  _MODIFIER_OUT_OF_ORDER,
   _CONST_AND_COVARIANT,
   _CONST_AND_FINAL,
   _CONST_AND_VAR,
@@ -141,11 +141,6 @@
     'CONSTRUCTOR_WITH_RETURN_TYPE', r"Constructors can't have a return type.",
     correction: "Try removing the return type.");
 
-const ParserErrorCode _CONST_AFTER_FACTORY = const ParserErrorCode(
-    'CONST_AFTER_FACTORY',
-    r"The modifier 'const' should be before the modifier 'factory'.",
-    correction: "Try re-ordering the modifiers.");
-
 const ParserErrorCode _CONST_AND_COVARIANT = const ParserErrorCode(
     'CONST_AND_COVARIANT',
     r"Members can't be declared to be both 'const' and 'covariant'.",
@@ -450,6 +445,11 @@
 const ParserErrorCode _MISSING_STATEMENT =
     const ParserErrorCode('MISSING_STATEMENT', r"Expected a statement.");
 
+const ParserErrorCode _MODIFIER_OUT_OF_ORDER = const ParserErrorCode(
+    'MODIFIER_OUT_OF_ORDER',
+    r"The modifier '#string' should be before the modifier '#string2'.",
+    correction: "Try re-ordering the modifiers.");
+
 const ParserErrorCode _MULTIPLE_EXTENDS_CLAUSES = const ParserErrorCode(
     'MULTIPLE_EXTENDS_CLAUSES',
     r"Each class definition can have at most one extends clause.",
diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart
index 5aef022..69942af 100644
--- a/pkg/analyzer/test/src/task/options_test.dart
+++ b/pkg/analyzer/test/src/task/options_test.dart
@@ -11,6 +11,7 @@
 import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
 import 'package:analyzer/src/analysis_options/error/option_codes.dart';
 import 'package:analyzer/src/dart/error/hint_codes.dart';
+import 'package:analyzer/src/dart/error/syntactic_errors.dart';
 import 'package:analyzer/src/error/codes.dart';
 import 'package:analyzer/src/file_system/file_system.dart';
 import 'package:analyzer/src/generated/engine.dart';
@@ -234,6 +235,8 @@
         removeCode(StrongModeCode.TOP_LEVEL_INSTANCE_METHOD);
       } else if (errorType == TodoCode) {
         declaredNames.remove('TODO_REGEX');
+      } else if (errorType == ParserErrorCode) {
+        declaredNames.remove('CONST_AFTER_FACTORY');
       }
 
       // Assert that all remaining declared names are in errorCodeValues
diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
index b6ba1c0..01e5f4b 100644
--- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
+++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
@@ -896,17 +896,6 @@
     message: r"""This is the type variable.""");
 
 // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
-const Code<Null> codeConstAfterFactory = messageConstAfterFactory;
-
-// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
-const MessageCode messageConstAfterFactory = const MessageCode(
-    "ConstAfterFactory",
-    index: 56,
-    message:
-        r"""The modifier 'const' should be before the modifier 'factory'.""",
-    tip: r"""Try re-ordering the modifiers.""");
-
-// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
 const Code<Null> codeConstAndCovariant = messageConstAndCovariant;
 
 // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -6912,6 +6901,36 @@
 }
 
 // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const Template<
+    Message Function(
+        String string,
+        String
+            string2)> templateModifierOutOfOrder = const Template<
+        Message Function(String string, String string2)>(
+    messageTemplate:
+        r"""The modifier '#string' should be before the modifier '#string2'.""",
+    tipTemplate: r"""Try re-ordering the modifiers.""",
+    withArguments: _withArgumentsModifierOutOfOrder);
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+const Code<Message Function(String string, String string2)>
+    codeModifierOutOfOrder =
+    const Code<Message Function(String string, String string2)>(
+        "ModifierOutOfOrder", templateModifierOutOfOrder,
+        index: 56);
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
+Message _withArgumentsModifierOutOfOrder(String string, String string2) {
+  if (string.isEmpty) throw 'No string provided';
+  if (string2.isEmpty) throw 'No string provided';
+  return new Message(codeModifierOutOfOrder,
+      message:
+          """The modifier '${string}' should be before the modifier '${string2}'.""",
+      tip: """Try re-ordering the modifiers.""",
+      arguments: {'string': string, 'string2': string2});
+}
+
+// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
 const Code<Null> codeMoreThanOneSuperOrThisInitializer =
     messageMoreThanOneSuperOrThisInitializer;
 
diff --git a/pkg/front_end/lib/src/fasta/parser/modifier_context.dart b/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
index 83d9a8d..3a5c8d1 100644
--- a/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
+++ b/pkg/front_end/lib/src/fasta/parser/modifier_context.dart
@@ -240,7 +240,8 @@
       varFinalOrConst = constToken = next;
 
       if (afterFactory) {
-        parser.reportRecoverableError(next, fasta.messageConstAfterFactory);
+        parser.reportRecoverableError(next,
+            fasta.templateModifierOutOfOrder.withArguments('const', 'factory'));
       }
       return next;
     }
diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status
index 0427629..d900666 100644
--- a/pkg/front_end/messages.status
+++ b/pkg/front_end/messages.status
@@ -51,7 +51,6 @@
 ConflictsWithSetter/example: Fail
 ConflictsWithSetterWarning/example: Fail
 ConflictsWithTypeVariable/example: Fail
-ConstAfterFactory/script1: Fail
 ConstAndCovariant/script2: Fail
 ConstAndFinal/declaration3: Fail
 ConstAndFinal/declaration4: Fail
@@ -277,6 +276,7 @@
 MissingMain/example: Fail
 MissingPrefixInDeferredImport/example: Fail
 MixinInferenceNoMatchingClass/example: Fail
+ModifierOutOfOrder/script1: Fail
 MultipleExtends/script: Fail
 MultipleImplements/script: Fail
 MultipleLibraryDirectives/example: Fail
diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml
index ad73e94..962bdb7 100644
--- a/pkg/front_end/messages.yaml
+++ b/pkg/front_end/messages.yaml
@@ -632,11 +632,11 @@
   tip: "Try using a constructor or factory that is 'const'."
   analyzerCode: NOT_CONSTANT_EXPRESSION
 
-ConstAfterFactory:
+ModifierOutOfOrder:
   index: 56
-  template: "The modifier 'const' should be before the modifier 'factory'."
+  template: "The modifier '#string' should be before the modifier '#string2'."
   tip: "Try re-ordering the modifiers."
-  analyzerCode: ParserErrorCode.CONST_AFTER_FACTORY
+  analyzerCode: ParserErrorCode.MODIFIER_OUT_OF_ORDER
   script:
     - "class C { factory const C() = prefix.B.foo; }"