Skip to content

Commit 4c94422

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Change ErrorCodeInfo.toAnalyzerCode to accept ErrorClassInfo.
Previously, `ErrorCodeInfo.toAnalyzerCode` didn't know anything about the error class it was generating an analyzer code for, other than the class name (which was passed in via a `className` parameter). Changing this parameter to an `ErrorClassInfo` type paves the way for a follow-up CL in which I plan to generalize `ErrorCodeInfo.toAnalyzerCode` so that it can generate analyzer error codes that support `.withArguments()` (similar to how CFE error formatting works). To make this work, I had to create an instance of `ErrorClassInfo` in `generate_lints.dart`, to represent the linter class `LinterLintCode`. Change-Id: I160e27a46602da13f4757393fdaad4bc2f15d50e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442165 Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 96efc10 commit 4c94422

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ abstract class ErrorCodeInfo {
602602
///
603603
/// [diagnosticCode] is the name of the error code to be generated.
604604
String toAnalyzerCode(
605-
String className,
605+
ErrorClassInfo errorClassInfo,
606606
String diagnosticCode, {
607607
String? sharedNameReference,
608608
required bool useExplicitConst,
609609
}) {
610610
var out = StringBuffer();
611611
if (useExplicitConst) out.writeln('const ');
612-
out.writeln('$className(');
612+
out.writeln('${errorClassInfo.name}(');
613613
out.writeln(
614614
'${sharedNameReference ?? "'${sharedName ?? diagnosticCode}'"},',
615615
);

pkg/analyzer/tool/messages/generate.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ library;
158158
out.writeln(' static const ${errorClass.name} $errorName =');
159159
out.writeln(
160160
errorCodeInfo.toAnalyzerCode(
161-
errorClass.name,
161+
errorClass,
162162
errorName,
163163
useExplicitConst: file.shouldUseExplicitConst,
164164
),

pkg/linter/tool/generate_lints.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ const String generatedCodesPath = 'linter/lib/src/lint_codes.g.dart';
2323

2424
const String generatedNamesPath = 'linter/lib/src/lint_names.g.dart';
2525

26+
const lintCodesFile = GeneratedErrorCodeFile(
27+
path: generatedCodesPath,
28+
preferredImportUri: 'package:linter/src/lint_codes.dart',
29+
);
30+
31+
const linterLintCodeInfo = ErrorClassInfo(
32+
file: lintCodesFile,
33+
name: 'LinterLintCode',
34+
type: 'LINT',
35+
);
36+
2637
GeneratedFile get generatedCodesFile =>
2738
GeneratedFile(generatedCodesPath, (pkgRoot) async {
2839
var out = StringBuffer('''
@@ -61,7 +72,7 @@ class LinterLintCode extends LintCode {
6172
out.writeln(' static const LintCode $errorName =');
6273
out.writeln(
6374
codeInfo.toAnalyzerCode(
64-
'LinterLintCode',
75+
linterLintCodeInfo,
6576
errorName,
6677
sharedNameReference: 'LintNames.$lintName',
6778
useExplicitConst: false,

0 commit comments

Comments
 (0)