@@ -96,87 +96,102 @@ class DiagnosticReporter {
9696 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
9797 ///
9898 /// The location of the diagnostic will be the name of the [node] .
99- void atConstructorDeclaration (
99+ ///
100+ /// The reported [Diagnostic] is returned so that the caller may attach
101+ /// additional information to it (for example, using an expando).
102+ Diagnostic atConstructorDeclaration (
100103 ConstructorDeclaration node,
101104 DiagnosticCode diagnosticCode, {
102105 List <Object >? arguments,
103106 List <DiagnosticMessage >? contextMessages,
104- Object ? data,
107+ @Deprecated ( 'Use an expando instead' ) Object ? data,
105108 }) {
106109 // TODO(brianwilkerson): Consider extending this method to take any
107110 // declaration and compute the correct range for the name of that
108111 // declaration. This might make it easier to be consistent.
109112 if (node.name case var nameToken? ) {
110113 var offset = node.returnType.offset;
111- atOffset (
114+ return atOffset (
112115 offset: offset,
113116 length: nameToken.end - offset,
114117 diagnosticCode: diagnosticCode,
115118 arguments: arguments,
116119 );
117120 } else {
118- atNode (node.returnType, diagnosticCode, arguments: arguments);
121+ return atNode (node.returnType, diagnosticCode, arguments: arguments);
119122 }
120123 }
121124
122125 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
123126 ///
124127 /// The [element] is used to compute the location of the diagnostic.
128+ ///
129+ /// The reported [Diagnostic] is returned so that the caller may attach
130+ /// additional information to it (for example, using an expando).
125131 @experimental
126- void atElement2 (
132+ Diagnostic atElement2 (
127133 Element element,
128134 DiagnosticCode diagnosticCode, {
129135 List <Object >? arguments,
130136 List <DiagnosticMessage >? contextMessages,
131- Object ? data,
137+ @Deprecated ( 'Use an expando instead' ) Object ? data,
132138 }) {
133139 var nonSynthetic = element.nonSynthetic;
134- atOffset (
140+ return atOffset (
135141 diagnosticCode: diagnosticCode,
136142 offset: nonSynthetic.firstFragment.nameOffset ?? - 1 ,
137143 length: nonSynthetic.name? .length ?? 0 ,
138144 arguments: arguments,
139145 contextMessages: contextMessages,
146+ // ignore: deprecated_member_use_from_same_package
140147 data: data,
141148 );
142149 }
143150
144151 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
145152 ///
146153 /// The [entity] is used to compute the location of the diagnostic.
147- void atEntity (
154+ ///
155+ /// The reported [Diagnostic] is returned so that the caller may attach
156+ /// additional information to it (for example, using an expando).
157+ Diagnostic atEntity (
148158 SyntacticEntity entity,
149159 DiagnosticCode diagnosticCode, {
150160 List <Object >? arguments,
151161 List <DiagnosticMessage >? contextMessages,
152- Object ? data,
162+ @Deprecated ( 'Use an expando instead' ) Object ? data,
153163 }) {
154- atOffset (
164+ return atOffset (
155165 diagnosticCode: diagnosticCode,
156166 offset: entity.offset,
157167 length: entity.length,
158168 arguments: arguments,
159169 contextMessages: contextMessages,
170+ // ignore: deprecated_member_use_from_same_package
160171 data: data,
161172 );
162173 }
163174
164175 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
165176 ///
166177 /// The [node] is used to compute the location of the diagnostic.
167- void atNode (
178+ ///
179+ /// The reported [Diagnostic] is returned so that the caller may attach
180+ /// additional information to it (for example, using an expando).
181+ Diagnostic atNode (
168182 AstNode node,
169183 DiagnosticCode diagnosticCode, {
170184 List <Object >? arguments,
171185 List <DiagnosticMessage >? contextMessages,
172- Object ? data,
186+ @Deprecated ( 'Use an expando instead' ) Object ? data,
173187 }) {
174- atOffset (
188+ return atOffset (
175189 diagnosticCode: diagnosticCode,
176190 offset: node.offset,
177191 length: node.length,
178192 arguments: arguments,
179193 contextMessages: contextMessages,
194+ // ignore: deprecated_member_use_from_same_package
180195 data: data,
181196 );
182197 }
@@ -186,18 +201,18 @@ class DiagnosticReporter {
186201 ///
187202 /// The location of the diagnostic is specified by the given [offset] and
188203 /// [length] .
189- void atOffset ({
204+ ///
205+ /// The reported [Diagnostic] is returned so that the caller may attach
206+ /// additional information to it (for example, using an expando).
207+ Diagnostic atOffset ({
190208 required int offset,
191209 required int length,
192210 @Deprecated ("Use 'diagnosticCode' instead" ) DiagnosticCode ? errorCode,
193211 DiagnosticCode ? diagnosticCode,
194212 List <Object >? arguments,
195213 List <DiagnosticMessage >? contextMessages,
196- Object ? data,
214+ @Deprecated ( 'Use an expando instead' ) Object ? data,
197215 }) {
198- if (lockLevel != 0 ) {
199- return ;
200- }
201216 if ((errorCode == null && diagnosticCode == null ) ||
202217 (errorCode != null && diagnosticCode != null )) {
203218 throw ArgumentError (
@@ -225,61 +240,73 @@ class DiagnosticReporter {
225240
226241 contextMessages ?? = [];
227242 contextMessages.addAll (convertTypeNames (arguments));
228- _diagnosticListener.onDiagnostic (
229- Diagnostic .tmp (
230- source: _source,
231- offset: offset,
232- length: length,
233- diagnosticCode: diagnosticCode,
234- arguments: arguments ?? const [],
235- contextMessages: contextMessages,
236- data: data,
237- ),
243+ var diagnostic = Diagnostic .tmp (
244+ source: _source,
245+ offset: offset,
246+ length: length,
247+ diagnosticCode: diagnosticCode,
248+ arguments: arguments ?? const [],
249+ contextMessages: contextMessages,
250+ // ignore: deprecated_member_use_from_same_package
251+ data: data,
238252 );
253+ reportError (diagnostic);
254+ return diagnostic;
239255 }
240256
241257 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
242258 ///
243259 /// The [span] is used to compute the location of the diagnostic.
244- void atSourceSpan (
260+ ///
261+ /// The reported [Diagnostic] is returned so that the caller may attach
262+ /// additional information to it (for example, using an expando).
263+ Diagnostic atSourceSpan (
245264 SourceSpan span,
246265 DiagnosticCode diagnosticCode, {
247266 List <Object >? arguments,
248267 List <DiagnosticMessage >? contextMessages,
249- Object ? data,
268+ @Deprecated ( 'Use an expando instead' ) Object ? data,
250269 }) {
251- atOffset (
270+ return atOffset (
252271 diagnosticCode: diagnosticCode,
253272 offset: span.start.offset,
254273 length: span.length,
255274 arguments: arguments,
256275 contextMessages: contextMessages,
276+ // ignore: deprecated_member_use_from_same_package
257277 data: data,
258278 );
259279 }
260280
261281 /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
262282 ///
263283 /// The [token] is used to compute the location of the diagnostic.
264- void atToken (
284+ ///
285+ /// The reported [Diagnostic] is returned so that the caller may attach
286+ /// additional information to it (for example, using an expando).
287+ Diagnostic atToken (
265288 Token token,
266289 DiagnosticCode diagnosticCode, {
267290 List <Object >? arguments,
268291 List <DiagnosticMessage >? contextMessages,
269- Object ? data,
292+ @Deprecated ( 'Use an expando instead' ) Object ? data,
270293 }) {
271- atOffset (
294+ return atOffset (
272295 diagnosticCode: diagnosticCode,
273296 offset: token.offset,
274297 length: token.length,
275298 arguments: arguments,
276299 contextMessages: contextMessages,
300+ // ignore: deprecated_member_use_from_same_package
277301 data: data,
278302 );
279303 }
280304
281305 /// Report the given [diagnostic] .
282306 void reportError (Diagnostic diagnostic) {
307+ if (lockLevel != 0 ) {
308+ return ;
309+ }
283310 _diagnosticListener.onDiagnostic (diagnostic);
284311 }
285312}
0 commit comments