Skip to content

Commit ef68d43

Browse files
scheglovpull[bot]
authored andcommitted
CQ. ErrorReporter, use atOffset() instead of reportErrorForOffset()
Change-Id: I506f71d1e7aa95f1c62fca1746e4a86c78720336 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353782 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]>
1 parent d9ecb2c commit ef68d43

34 files changed

+1114
-552
lines changed

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

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ class CodeFragmentParser {
8080
}
8181
accessors.add(accessor);
8282
} else {
83-
errorReporter.reportErrorForOffset(TransformSetErrorCode.wrongToken,
84-
token.offset + delta, token.length, ['.', token.kind.displayName]);
83+
errorReporter.atOffset(
84+
offset: token.offset + delta,
85+
length: token.length,
86+
errorCode: TransformSetErrorCode.wrongToken,
87+
arguments: ['.', token.kind.displayName],
88+
contextMessages: null,
89+
data: null,
90+
);
8591
return null;
8692
}
8793
}
@@ -106,8 +112,14 @@ class CodeFragmentParser {
106112
var expression = _parseLogicalAndExpression();
107113
if (currentIndex < _tokens.length) {
108114
var token = _tokens[currentIndex];
109-
errorReporter.reportErrorForOffset(TransformSetErrorCode.unexpectedToken,
110-
token.offset + delta, token.length, [token.kind.displayName]);
115+
errorReporter.atOffset(
116+
offset: token.offset + delta,
117+
length: token.length,
118+
errorCode: TransformSetErrorCode.unexpectedToken,
119+
arguments: [token.kind.displayName],
120+
contextMessages: null,
121+
data: null,
122+
);
111123
return null;
112124
}
113125
return expression;
@@ -140,16 +152,25 @@ class CodeFragmentParser {
140152
offset = last.offset;
141153
length = last.length;
142154
}
143-
errorReporter.reportErrorForOffset(TransformSetErrorCode.missingToken,
144-
offset + delta, length, [validKindsDisplayString()]);
155+
errorReporter.atOffset(
156+
offset: offset + delta,
157+
length: length,
158+
errorCode: TransformSetErrorCode.missingToken,
159+
arguments: [validKindsDisplayString()],
160+
contextMessages: null,
161+
data: null,
162+
);
145163
return null;
146164
}
147165
if (!validKinds.contains(token.kind)) {
148-
errorReporter.reportErrorForOffset(
149-
TransformSetErrorCode.wrongToken,
150-
token.offset + delta,
151-
token.length,
152-
[validKindsDisplayString(), token.kind.displayName]);
166+
errorReporter.atOffset(
167+
offset: token.offset + delta,
168+
length: token.length,
169+
errorCode: TransformSetErrorCode.wrongToken,
170+
arguments: [validKindsDisplayString(), token.kind.displayName],
171+
contextMessages: null,
172+
data: null,
173+
);
153174
return null;
154175
}
155176
return token;
@@ -217,8 +238,14 @@ class CodeFragmentParser {
217238
advance();
218239
return TypeArgumentAccessor(argumentIndex);
219240
} else {
220-
errorReporter.reportErrorForOffset(TransformSetErrorCode.unknownAccessor,
221-
token.offset + delta, token.length, [identifier]);
241+
errorReporter.atOffset(
242+
offset: token.offset + delta,
243+
length: token.length,
244+
errorCode: TransformSetErrorCode.unknownAccessor,
245+
arguments: [identifier],
246+
contextMessages: null,
247+
data: null,
248+
);
222249
return null;
223250
}
224251
}
@@ -293,11 +320,14 @@ class CodeFragmentParser {
293320
var variableName = token.lexeme;
294321
var generator = variableScope.lookup(variableName);
295322
if (generator == null) {
296-
errorReporter.reportErrorForOffset(
297-
TransformSetErrorCode.undefinedVariable,
298-
token.offset + delta,
299-
token.length,
300-
[variableName]);
323+
errorReporter.atOffset(
324+
offset: token.offset + delta,
325+
length: token.length,
326+
errorCode: TransformSetErrorCode.undefinedVariable,
327+
arguments: [variableName],
328+
contextMessages: null,
329+
data: null,
330+
);
301331
return null;
302332
}
303333
return VariableReference(generator);
@@ -323,8 +353,14 @@ class CodeFragmentParser {
323353
offset = token.offset + delta;
324354
length = token.length;
325355
}
326-
errorReporter.reportErrorForOffset(
327-
TransformSetErrorCode.expectedPrimary, offset, length);
356+
errorReporter.atOffset(
357+
offset: offset,
358+
length: length,
359+
errorCode: TransformSetErrorCode.expectedPrimary,
360+
arguments: null,
361+
contextMessages: null,
362+
data: null,
363+
);
328364
return null;
329365
}
330366
}
@@ -454,8 +490,14 @@ class _CodeFragmentScanner {
454490

455491
/// Report the presence of an invalid character at the given [offset].
456492
Null _reportInvalidCharacter(int offset) {
457-
errorReporter.reportErrorForOffset(TransformSetErrorCode.invalidCharacter,
458-
offset + delta, 1, [content.substring(offset, offset + 1)]);
493+
errorReporter.atOffset(
494+
offset: offset + delta,
495+
length: 1,
496+
errorCode: TransformSetErrorCode.invalidCharacter,
497+
arguments: [content.substring(offset, offset + 1)],
498+
contextMessages: null,
499+
data: null,
500+
);
459501
return null;
460502
}
461503

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

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,29 @@ class TransformSetParser {
190190
}
191191
var endIndex = template.indexOf(_closeComponent, variableStart + 2);
192192
if (endIndex < 0) {
193-
errorReporter.reportErrorForOffset(
194-
TransformSetErrorCode.missingTemplateEnd,
195-
templateOffset + variableStart,
196-
2);
193+
errorReporter.atOffset(
194+
offset: templateOffset + variableStart,
195+
length: 2,
196+
errorCode: TransformSetErrorCode.missingTemplateEnd,
197+
arguments: null,
198+
contextMessages: null,
199+
data: null,
200+
);
197201
// Ignore the invalid component, treating it as if it extended to the
198202
// end of the template.
199203
return components;
200204
} else {
201205
var name = template.substring(variableStart + 2, endIndex).trim();
202206
var generator = variableScope.lookup(name);
203207
if (generator == null) {
204-
errorReporter.reportErrorForOffset(
205-
TransformSetErrorCode.undefinedVariable,
206-
templateOffset + template.indexOf(name, variableStart),
207-
name.length,
208-
[name]);
208+
errorReporter.atOffset(
209+
offset: templateOffset + template.indexOf(name, variableStart),
210+
length: name.length,
211+
errorCode: TransformSetErrorCode.undefinedVariable,
212+
arguments: [name],
213+
contextMessages: null,
214+
data: null,
215+
);
209216
// Ignore the invalid component.
210217
} else {
211218
components.add(TemplateVariable(generator));
@@ -254,8 +261,14 @@ class TransformSetParser {
254261
var span = e.span;
255262
var offset = span?.start.offset ?? 0;
256263
var length = span?.length ?? 0;
257-
errorReporter.reportErrorForOffset(
258-
TransformSetErrorCode.yamlSyntaxError, offset, length, [e.message]);
264+
errorReporter.atOffset(
265+
offset: offset,
266+
length: length,
267+
errorCode: TransformSetErrorCode.yamlSyntaxError,
268+
arguments: [e.message],
269+
contextMessages: null,
270+
data: null,
271+
);
259272
}
260273
return null;
261274
}
@@ -266,8 +279,14 @@ class TransformSetParser {
266279
void _reportError(TransformSetErrorCode code, YamlNode node,
267280
[List<String> arguments = const []]) {
268281
var span = node.span;
269-
errorReporter.reportErrorForOffset(
270-
code, span.start.offset, span.length, arguments);
282+
errorReporter.atOffset(
283+
offset: span.start.offset,
284+
length: span.length,
285+
errorCode: code,
286+
arguments: arguments,
287+
contextMessages: null,
288+
data: null,
289+
);
271290
}
272291

273292
/// Report that the value represented by the [node] does not have the

pkg/analyzer/lib/error/listener.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,14 @@ class ErrorReporter {
180180
// declaration. This might make it easier to be consistent.
181181
if (constructor.name != null) {
182182
var offset = constructor.returnType.offset;
183-
reportErrorForOffset(
184-
code, offset, constructor.name!.end - offset, arguments);
183+
atOffset(
184+
offset: offset,
185+
length: constructor.name!.end - offset,
186+
errorCode: code,
187+
arguments: arguments,
188+
contextMessages: null,
189+
data: null,
190+
);
185191
} else {
186192
atNode(
187193
constructor.returnType,
@@ -212,6 +218,7 @@ class ErrorReporter {
212218

213219
/// Report an error with the given [errorCode] and [arguments]. The location
214220
/// of the error is specified by the given [offset] and [length].
221+
@Deprecated('Use atOffset() instead')
215222
void reportErrorForOffset(
216223
ErrorCode errorCode,
217224
int offset,
@@ -234,7 +241,14 @@ class ErrorReporter {
234241
/// of the error is specified by the given [span].
235242
void reportErrorForSpan(ErrorCode errorCode, SourceSpan span,
236243
[List<Object>? arguments]) {
237-
reportErrorForOffset(errorCode, span.start.offset, span.length, arguments);
244+
atOffset(
245+
offset: span.start.offset,
246+
length: span.length,
247+
errorCode: errorCode,
248+
arguments: arguments,
249+
contextMessages: null,
250+
data: null,
251+
);
238252
}
239253

240254
/// Report an error with the given [errorCode] and [arguments]. The [token] is
@@ -268,7 +282,14 @@ class ErrorReporter {
268282
@Deprecated('Use reportErrorForNode(), it will convert types as well')
269283
void reportTypeErrorForNode(
270284
ErrorCode errorCode, AstNode node, List<Object> arguments) {
271-
reportErrorForOffset(errorCode, node.offset, node.length, arguments);
285+
atOffset(
286+
offset: node.offset,
287+
length: node.length,
288+
errorCode: errorCode,
289+
arguments: arguments,
290+
contextMessages: null,
291+
data: null,
292+
);
272293
}
273294

274295
/// Convert all [Element]s in the [arguments] into their display strings.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,13 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
276276
switch (result) {
277277
case InvalidConstant():
278278
if (!result.avoidReporting) {
279-
_errorReporter.reportErrorForOffset(
280-
result.errorCode,
281-
result.offset,
282-
result.length,
283-
result.arguments,
284-
result.contextMessages,
279+
_errorReporter.atOffset(
280+
offset: result.offset,
281+
length: result.length,
282+
errorCode: result.errorCode,
283+
arguments: result.arguments,
284+
contextMessages: result.contextMessages,
285+
data: null,
285286
);
286287
}
287288
case DartObjectImpl():

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,13 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
581581
Constant evaluateAndReportInvalidConstant(AstNode node) {
582582
var result = evaluateConstant(node);
583583
if (result case InvalidConstant(avoidReporting: false)) {
584-
_errorReporter.reportErrorForOffset(
585-
result.errorCode,
586-
result.offset,
587-
result.length,
588-
result.arguments,
589-
result.contextMessages,
584+
_errorReporter.atOffset(
585+
offset: result.offset,
586+
length: result.length,
587+
errorCode: result.errorCode,
588+
arguments: result.arguments,
589+
contextMessages: result.contextMessages,
590+
data: null,
590591
);
591592
}
592593
return result;
@@ -1946,12 +1947,13 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19461947
// interaction with g3 more elegantly.
19471948
case InvalidConstant(isUnresolved: true):
19481949
if (!expressionValue.avoidReporting) {
1949-
_errorReporter.reportErrorForOffset(
1950-
expressionValue.errorCode,
1951-
expressionValue.offset,
1952-
expressionValue.length,
1953-
expressionValue.arguments,
1954-
expressionValue.contextMessages,
1950+
_errorReporter.atOffset(
1951+
offset: expressionValue.offset,
1952+
length: expressionValue.length,
1953+
errorCode: expressionValue.errorCode,
1954+
arguments: expressionValue.arguments,
1955+
contextMessages: expressionValue.contextMessages,
1956+
data: null,
19551957
);
19561958
}
19571959
return ConstantEvaluationEngine._unresolvedObject(

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,14 @@ class BinaryExpressionResolver {
125125
? WarningCode.UNNECESSARY_NULL_COMPARISON_FALSE
126126
: WarningCode.UNNECESSARY_NULL_COMPARISON_TRUE;
127127
var offset = start.offset;
128-
_errorReporter.reportErrorForOffset(errorCode, offset, end.end - offset);
128+
_errorReporter.atOffset(
129+
offset: offset,
130+
length: end.end - offset,
131+
errorCode: errorCode,
132+
arguments: null,
133+
contextMessages: null,
134+
data: null,
135+
);
129136
}
130137

131138
if (left is SimpleIdentifierImpl && right is NullLiteralImpl) {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ class ExtensionMemberResolver {
106106
return extension.asResolutionResult;
107107
},
108108
(noneMoreSpecific) {
109-
_errorReporter.reportErrorForOffset(
110-
CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS,
111-
nameEntity.offset,
112-
nameEntity.length,
113-
[
109+
_errorReporter.atOffset(
110+
offset: nameEntity.offset,
111+
length: nameEntity.length,
112+
errorCode: CompileTimeErrorCode.AMBIGUOUS_EXTENSION_MEMBER_ACCESS,
113+
arguments: [
114114
name,
115115
noneMoreSpecific.map((e) {
116116
var name = e.extension.name;
@@ -121,6 +121,8 @@ class ExtensionMemberResolver {
121121
return "unnamed extension on '$type'";
122122
}).commaSeparatedWithAnd,
123123
],
124+
contextMessages: null,
125+
data: null,
124126
);
125127
return ResolutionResult.ambiguous;
126128
},

0 commit comments

Comments
 (0)