Skip to content

Commit b04639b

Browse files
stereotype441Commit Queue
authored andcommitted
[messages] Specialize SharedToAnalyzerErrorCodeTables for SharedErrorCodeInfo.
Changes the `SharedToAnalyzerErrorCodeTables` class so that its references to error codes all have type `SharedErrorCodeInfo` rather than `ErrorCodeInfo`. There is no functional change because this class only deals with shared errors. (Previously it filtered out non-shared errors using an if-test in the constructor; now it simply does not consider them.) This change will make it easier to make further improvements to the `SharedToAnalyzerErrorCodeTables` class and its clients, since code will be able to assume that any error codes it references are truly shared. Change-Id: I6a6a696400cff9ac3fee2c2396bc15b210562d3d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449680 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 724cb50 commit b04639b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

pkg/analyzer_utilities/lib/messages.dart

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final RegExp placeholderPattern = RegExp(
6565

6666
/// A set of tables mapping between shared and analyzer error codes.
6767
final SharedToAnalyzerErrorCodeTables sharedToAnalyzerErrorCodeTables =
68-
SharedToAnalyzerErrorCodeTables._(frontEndAndSharedMessages);
68+
SharedToAnalyzerErrorCodeTables._(feAnalyzerSharedMessages);
6969

7070
/// Convert a template string (which uses placeholders matching
7171
/// [placeholderPattern]) to an analyzer internal template string (which uses
@@ -989,39 +989,34 @@ class SharedErrorCodeInfo extends CfeStyleErrorCodeInfo {
989989
/// Data tables mapping between shared errors and their corresponding
990990
/// automatically generated analyzer errors.
991991
class SharedToAnalyzerErrorCodeTables {
992-
/// List of CFE errors for which analyzer errors should be automatically
992+
/// List of shared errors for which analyzer errors should be automatically
993993
/// generated, organized by their `index` property.
994-
final List<ErrorCodeInfo?> indexToInfo = [];
994+
final List<SharedErrorCodeInfo?> indexToInfo = [];
995995

996-
/// Map whose values are the CFE errors for which analyzer errors should be
996+
/// Map whose values are the shared errors for which analyzer errors should be
997997
/// automatically generated, and whose keys are the corresponding analyzer
998998
/// error name. (Names are simple identifiers; they are not prefixed by the
999999
/// class name `ParserErrorCode`)
1000-
final Map<String, ErrorCodeInfo> analyzerCodeToInfo = {};
1000+
final Map<String, SharedErrorCodeInfo> analyzerCodeToInfo = {};
10011001

1002-
/// Map whose values are the CFE errors for which analyzer errors should be
1002+
/// Map whose values are the shared errors for which analyzer errors should be
10031003
/// automatically generated, and whose keys are the front end error name.
1004-
final Map<String, ErrorCodeInfo> frontEndCodeToInfo = {};
1004+
final Map<String, SharedErrorCodeInfo> frontEndCodeToInfo = {};
10051005

1006-
/// Map whose keys are the CFE errors for which analyzer errors should be
1006+
/// Map whose keys are the shared errors for which analyzer errors should be
10071007
/// automatically generated, and whose values are the corresponding analyzer
10081008
/// error name. (Names are simple identifiers; they are not prefixed by the
10091009
/// class name `ParserErrorCode`)
1010-
final Map<ErrorCodeInfo, String> infoToAnalyzerCode = {};
1010+
final Map<SharedErrorCodeInfo, String> infoToAnalyzerCode = {};
10111011

1012-
/// Map whose keys are the CFE errors for which analyzer errors should be
1012+
/// Map whose keys are the shared errors for which analyzer errors should be
10131013
/// automatically generated, and whose values are the front end error name.
1014-
final Map<ErrorCodeInfo, String> infoToFrontEndCode = {};
1014+
final Map<SharedErrorCodeInfo, String> infoToFrontEndCode = {};
10151015

1016-
SharedToAnalyzerErrorCodeTables._(
1017-
Map<String, CfeStyleErrorCodeInfo> messages,
1018-
) {
1016+
SharedToAnalyzerErrorCodeTables._(Map<String, SharedErrorCodeInfo> messages) {
10191017
for (var entry in messages.entries) {
10201018
var errorCodeInfo = entry.value;
10211019
var index = errorCodeInfo.index;
1022-
if (index == null || errorCodeInfo.analyzerCodes.length != 1) {
1023-
continue;
1024-
}
10251020
var frontEndCode = entry.key;
10261021
if (index < 1) {
10271022
throw '''
@@ -1041,7 +1036,7 @@ dart pkg/front_end/tool/generate_messages.dart
10411036
indexToInfo[index] = errorCodeInfo;
10421037
frontEndCodeToInfo[frontEndCode] = errorCodeInfo;
10431038
infoToFrontEndCode[errorCodeInfo] = frontEndCode;
1044-
var analyzerCodeLong = errorCodeInfo.analyzerCodes.single;
1039+
var analyzerCodeLong = errorCodeInfo.analyzerCode;
10451040
var expectedPrefix = 'ParserErrorCode.';
10461041
if (!analyzerCodeLong.startsWith(expectedPrefix)) {
10471042
throw 'Expected all analyzer error codes to be prefixed with '

0 commit comments

Comments
 (0)