Skip to content

Commit 9ab2139

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
analyzer: Deprecate ErrorSeverity in favor of DiagnosticSeverity
Work towards #60635 Change-Id: Ic7f84584d4185e1ab7e8741052ec6694487c8c08 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426600 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent c6658d0 commit 9ab2139

File tree

9 files changed

+76
-64
lines changed

9 files changed

+76
-64
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ abstract class ErrorCode {
129129

130130
/// The severity of a [DiagnosticCode].
131131
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
132-
typedef DiagnosticSeverity = ErrorSeverity;
132+
@Deprecated("Use 'DiagnosticSeverity' instead.")
133+
typedef ErrorSeverity = DiagnosticSeverity;
133134

134135
/**
135136
* The severity of an [ErrorCode].
@@ -138,32 +139,39 @@ typedef DiagnosticSeverity = ErrorSeverity;
138139
* the type alias, [DiagnosticSeverity].
139140
*/
140141
@AnalyzerPublicApi(message: 'exported by package:analyzer/error/error.dart')
141-
class ErrorSeverity implements Comparable<ErrorSeverity> {
142+
class DiagnosticSeverity implements Comparable<DiagnosticSeverity> {
142143
/**
143144
* The severity representing a non-error. This is never used for any error
144145
* code, but is useful for clients.
145146
*/
146-
static const ErrorSeverity NONE = const ErrorSeverity('NONE', 0, " ", "none");
147+
static const DiagnosticSeverity NONE =
148+
const DiagnosticSeverity('NONE', 0, " ", "none");
147149

148150
/**
149151
* The severity representing an informational level analysis issue.
150152
*/
151-
static const ErrorSeverity INFO = const ErrorSeverity('INFO', 1, "I", "info");
153+
static const DiagnosticSeverity INFO =
154+
const DiagnosticSeverity('INFO', 1, "I", "info");
152155

153156
/**
154157
* The severity representing a warning. Warnings can become errors if the
155158
* `-Werror` command line flag is specified.
156159
*/
157-
static const ErrorSeverity WARNING =
158-
const ErrorSeverity('WARNING', 2, "W", "warning");
160+
static const DiagnosticSeverity WARNING =
161+
const DiagnosticSeverity('WARNING', 2, "W", "warning");
159162

160163
/**
161164
* The severity representing an error.
162165
*/
163-
static const ErrorSeverity ERROR =
164-
const ErrorSeverity('ERROR', 3, "E", "error");
165-
166-
static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
166+
static const DiagnosticSeverity ERROR =
167+
const DiagnosticSeverity('ERROR', 3, "E", "error");
168+
169+
static const List<DiagnosticSeverity> values = const [
170+
NONE,
171+
INFO,
172+
WARNING,
173+
ERROR
174+
];
167175

168176
final String name;
169177

@@ -179,19 +187,19 @@ class ErrorSeverity implements Comparable<ErrorSeverity> {
179187
*/
180188
final String displayName;
181189

182-
const ErrorSeverity(
190+
const DiagnosticSeverity(
183191
this.name, this.ordinal, this.machineCode, this.displayName);
184192

185193
@override
186194
int get hashCode => ordinal;
187195

188196
@override
189-
int compareTo(ErrorSeverity other) => ordinal - other.ordinal;
197+
int compareTo(DiagnosticSeverity other) => ordinal - other.ordinal;
190198

191199
/**
192200
* Return the severity constant that represents the greatest severity.
193201
*/
194-
ErrorSeverity max(ErrorSeverity severity) =>
202+
DiagnosticSeverity max(DiagnosticSeverity severity) =>
195203
this.ordinal >= severity.ordinal ? this : severity;
196204

197205
@override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import 'package:analysis_server/src/utilities/process.dart';
3333
import 'package:analysis_server_plugin/src/correction/performance.dart';
3434
import 'package:analyzer/dart/analysis/results.dart';
3535
import 'package:analyzer/dart/analysis/session.dart';
36-
import 'package:analyzer/error/error.dart';
36+
import 'package:analyzer/error/error.dart' as engine;
3737
import 'package:analyzer/exception/exception.dart';
3838
import 'package:analyzer/file_system/file_system.dart';
3939
import 'package:analyzer/instrumentation/instrumentation.dart';
@@ -1394,12 +1394,12 @@ class LspServerContextManagerCallbacks
13941394

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

14011401
// TODOs that are upgraded from INFO are always shown.
1402-
if (error.severity.name != ErrorSeverity.INFO.name) {
1402+
if (error.severity.name != engine.DiagnosticSeverity.INFO.name) {
14031403
return true;
14041404
}
14051405

pkg/analysis_server/lib/src/protocol_server.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ List<T> mapEngineErrors<T>(
112112
T Function(
113113
engine.AnalysisResultWithErrors result,
114114
engine.Diagnostic diagnostic, [
115-
engine.ErrorSeverity errorSeverity,
115+
engine.DiagnosticSeverity errorSeverity,
116116
])
117117
constructor,
118118
) {
@@ -137,19 +137,20 @@ List<T> mapEngineErrors<T>(
137137

138138
/// Construct based on error information from the analyzer engine.
139139
///
140-
/// If an [errorSeverity] is specified, it will override the one in [error].
140+
/// If an [diagnosticSeverity] is specified, it will override the one in
141+
/// [diagnostic].
141142
AnalysisError newAnalysisError_fromEngine(
142143
engine.AnalysisResultWithErrors result,
143-
engine.Diagnostic error, [
144-
engine.ErrorSeverity? errorSeverity,
144+
engine.Diagnostic diagnostic, [
145+
engine.DiagnosticSeverity? diagnosticSeverity,
145146
]) {
146-
var errorCode = error.errorCode;
147+
var errorCode = diagnostic.errorCode;
147148
// prepare location
148149
Location location;
149150
{
150-
var file = error.source.fullName;
151-
var offset = error.offset;
152-
var length = error.length;
151+
var file = diagnostic.source.fullName;
152+
var offset = diagnostic.offset;
153+
var length = diagnostic.length;
153154
var lineInfo = result.lineInfo;
154155

155156
var startLocation = lineInfo.getLocation(offset);
@@ -172,21 +173,21 @@ AnalysisError newAnalysisError_fromEngine(
172173
}
173174

174175
// Default to the error's severity if none is specified.
175-
errorSeverity ??= errorCode.errorSeverity;
176+
diagnosticSeverity ??= errorCode.errorSeverity;
176177

177178
// done
178-
var severity = AnalysisErrorSeverity.values.byName(errorSeverity.name);
179+
var severity = AnalysisErrorSeverity.values.byName(diagnosticSeverity.name);
179180
var type = AnalysisErrorType.values.byName(errorCode.type.name);
180-
var message = error.message;
181+
var message = diagnostic.message;
181182
var code = errorCode.name.toLowerCase();
182183
List<DiagnosticMessage>? contextMessages;
183-
if (error.contextMessages.isNotEmpty) {
184+
if (diagnostic.contextMessages.isNotEmpty) {
184185
contextMessages =
185-
error.contextMessages
186+
diagnostic.contextMessages
186187
.map((message) => newDiagnosticMessage(result, message))
187188
.toList();
188189
}
189-
var correction = error.correctionMessage;
190+
var correction = diagnostic.correctionMessage;
190191
var url = errorCode.url;
191192
return AnalysisError(
192193
severity,

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
@@ -188,7 +188,7 @@ class TransformSetErrorCode extends DiagnosticCode {
188188
);
189189

190190
@override
191-
ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
191+
DiagnosticSeverity get errorSeverity => DiagnosticSeverity.ERROR;
192192

193193
@override
194194
DiagnosticType get type => DiagnosticType.COMPILE_TIME_ERROR;

pkg/analysis_server/test/protocol_server_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ class AnalysisErrorTest {
229229
@reflectiveTest
230230
class EnumTest {
231231
void test_AnalysisErrorSeverity() {
232-
EnumTester<engine.ErrorSeverity, AnalysisErrorSeverity>().run(
233-
(engine.ErrorSeverity engineErrorSeverity) =>
234-
AnalysisErrorSeverity.values.byName(engineErrorSeverity.name),
235-
exceptions: {engine.ErrorSeverity.NONE: null},
232+
EnumTester<engine.DiagnosticSeverity, AnalysisErrorSeverity>().run(
233+
(engineSeverity) =>
234+
AnalysisErrorSeverity.values.byName(engineSeverity.name),
235+
exceptions: {engine.DiagnosticSeverity.NONE: null},
236236
);
237237
}
238238

239239
void test_AnalysisErrorType() {
240240
EnumTester<engine.DiagnosticType, AnalysisErrorType>().run(
241-
(engine.DiagnosticType engineErrorType) =>
241+
(engineErrorType) =>
242242
AnalysisErrorType.values.byName(engineErrorType.name),
243243
);
244244
}
@@ -391,7 +391,7 @@ class MockDiagnosticCode implements engine.DiagnosticCode {
391391
engine.DiagnosticType type;
392392

393393
@override
394-
engine.ErrorSeverity errorSeverity;
394+
engine.DiagnosticSeverity errorSeverity;
395395

396396
@override
397397
String name;
@@ -401,7 +401,7 @@ class MockDiagnosticCode implements engine.DiagnosticCode {
401401

402402
MockDiagnosticCode({
403403
this.type = engine.DiagnosticType.COMPILE_TIME_ERROR,
404-
this.errorSeverity = engine.ErrorSeverity.ERROR,
404+
this.errorSeverity = engine.DiagnosticSeverity.ERROR,
405405
this.name = 'TEST_ERROR',
406406
this.url,
407407
});

pkg/analysis_server/test/utils/test_support.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ class GatheringErrorListener implements AnalysisErrorListener {
333333
/// number of [expectedSeverities] and that there are the same number of
334334
/// errors and warnings as specified by the argument. The order in which the
335335
/// errors were gathered is ignored.
336-
void assertErrorsWithSeverities(List<ErrorSeverity> expectedSeverities) {
336+
void assertErrorsWithSeverities(List<DiagnosticSeverity> expectedSeverities) {
337337
var expectedErrorCount = 0;
338338
var expectedWarningCount = 0;
339339
for (var severity in expectedSeverities) {
340-
if (severity == ErrorSeverity.ERROR) {
340+
if (severity == DiagnosticSeverity.ERROR) {
341341
expectedErrorCount++;
342342
} else {
343343
expectedWarningCount++;
@@ -346,7 +346,7 @@ class GatheringErrorListener implements AnalysisErrorListener {
346346
var actualErrorCount = 0;
347347
var actualWarningCount = 0;
348348
for (var error in _errors) {
349-
if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) {
349+
if (error.errorCode.errorSeverity == DiagnosticSeverity.ERROR) {
350350
actualErrorCount++;
351351
} else {
352352
actualWarningCount++;

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Deprecate `AnalysisError.correction` field; use
1010
`AnalysisError.correctionMessage` instead.
1111
* Deprecate `ErrorType`; use `DiagnosticType` instead.
12+
* Deprecate `ErrorSeverity`; use `DiagnosticSeverity` instead.
1213
* Change `ElementDirective` from `sealed` to `abstract`.
1314
This allows the analyzer to have an internal implementation
1415
class corresponding to `ElementDirective`.

pkg/analyzer/api.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,21 @@ package:analyzer/diagnostic/diagnostic.dart:
43614361
package:analyzer/error/error.dart:
43624362
errorCodeValues (static getter: List<ErrorCode>)
43634363
errorCodeByUniqueName (function: ErrorCode? Function(String))
4364+
DiagnosticSeverity (class extends Object implements Comparable<DiagnosticSeverity>):
4365+
ERROR (static getter: DiagnosticSeverity)
4366+
INFO (static getter: DiagnosticSeverity)
4367+
NONE (static getter: DiagnosticSeverity)
4368+
WARNING (static getter: DiagnosticSeverity)
4369+
values (static getter: List<DiagnosticSeverity>)
4370+
new (constructor: DiagnosticSeverity Function(String, int, String, String))
4371+
displayName (getter: String)
4372+
hashCode (getter: int)
4373+
machineCode (getter: String)
4374+
name (getter: String)
4375+
ordinal (getter: int)
4376+
compareTo (method: int Function(DiagnosticSeverity))
4377+
max (method: DiagnosticSeverity Function(DiagnosticSeverity))
4378+
toString (method: String Function())
43644379
DiagnosticType (class extends Object implements Comparable<DiagnosticType>):
43654380
CHECKED_MODE_COMPILE_TIME_ERROR (static getter: DiagnosticType)
43664381
COMPILE_TIME_ERROR (static getter: DiagnosticType)
@@ -4370,18 +4385,18 @@ package:analyzer/error/error.dart:
43704385
SYNTACTIC_ERROR (static getter: DiagnosticType)
43714386
TODO (static getter: DiagnosticType)
43724387
values (static getter: List<DiagnosticType>)
4373-
new (constructor: DiagnosticType Function(String, int, ErrorSeverity))
4388+
new (constructor: DiagnosticType Function(String, int, DiagnosticSeverity))
43744389
displayName (getter: String)
43754390
hashCode (getter: int)
43764391
name (getter: String)
43774392
ordinal (getter: int)
4378-
severity (getter: ErrorSeverity)
4393+
severity (getter: DiagnosticSeverity)
43794394
compareTo (method: int Function(DiagnosticType))
43804395
toString (method: String Function())
43814396
ErrorCode (class extends Object):
43824397
new (constructor: ErrorCode Function({String? correctionMessage, bool hasPublishedDocs, bool isUnresolvedIdentifier, required String name, required String problemMessage, required String uniqueName}))
43834398
correctionMessage (getter: String?)
4384-
errorSeverity (getter: ErrorSeverity)
4399+
errorSeverity (getter: DiagnosticSeverity)
43854400
hasPublishedDocs (getter: bool)
43864401
isIgnorable (getter: bool)
43874402
isUnresolvedIdentifier (getter: bool)
@@ -4392,31 +4407,16 @@ package:analyzer/error/error.dart:
43924407
uniqueName (getter: String)
43934408
url (getter: String?)
43944409
toString (method: String Function())
4395-
ErrorSeverity (class extends Object implements Comparable<ErrorSeverity>):
4396-
ERROR (static getter: ErrorSeverity)
4397-
INFO (static getter: ErrorSeverity)
4398-
NONE (static getter: ErrorSeverity)
4399-
WARNING (static getter: ErrorSeverity)
4400-
values (static getter: List<ErrorSeverity>)
4401-
new (constructor: ErrorSeverity Function(String, int, String, String))
4402-
displayName (getter: String)
4403-
hashCode (getter: int)
4404-
machineCode (getter: String)
4405-
name (getter: String)
4406-
ordinal (getter: int)
4407-
compareTo (method: int Function(ErrorSeverity))
4408-
max (method: ErrorSeverity Function(ErrorSeverity))
4409-
toString (method: String Function())
44104410
LintCode (class extends ErrorCode):
44114411
new (constructor: LintCode Function(String, String, {String? correctionMessage, bool hasPublishedDocs, String? uniqueName}))
4412-
errorSeverity (getter: ErrorSeverity)
4412+
errorSeverity (getter: DiagnosticSeverity)
44134413
hashCode (getter: int)
44144414
type (getter: DiagnosticType)
44154415
url (getter: String?)
44164416
== (method: bool Function(Object))
44174417
AnalysisError (type alias for Diagnostic)
44184418
DiagnosticCode (type alias for ErrorCode)
4419-
DiagnosticSeverity (type alias for ErrorSeverity)
4419+
ErrorSeverity (type alias for DiagnosticSeverity, deprecated)
44204420
ErrorType (type alias for DiagnosticType, deprecated)
44214421
package:analyzer/error/listener.dart:
44224422
AnalysisErrorListener (class extends Object):
@@ -4694,17 +4694,17 @@ package:analyzer/instrumentation/service.dart:
46944694
InstrumentationService (see above)
46954695
InstrumentationServiceAttachment (see above)
46964696
package:analyzer/source/error_processor.dart:
4697-
severityMap (static getter: Map<String, ErrorSeverity>)
4697+
severityMap (static getter: Map<String, DiagnosticSeverity>)
46984698
ErrorConfig (class extends Object):
46994699
new (constructor: ErrorConfig Function(YamlNode?))
47004700
processors (getter: List<ErrorProcessor>)
47014701
ErrorProcessor (class extends Object):
47024702
getProcessor (static method: ErrorProcessor? Function(AnalysisOptions?, Diagnostic))
47034703
ignore (constructor: ErrorProcessor Function(String))
4704-
new (constructor: ErrorProcessor Function(String, [ErrorSeverity?]))
4704+
new (constructor: ErrorProcessor Function(String, [DiagnosticSeverity?]))
47054705
code (getter: String)
47064706
description (getter: String)
4707-
severity (getter: ErrorSeverity?)
4707+
severity (getter: DiagnosticSeverity?)
47084708
appliesTo (method: bool Function(Diagnostic))
47094709
toString (method: String Function())
47104710
package:analyzer/source/file_source.dart:

pkg/analyzer/lib/error/error.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export 'package:_fe_analyzer_shared/src/base/errors.dart'
1717
DiagnosticSeverity,
1818
DiagnosticType,
1919
ErrorCode,
20+
// Continue exporting the deleted element until it is removed.
21+
// ignore: deprecated_member_use
2022
ErrorSeverity,
2123
// Continue exporting the deleted element until it is removed.
2224
// ignore: deprecated_member_use

0 commit comments

Comments
 (0)