@@ -65,11 +65,12 @@ class ErrorReporter {
6565
6666 Source get source => _source;
6767
68- /// Report a diagnostic with the given [errorCode] and [arguments] .
68+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
69+ ///
6970 /// The location of the diagnostic will be the name of the [node] .
7071 void atConstructorDeclaration (
7172 ConstructorDeclaration node,
72- DiagnosticCode errorCode , {
73+ DiagnosticCode diagnosticCode , {
7374 List <Object >? arguments,
7475 List <DiagnosticMessage >? contextMessages,
7576 Object ? data,
@@ -82,27 +83,28 @@ class ErrorReporter {
8283 atOffset (
8384 offset: offset,
8485 length: nameToken.end - offset,
85- errorCode : errorCode ,
86+ diagnosticCode : diagnosticCode ,
8687 arguments: arguments,
8788 );
8889 } else {
89- atNode (node.returnType, errorCode , arguments: arguments);
90+ atNode (node.returnType, diagnosticCode , arguments: arguments);
9091 }
9192 }
9293
93- /// Report an error with the given [diagnosticCode] and [arguments] .
94- /// The [element] is used to compute the location of the error.
94+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
95+ ///
96+ /// The [element] is used to compute the location of the diagnostic.
9597 @experimental
9698 void atElement2 (
97- Element element2 ,
99+ Element element ,
98100 DiagnosticCode diagnosticCode, {
99101 List <Object >? arguments,
100102 List <DiagnosticMessage >? contextMessages,
101103 Object ? data,
102104 }) {
103- var nonSynthetic = element2 .nonSynthetic2;
105+ var nonSynthetic = element .nonSynthetic2;
104106 atOffset (
105- errorCode : diagnosticCode,
107+ diagnosticCode : diagnosticCode,
106108 offset: nonSynthetic.firstFragment.nameOffset2 ?? - 1 ,
107109 length: nonSynthetic.name3? .length ?? 0 ,
108110 arguments: arguments,
@@ -111,17 +113,18 @@ class ErrorReporter {
111113 );
112114 }
113115
114- /// Report an error with the given [errorCode] and [arguments] .
115- /// The [entity] is used to compute the location of the error.
116+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
117+ ///
118+ /// The [entity] is used to compute the location of the diagnostic.
116119 void atEntity (
117120 SyntacticEntity entity,
118- DiagnosticCode errorCode , {
121+ DiagnosticCode diagnosticCode , {
119122 List <Object >? arguments,
120123 List <DiagnosticMessage >? contextMessages,
121124 Object ? data,
122125 }) {
123126 atOffset (
124- errorCode : errorCode ,
127+ diagnosticCode : diagnosticCode ,
125128 offset: entity.offset,
126129 length: entity.length,
127130 arguments: arguments,
@@ -130,8 +133,9 @@ class ErrorReporter {
130133 );
131134 }
132135
133- /// Report an error with the given [diagnosticCode] and [arguments] .
134- /// The [node] is used to compute the location of the error.
136+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
137+ ///
138+ /// The [node] is used to compute the location of the diagnostic.
135139 void atNode (
136140 AstNode node,
137141 DiagnosticCode diagnosticCode, {
@@ -140,7 +144,7 @@ class ErrorReporter {
140144 Object ? data,
141145 }) {
142146 atOffset (
143- errorCode : diagnosticCode,
147+ diagnosticCode : diagnosticCode,
144148 offset: node.offset,
145149 length: node.length,
146150 arguments: arguments,
@@ -149,19 +153,31 @@ class ErrorReporter {
149153 );
150154 }
151155
152- /// Report an error with the given [errorCode] and [arguments] . The location
153- /// of the error is specified by the given [offset] and [length] .
156+ /// Reports a diagnostic with the given [diagnosticCode] (or [errorCode] ,
157+ /// deprecated) and [arguments] .
158+ ///
159+ /// The location of the diagnostic is specified by the given [offset] and
160+ /// [length] .
154161 void atOffset ({
155162 required int offset,
156163 required int length,
157- required DiagnosticCode errorCode,
164+ @Deprecated ("Use 'diagnosticCode' instead" ) DiagnosticCode ? errorCode,
165+ DiagnosticCode ? diagnosticCode,
158166 List <Object >? arguments,
159167 List <DiagnosticMessage >? contextMessages,
160168 Object ? data,
161169 }) {
162170 if (lockLevel != 0 ) {
163171 return ;
164172 }
173+ if ((errorCode == null && diagnosticCode == null ) ||
174+ (errorCode != null && diagnosticCode != null )) {
175+ throw ArgumentError (
176+ "Exactly one of 'errorCode' (deprecated) and 'diagnosticCode' should be given" ,
177+ );
178+ }
179+
180+ diagnosticCode ?? = errorCode! ;
165181
166182 if (arguments != null ) {
167183 var invalid =
@@ -186,25 +202,26 @@ class ErrorReporter {
186202 source: _source,
187203 offset: offset,
188204 length: length,
189- errorCode: errorCode ,
205+ errorCode: diagnosticCode ,
190206 arguments: arguments ?? const [],
191207 contextMessages: contextMessages,
192208 data: data,
193209 ),
194210 );
195211 }
196212
197- /// Report an error with the given [errorCode] and [arguments] .
198- /// The [span] is used to compute the location of the error.
213+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
214+ ///
215+ /// The [span] is used to compute the location of the diagnostic.
199216 void atSourceSpan (
200217 SourceSpan span,
201- DiagnosticCode errorCode , {
218+ DiagnosticCode diagnosticCode , {
202219 List <Object >? arguments,
203220 List <DiagnosticMessage >? contextMessages,
204221 Object ? data,
205222 }) {
206223 atOffset (
207- errorCode : errorCode ,
224+ diagnosticCode : diagnosticCode ,
208225 offset: span.start.offset,
209226 length: span.length,
210227 arguments: arguments,
@@ -213,8 +230,9 @@ class ErrorReporter {
213230 );
214231 }
215232
216- /// Report an error with the given [diagnosticCode] and [arguments] . The [token] is
217- /// used to compute the location of the error.
233+ /// Reports a diagnostic with the given [diagnosticCode] and [arguments] .
234+ ///
235+ /// The [token] is used to compute the location of the diagnostic.
218236 void atToken (
219237 Token token,
220238 DiagnosticCode diagnosticCode, {
@@ -223,7 +241,7 @@ class ErrorReporter {
223241 Object ? data,
224242 }) {
225243 atOffset (
226- errorCode : diagnosticCode,
244+ diagnosticCode : diagnosticCode,
227245 offset: token.offset,
228246 length: token.length,
229247 arguments: arguments,
0 commit comments