Skip to content

Commit cd07d19

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Make AnalysisError._problemMessage non-late and public
Work towards #60635 Change-Id: Id80912299c8bd9caafb9f6a9521168c74911f90d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425581 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 508ad13 commit cd07d19

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class AnalysisError implements Diagnostic {
5757
/// The error code associated with the error.
5858
final ErrorCode errorCode;
5959

60-
/// The message describing the problem.
61-
late final DiagnosticMessage _problemMessage;
60+
@override
61+
final DiagnosticMessage problemMessage;
6262

6363
/// The context messages associated with the problem. This list will be empty
6464
/// if there are no context messages.
@@ -85,30 +85,29 @@ class AnalysisError implements Diagnostic {
8585
List<DiagnosticMessage> contextMessages = const [],
8686
this.data,
8787
}) : _correctionMessage = correctionMessage,
88-
_contextMessages = contextMessages {
89-
_problemMessage = DiagnosticMessageImpl(
90-
filePath: source.fullName,
91-
length: length,
92-
message: message,
93-
offset: offset,
94-
url: null,
95-
);
96-
}
88+
_contextMessages = contextMessages,
89+
problemMessage = DiagnosticMessageImpl(
90+
filePath: source.fullName,
91+
length: length,
92+
message: message,
93+
offset: offset,
94+
url: null,
95+
);
9796

9897
/// Initialize a newly created analysis error. The error is associated with
9998
/// the given [source] and is located at the given [offset] with the given
10099
/// [length]. The error will have the given [errorCode] and the list of
101100
/// [arguments] will be used to complete the message and correction. If any
102101
/// [contextMessages] are provided, they will be recorded with the error.
103-
AnalysisError.tmp({
104-
required this.source,
102+
factory AnalysisError.tmp({
103+
required Source source,
105104
required int offset,
106105
required int length,
107-
required this.errorCode,
106+
required ErrorCode errorCode,
108107
List<Object?> arguments = const [],
109108
List<DiagnosticMessage> contextMessages = const [],
110-
this.data,
111-
}) : _contextMessages = contextMessages {
109+
Object? data,
110+
}) {
112111
assert(
113112
arguments.length == errorCode.numParameters,
114113
'Message $errorCode requires ${errorCode.numParameters} '
@@ -117,17 +116,22 @@ class AnalysisError implements Diagnostic {
117116
'argument${arguments.length == 1 ? ' was' : 's were'} '
118117
'provided',
119118
);
120-
String problemMessage = formatList(errorCode.problemMessage, arguments);
119+
String message = formatList(errorCode.problemMessage, arguments);
121120
String? correctionTemplate = errorCode.correctionMessage;
121+
String? correctionMessage;
122122
if (correctionTemplate != null) {
123-
_correctionMessage = formatList(correctionTemplate, arguments);
123+
correctionMessage = formatList(correctionTemplate, arguments);
124124
}
125-
_problemMessage = DiagnosticMessageImpl(
126-
filePath: source.fullName,
127-
length: length,
128-
message: problemMessage,
125+
126+
return AnalysisError.forValues(
127+
source: source,
129128
offset: offset,
130-
url: null,
129+
length: length,
130+
errorCode: errorCode,
131+
message: message,
132+
correctionMessage: correctionMessage,
133+
contextMessages: contextMessages,
134+
data: data,
131135
);
132136
}
133137

@@ -152,18 +156,15 @@ class AnalysisError implements Diagnostic {
152156

153157
/// The number of characters from the offset to the end of the source which
154158
/// encompasses the compilation error.
155-
int get length => _problemMessage.length;
159+
int get length => problemMessage.length;
156160

157161
/// Return the message to be displayed for this error. The message should
158162
/// indicate what is wrong and why it is wrong.
159-
String get message => _problemMessage.messageText(includeUrl: true);
163+
String get message => problemMessage.messageText(includeUrl: true);
160164

161165
/// The character offset from the beginning of the source (zero based) where
162166
/// the error occurred.
163-
int get offset => _problemMessage.offset;
164-
165-
@override
166-
DiagnosticMessage get problemMessage => _problemMessage;
167+
int get offset => problemMessage.offset;
167168

168169
@override
169170
Severity get severity {

0 commit comments

Comments
 (0)