Skip to content

Commit 7a4c651

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Rename 'errorCode' parameters in ErrorReporter
Work towards #60635 Change-Id: I4a3d320585967a4d2e8cbed430d2a67aa3f905fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430040 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent efa2870 commit 7a4c651

26 files changed

+205
-177
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CodeFragmentParser {
8383
errorReporter.atOffset(
8484
offset: token.offset + delta,
8585
length: token.length,
86-
errorCode: TransformSetErrorCode.wrongToken,
86+
diagnosticCode: TransformSetErrorCode.wrongToken,
8787
arguments: ['.', token.kind.displayName],
8888
);
8989
return null;
@@ -113,7 +113,7 @@ class CodeFragmentParser {
113113
errorReporter.atOffset(
114114
offset: token.offset + delta,
115115
length: token.length,
116-
errorCode: TransformSetErrorCode.unexpectedToken,
116+
diagnosticCode: TransformSetErrorCode.unexpectedToken,
117117
arguments: [token.kind.displayName],
118118
);
119119
return null;
@@ -151,7 +151,7 @@ class CodeFragmentParser {
151151
errorReporter.atOffset(
152152
offset: offset + delta,
153153
length: length,
154-
errorCode: TransformSetErrorCode.missingToken,
154+
diagnosticCode: TransformSetErrorCode.missingToken,
155155
arguments: [validKindsDisplayString()],
156156
);
157157
return null;
@@ -160,7 +160,7 @@ class CodeFragmentParser {
160160
errorReporter.atOffset(
161161
offset: token.offset + delta,
162162
length: token.length,
163-
errorCode: TransformSetErrorCode.wrongToken,
163+
diagnosticCode: TransformSetErrorCode.wrongToken,
164164
arguments: [validKindsDisplayString(), token.kind.displayName],
165165
);
166166
return null;
@@ -233,7 +233,7 @@ class CodeFragmentParser {
233233
errorReporter.atOffset(
234234
offset: token.offset + delta,
235235
length: token.length,
236-
errorCode: TransformSetErrorCode.unknownAccessor,
236+
diagnosticCode: TransformSetErrorCode.unknownAccessor,
237237
arguments: [identifier],
238238
);
239239
return null;
@@ -313,7 +313,7 @@ class CodeFragmentParser {
313313
errorReporter.atOffset(
314314
offset: token.offset + delta,
315315
length: token.length,
316-
errorCode: TransformSetErrorCode.undefinedVariable,
316+
diagnosticCode: TransformSetErrorCode.undefinedVariable,
317317
arguments: [variableName],
318318
);
319319
return null;
@@ -344,7 +344,7 @@ class CodeFragmentParser {
344344
errorReporter.atOffset(
345345
offset: offset,
346346
length: length,
347-
errorCode: TransformSetErrorCode.expectedPrimary,
347+
diagnosticCode: TransformSetErrorCode.expectedPrimary,
348348
);
349349
return null;
350350
}
@@ -471,7 +471,7 @@ class _CodeFragmentScanner {
471471
errorReporter.atOffset(
472472
offset: offset + delta,
473473
length: 1,
474-
errorCode: TransformSetErrorCode.invalidCharacter,
474+
diagnosticCode: TransformSetErrorCode.invalidCharacter,
475475
arguments: [content.substring(offset, offset + 1)],
476476
);
477477
return null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TransformSetParser {
195195
errorReporter.atOffset(
196196
offset: templateOffset + variableStart,
197197
length: 2,
198-
errorCode: TransformSetErrorCode.missingTemplateEnd,
198+
diagnosticCode: TransformSetErrorCode.missingTemplateEnd,
199199
);
200200
// Ignore the invalid component, treating it as if it extended to the
201201
// end of the template.
@@ -207,7 +207,7 @@ class TransformSetParser {
207207
errorReporter.atOffset(
208208
offset: templateOffset + template.indexOf(name, variableStart),
209209
length: name.length,
210-
errorCode: TransformSetErrorCode.undefinedVariable,
210+
diagnosticCode: TransformSetErrorCode.undefinedVariable,
211211
arguments: [name],
212212
);
213213
// Ignore the invalid component.
@@ -261,7 +261,7 @@ class TransformSetParser {
261261
errorReporter.atOffset(
262262
offset: offset,
263263
length: length,
264-
errorCode: TransformSetErrorCode.yamlSyntaxError,
264+
diagnosticCode: TransformSetErrorCode.yamlSyntaxError,
265265
arguments: [e.message],
266266
);
267267
}
@@ -280,7 +280,7 @@ class TransformSetParser {
280280
errorReporter.atOffset(
281281
offset: span.start.offset,
282282
length: span.length,
283-
errorCode: code,
283+
diagnosticCode: code,
284284
arguments: arguments,
285285
);
286286
}

pkg/analyzer/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
* Deprecate `InterfaceElement.constructors2`, use `constructors` instead.
3333
* Deprecate `InterfaceFragment.constructors2`, use `constructors` instead.
3434
* Deprecate `JoinPatternVariableElement.variables2`, use `variables` instead.
35+
* Deprecate `ErrorReporter.atOffset`'s `errorCode` parameter; use
36+
`diagnosticCode` instead.
3537

3638
## 7.4.1
3739
* Restore `InstanceElement.augmented` getter.

pkg/analyzer/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4464,7 +4464,7 @@ package:analyzer/error/listener.dart:
44644464
atElement2 (method: void Function(Element, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}), experimental)
44654465
atEntity (method: void Function(SyntacticEntity, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
44664466
atNode (method: void Function(AstNode, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
4467-
atOffset (method: void Function({List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data, required DiagnosticCode errorCode, required int length, required int offset}))
4467+
atOffset (method: void Function({List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data, DiagnosticCode? diagnosticCode, DiagnosticCode? errorCode, required int length, required int offset}))
44684468
atSourceSpan (method: void Function(SourceSpan, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
44694469
atToken (method: void Function(Token, DiagnosticCode, {List<Object>? arguments, List<DiagnosticMessage>? contextMessages, Object? data}))
44704470
reportError (method: void Function(Diagnostic))

pkg/analyzer/lib/error/listener.dart

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ class ErrorReporter {
6565

6666
Source get source => _source;
6767

68-
/// Report a diagnostic with the given [errorCode] and [arguments].
68+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
69+
///
6970
/// The location of the diagnostic will be the name of the [node].
7071
void atConstructorDeclaration(
7172
ConstructorDeclaration node,
72-
DiagnosticCode errorCode, {
73+
DiagnosticCode diagnosticCode, {
7374
List<Object>? arguments,
7475
List<DiagnosticMessage>? contextMessages,
7576
Object? data,
@@ -82,27 +83,28 @@ class ErrorReporter {
8283
atOffset(
8384
offset: offset,
8485
length: nameToken.end - offset,
85-
errorCode: errorCode,
86+
diagnosticCode: diagnosticCode,
8687
arguments: arguments,
8788
);
8889
} else {
89-
atNode(node.returnType, errorCode, arguments: arguments);
90+
atNode(node.returnType, diagnosticCode, arguments: arguments);
9091
}
9192
}
9293

93-
/// Report an error with the given [diagnosticCode] and [arguments].
94-
/// The [element] is used to compute the location of the error.
94+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
95+
///
96+
/// The [element] is used to compute the location of the diagnostic.
9597
@experimental
9698
void atElement2(
97-
Element element2,
99+
Element element,
98100
DiagnosticCode diagnosticCode, {
99101
List<Object>? arguments,
100102
List<DiagnosticMessage>? contextMessages,
101103
Object? data,
102104
}) {
103-
var nonSynthetic = element2.nonSynthetic2;
105+
var nonSynthetic = element.nonSynthetic2;
104106
atOffset(
105-
errorCode: diagnosticCode,
107+
diagnosticCode: diagnosticCode,
106108
offset: nonSynthetic.firstFragment.nameOffset2 ?? -1,
107109
length: nonSynthetic.name3?.length ?? 0,
108110
arguments: arguments,
@@ -111,17 +113,18 @@ class ErrorReporter {
111113
);
112114
}
113115

114-
/// Report an error with the given [errorCode] and [arguments].
115-
/// The [entity] is used to compute the location of the error.
116+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
117+
///
118+
/// The [entity] is used to compute the location of the diagnostic.
116119
void atEntity(
117120
SyntacticEntity entity,
118-
DiagnosticCode errorCode, {
121+
DiagnosticCode diagnosticCode, {
119122
List<Object>? arguments,
120123
List<DiagnosticMessage>? contextMessages,
121124
Object? data,
122125
}) {
123126
atOffset(
124-
errorCode: errorCode,
127+
diagnosticCode: diagnosticCode,
125128
offset: entity.offset,
126129
length: entity.length,
127130
arguments: arguments,
@@ -130,8 +133,9 @@ class ErrorReporter {
130133
);
131134
}
132135

133-
/// Report an error with the given [diagnosticCode] and [arguments].
134-
/// The [node] is used to compute the location of the error.
136+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
137+
///
138+
/// The [node] is used to compute the location of the diagnostic.
135139
void atNode(
136140
AstNode node,
137141
DiagnosticCode diagnosticCode, {
@@ -140,7 +144,7 @@ class ErrorReporter {
140144
Object? data,
141145
}) {
142146
atOffset(
143-
errorCode: diagnosticCode,
147+
diagnosticCode: diagnosticCode,
144148
offset: node.offset,
145149
length: node.length,
146150
arguments: arguments,
@@ -149,19 +153,31 @@ class ErrorReporter {
149153
);
150154
}
151155

152-
/// Report an error with the given [errorCode] and [arguments]. The location
153-
/// of the error is specified by the given [offset] and [length].
156+
/// Reports a diagnostic with the given [diagnosticCode] (or [errorCode],
157+
/// deprecated) and [arguments].
158+
///
159+
/// The location of the diagnostic is specified by the given [offset] and
160+
/// [length].
154161
void atOffset({
155162
required int offset,
156163
required int length,
157-
required DiagnosticCode errorCode,
164+
@Deprecated("Use 'diagnosticCode' instead") DiagnosticCode? errorCode,
165+
DiagnosticCode? diagnosticCode,
158166
List<Object>? arguments,
159167
List<DiagnosticMessage>? contextMessages,
160168
Object? data,
161169
}) {
162170
if (lockLevel != 0) {
163171
return;
164172
}
173+
if ((errorCode == null && diagnosticCode == null) ||
174+
(errorCode != null && diagnosticCode != null)) {
175+
throw ArgumentError(
176+
"Exactly one of 'errorCode' (deprecated) and 'diagnosticCode' should be given",
177+
);
178+
}
179+
180+
diagnosticCode ??= errorCode!;
165181

166182
if (arguments != null) {
167183
var invalid =
@@ -186,25 +202,26 @@ class ErrorReporter {
186202
source: _source,
187203
offset: offset,
188204
length: length,
189-
errorCode: errorCode,
205+
errorCode: diagnosticCode,
190206
arguments: arguments ?? const [],
191207
contextMessages: contextMessages,
192208
data: data,
193209
),
194210
);
195211
}
196212

197-
/// Report an error with the given [errorCode] and [arguments].
198-
/// The [span] is used to compute the location of the error.
213+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
214+
///
215+
/// The [span] is used to compute the location of the diagnostic.
199216
void atSourceSpan(
200217
SourceSpan span,
201-
DiagnosticCode errorCode, {
218+
DiagnosticCode diagnosticCode, {
202219
List<Object>? arguments,
203220
List<DiagnosticMessage>? contextMessages,
204221
Object? data,
205222
}) {
206223
atOffset(
207-
errorCode: errorCode,
224+
diagnosticCode: diagnosticCode,
208225
offset: span.start.offset,
209226
length: span.length,
210227
arguments: arguments,
@@ -213,8 +230,9 @@ class ErrorReporter {
213230
);
214231
}
215232

216-
/// Report an error with the given [diagnosticCode] and [arguments]. The [token] is
217-
/// used to compute the location of the error.
233+
/// Reports a diagnostic with the given [diagnosticCode] and [arguments].
234+
///
235+
/// The [token] is used to compute the location of the diagnostic.
218236
void atToken(
219237
Token token,
220238
DiagnosticCode diagnosticCode, {
@@ -223,7 +241,7 @@ class ErrorReporter {
223241
Object? data,
224242
}) {
225243
atOffset(
226-
errorCode: diagnosticCode,
244+
diagnosticCode: diagnosticCode,
227245
offset: token.offset,
228246
length: token.length,
229247
arguments: arguments,

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
293293
_errorReporter.atOffset(
294294
offset: result.offset,
295295
length: result.length,
296-
errorCode: result.diagnosticCode,
296+
diagnosticCode: result.diagnosticCode,
297297
arguments: result.arguments,
298298
contextMessages: result.contextMessages,
299299
);

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
605605
_errorReporter.atOffset(
606606
offset: result.offset,
607607
length: result.length,
608-
errorCode: result.diagnosticCode,
608+
diagnosticCode: result.diagnosticCode,
609609
arguments: result.arguments,
610610
contextMessages: result.contextMessages,
611611
);
@@ -2225,7 +2225,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
22252225
_errorReporter.atOffset(
22262226
offset: expressionValue.offset,
22272227
length: expressionValue.length,
2228-
errorCode: expressionValue.diagnosticCode,
2228+
diagnosticCode: expressionValue.diagnosticCode,
22292229
arguments: expressionValue.arguments,
22302230
contextMessages: expressionValue.contextMessages,
22312231
);

pkg/analyzer/lib/src/dart/resolver/binary_expression_resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class BinaryExpressionResolver {
154154
_errorReporter.atOffset(
155155
offset: offset,
156156
length: end.end - offset,
157-
errorCode: errorCode,
157+
diagnosticCode: errorCode,
158158
);
159159
}
160160

0 commit comments

Comments
 (0)