Skip to content

Commit 35e8b9b

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Deprecate ErrorType in favor of new name, DiagnosticType
Change-Id: I552e816de6d526e3476cac9dd3ee2919fc7ec499 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425720 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Kevin Moore <[email protected]>
1 parent 0fe2a31 commit 35e8b9b

File tree

36 files changed

+113
-101
lines changed

36 files changed

+113
-101
lines changed

pkg/_fe_analyzer_shared/lib/src/base/errors.dart

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ abstract class ErrorCode {
110110
/**
111111
* The type of the error.
112112
*/
113-
ErrorType get type;
113+
DiagnosticType get type;
114114

115115
/**
116116
* Return a URL that can be used to access documentation for diagnostics with
@@ -207,66 +207,67 @@ class ErrorSeverity implements Comparable<ErrorSeverity> {
207207
String toString() => name;
208208
}
209209

210-
/// The type of a [DiagnosticCode].
211210
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
212-
typedef DiagnosticType = ErrorType;
211+
@Deprecated("Use 'DiagnosticType' instead.")
212+
typedef ErrorType = DiagnosticType;
213213

214214
/**
215-
* The type of an [ErrorCode].
216-
*
217-
* Note that this class name, `ErrorType`, is soft-deprecated in favor of
218-
* the type alias, [DiagnosticType].
215+
* The type of a [DiagnosticCode].
219216
*/
220217
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
221-
class ErrorType implements Comparable<ErrorType> {
218+
class DiagnosticType implements Comparable<DiagnosticType> {
222219
/**
223220
* Task (todo) comments in user code.
224221
*/
225-
static const ErrorType TODO = const ErrorType('TODO', 0, ErrorSeverity.INFO);
222+
static const DiagnosticType TODO =
223+
const DiagnosticType('TODO', 0, ErrorSeverity.INFO);
226224

227225
/**
228226
* Extra analysis run over the code to follow best practices, which are not in
229227
* the Dart Language Specification.
230228
*/
231-
static const ErrorType HINT = const ErrorType('HINT', 1, ErrorSeverity.INFO);
229+
static const DiagnosticType HINT =
230+
const DiagnosticType('HINT', 1, ErrorSeverity.INFO);
232231

233232
/**
234233
* Compile-time errors are errors that preclude execution. A compile time
235234
* error must be reported by a Dart compiler before the erroneous code is
236235
* executed.
237236
*/
238-
static const ErrorType COMPILE_TIME_ERROR =
239-
const ErrorType('COMPILE_TIME_ERROR', 2, ErrorSeverity.ERROR);
237+
static const DiagnosticType COMPILE_TIME_ERROR =
238+
const DiagnosticType('COMPILE_TIME_ERROR', 2, ErrorSeverity.ERROR);
240239

241240
/**
242241
* Checked mode compile-time errors are errors that preclude execution in
243242
* checked mode.
244243
*/
245-
static const ErrorType CHECKED_MODE_COMPILE_TIME_ERROR = const ErrorType(
246-
'CHECKED_MODE_COMPILE_TIME_ERROR', 3, ErrorSeverity.ERROR);
244+
static const DiagnosticType CHECKED_MODE_COMPILE_TIME_ERROR =
245+
const DiagnosticType(
246+
'CHECKED_MODE_COMPILE_TIME_ERROR', 3, ErrorSeverity.ERROR);
247247

248248
/**
249249
* Static warnings are those warnings reported by the static checker. They
250250
* have no effect on execution. Static warnings must be provided by Dart
251251
* compilers used during development.
252252
*/
253-
static const ErrorType STATIC_WARNING =
254-
const ErrorType('STATIC_WARNING', 4, ErrorSeverity.WARNING);
253+
static const DiagnosticType STATIC_WARNING =
254+
const DiagnosticType('STATIC_WARNING', 4, ErrorSeverity.WARNING);
255255

256256
/**
257257
* Syntactic errors are errors produced as a result of input that does not
258258
* conform to the grammar.
259259
*/
260-
static const ErrorType SYNTACTIC_ERROR =
261-
const ErrorType('SYNTACTIC_ERROR', 6, ErrorSeverity.ERROR);
260+
static const DiagnosticType SYNTACTIC_ERROR =
261+
const DiagnosticType('SYNTACTIC_ERROR', 6, ErrorSeverity.ERROR);
262262

263263
/**
264264
* Lint warnings describe style and best practice recommendations that can be
265265
* used to formalize a project's style guidelines.
266266
*/
267-
static const ErrorType LINT = const ErrorType('LINT', 7, ErrorSeverity.INFO);
267+
static const DiagnosticType LINT =
268+
const DiagnosticType('LINT', 7, ErrorSeverity.INFO);
268269

269-
static const List<ErrorType> values = const [
270+
static const List<DiagnosticType> values = const [
270271
TODO,
271272
HINT,
272273
COMPILE_TIME_ERROR,
@@ -295,15 +296,15 @@ class ErrorType implements Comparable<ErrorType> {
295296
* Initialize a newly created error type to have the given [name] and
296297
* [severity].
297298
*/
298-
const ErrorType(this.name, this.ordinal, this.severity);
299+
const DiagnosticType(this.name, this.ordinal, this.severity);
299300

300301
String get displayName => name.toLowerCase().replaceAll('_', ' ');
301302

302303
@override
303304
int get hashCode => ordinal;
304305

305306
@override
306-
int compareTo(ErrorType other) => ordinal - other.ordinal;
307+
int compareTo(DiagnosticType other) => ordinal - other.ordinal;
307308

308309
@override
309310
String toString() => name;

pkg/_fe_analyzer_shared/lib/src/scanner/errors.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ class ScannerErrorCode extends ErrorCode {
205205
ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
206206

207207
@override
208-
ErrorType get type => ErrorType.SYNTACTIC_ERROR;
208+
DiagnosticType get type => DiagnosticType.SYNTACTIC_ERROR;
209209
}

pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ class LspServerContextManagerCallbacks
13941394

13951395
bool _shouldSendError(protocol.AnalysisError error) {
13961396
// Non-TODOs are always shown.
1397-
if (error.type.name != ErrorType.TODO.name) {
1397+
if (error.type.name != DiagnosticType.TODO.name) {
13981398
return true;
13991399
}
14001400

pkg/analysis_server/lib/src/services/correction/dart/add_diagnostic_property_reference.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer {
331331
var endOffset = startOffset + declaration.length;
332332
for (var error in unitResult.errors) {
333333
var errorCode = error.errorCode;
334-
if (errorCode.type == ErrorType.LINT &&
334+
if (errorCode.type == DiagnosticType.LINT &&
335335
errorCode == LinterLintCode.diagnostic_describe_all_properties &&
336336
error.offset > startOffset &&
337337
error.offset < endOffset) {

pkg/analysis_server/lib/src/services/correction/dart/replace_with_decorated_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ReplaceWithDecoratedBox extends ResolvedCorrectionProducer {
120120
var constructorName = expression.constructorName;
121121
return unitResult.errors.any((error) {
122122
var errorCode = error.errorCode;
123-
return errorCode.type == ErrorType.LINT &&
123+
return errorCode.type == DiagnosticType.LINT &&
124124
errorCode == LinterLintCode.use_decorated_box &&
125125
error.offset == constructorName.offset &&
126126
error.length == constructorName.length;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,5 @@ class TransformSetErrorCode extends DiagnosticCode {
191191
ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
192192

193193
@override
194-
ErrorType get type => ErrorType.COMPILE_TIME_ERROR;
194+
DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR;
195195
}

pkg/analysis_server/test/protocol_server_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ class EnumTest {
236236
}
237237

238238
void test_AnalysisErrorType() {
239-
EnumTester<engine.ErrorType, AnalysisErrorType>().run(
240-
(engine.ErrorType engineErrorType) =>
239+
EnumTester<engine.DiagnosticType, AnalysisErrorType>().run(
240+
(engine.DiagnosticType engineErrorType) =>
241241
AnalysisErrorType.values.byName(engineErrorType.name),
242242
);
243243
}
@@ -387,7 +387,7 @@ class MockAnalysisError implements engine.AnalysisError {
387387

388388
class MockDiagnosticCode implements engine.DiagnosticCode {
389389
@override
390-
engine.ErrorType type;
390+
engine.DiagnosticType type;
391391

392392
@override
393393
engine.ErrorSeverity errorSeverity;
@@ -399,7 +399,7 @@ class MockDiagnosticCode implements engine.DiagnosticCode {
399399
String? url;
400400

401401
MockDiagnosticCode({
402-
this.type = engine.ErrorType.COMPILE_TIME_ERROR,
402+
this.type = engine.DiagnosticType.COMPILE_TIME_ERROR,
403403
this.errorSeverity = engine.ErrorSeverity.ERROR,
404404
this.name = 'TEST_ERROR',
405405
this.url,

pkg/analysis_server/test/src/services/correction/fix/convert_for_each_to_for_loop_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void f(List<int> list) {
487487
}
488488
''');
489489
await assertNoFix(
490-
errorFilter: (error) => error.errorCode.type == ErrorType.LINT,
490+
errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT,
491491
);
492492
}
493493

@@ -498,7 +498,7 @@ void f(List<int> list) {
498498
}
499499
''');
500500
await assertNoFix(
501-
errorFilter: (error) => error.errorCode.type == ErrorType.LINT,
501+
errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT,
502502
);
503503
}
504504

@@ -509,7 +509,7 @@ void f(List<int> list, bool b) {
509509
}
510510
''');
511511
await assertNoFix(
512-
errorFilter: (error) => error.errorCode.type == ErrorType.LINT,
512+
errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT,
513513
);
514514
}
515515

@@ -525,6 +525,6 @@ void f(List<int> list) {
525525
<int>{x};
526526
}
527527
}
528-
''', errorFilter: (error) => error.errorCode.type == ErrorType.LINT);
528+
''', errorFilter: (error) => error.errorCode.type == DiagnosticType.LINT);
529529
}
530530
}

pkg/analysis_server/tool/bulk_fix/supported_diagnostics.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Future<void> main() async {
1616

1717
var hintEntries = registeredFixGenerators.nonLintProducers.entries.where(
1818
(e) =>
19-
e.key.type == ErrorType.HINT || e.key.type == ErrorType.STATIC_WARNING,
19+
e.key.type == DiagnosticType.HINT ||
20+
e.key.type == DiagnosticType.STATIC_WARNING,
2021
);
2122

2223
var diagnostics = [

pkg/analyzer/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Remove deprecated `DartType.isStructurallyEqualTo`.
44
* Remove deprecated `RecordType.positionalTypes`.
55
* Remove deprecated `RecordType.sortedNamedTypes`.
6-
* Remove `ElementLocation` class, its values are not returned anymore.
7-
* Deprecated `element2.dart` library, import `element.dart`.
8-
* Deprecated `XyzElement2` classes, use `XyzElement` instead.
6+
* Remove `ElementLocation` class; its values are not returned anymore.
7+
* Deprecate `element2.dart` library; import `element.dart`.
8+
* Deprecate `XyzElement2` classes; use `XyzElement` instead.
99
* Deprecate `AnalysisError.correction` field; use
1010
`AnalysisError.correctionMessage` instead.
11+
* Deprecate `ErrorType`; use `DiagnosticType` instead.
1112

1213
## 7.4.1
1314
* Restore `InstanceElement.augmented` getter.

0 commit comments

Comments
 (0)