OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // An update to this file must be followed by regenerating the corresponding | 5 // An update to this file must be followed by regenerating the corresponding |
6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory. | 6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory. |
7 // | 7 // |
8 // Every message in this file must have an id. Use `message_id.dart` in the | 8 // Every message in this file must have an id. Use `message_id.dart` in the |
9 // bin directory to generate a fresh one. | 9 // bin directory to generate a fresh one. |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 static final checkedModeCompileTimeError = | 73 static final checkedModeCompileTimeError = |
74 new Category("CheckedModeCompileTimeError"); | 74 new Category("CheckedModeCompileTimeError"); |
75 | 75 |
76 static final parserError = new Category("ParserError"); | 76 static final parserError = new Category("ParserError"); |
77 | 77 |
78 final String name; | 78 final String name; |
79 | 79 |
80 Category(this.name); | 80 Category(this.name); |
81 } | 81 } |
82 | 82 |
83 enum Platform { | 83 enum Platform { dart2js, analyzer, } |
84 dart2js, analyzer, | |
85 } | |
86 const dart2js = Platform.dart2js; | 84 const dart2js = Platform.dart2js; |
87 const analyzer = Platform.analyzer; | 85 const analyzer = Platform.analyzer; |
88 | 86 |
89 class Message { | 87 class Message { |
88 /// Generic id for this message. | |
89 /// | |
90 /// This id should be shared by all errors that fall into the same category. | |
91 /// In particular, we want errors of the same category to share the same | |
92 /// explanation page, and want to disable warnings of the same category | |
93 /// with just one line. | |
90 final String id; | 94 final String id; |
95 | |
96 /// The sub-id of the error. | |
97 /// | |
98 /// This id just needs to be unique within the same [id]. | |
91 final int subId; | 99 final int subId; |
100 | |
101 /// The error sub-id of which this message is a specialization. | |
102 /// | |
103 /// For example, "Const is not allowed on getters" may be a specialization of | |
104 /// "The 'const' keyword is not allowed here". | |
105 /// | |
106 /// Examples of the specialized message, should trigger for the more generic | |
107 /// message, when the platform doesn't support the more specialized message. | |
108 final int specializationOf; | |
109 | |
92 final Category category; | 110 final Category category; |
93 final String template; | 111 final String template; |
94 // The analyzer fills holes positionally (and not named). The following field | 112 // The analyzer fills holes positionally (and not named). The following field |
95 // overrides the order of the holes. | 113 // overrides the order of the holes. |
96 // For example the template "The argument #field in #cls is bad", could have | 114 // For example the template "The argument #field in #cls is bad", could have |
97 // the order `["cls", "field"]', which means that the analyzer would first | 115 // the order `["cls", "field"]', which means that the analyzer would first |
98 // provide the class `cls` and then only `field`. | 116 // provide the class `cls` and then only `field`. |
99 // This list is generally `null`, but when it is provided it must contain all | 117 // This list is generally `null`, but when it is provided it must contain all |
100 // holes. | 118 // holes. |
101 final List<String> templateHoleOrder; | 119 final List<String> templateHoleOrder; |
102 final String howToFix; | 120 final String howToFix; |
103 final List<String> options; | 121 final List<String> options; |
104 final List examples; | 122 final List examples; |
105 final List<Platform> usedBy; | 123 final List<Platform> usedBy; |
106 | 124 |
107 Message( | 125 Message( |
108 {this.id, | 126 {this.id, |
109 this.subId: 0, | 127 this.subId: 0, |
128 this.specializationOf: -1, | |
110 this.category, | 129 this.category, |
111 this.template, | 130 this.template, |
112 this.templateHoleOrder, | 131 this.templateHoleOrder, |
113 this.howToFix, | 132 this.howToFix, |
114 this.options, | 133 this.options, |
115 this.usedBy: const [], | 134 this.usedBy: const [], |
116 this.examples}); | 135 this.examples}); |
117 } | 136 } |
118 | 137 |
119 String get messagesAsJson { | 138 String get messagesAsJson { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } | 174 } |
156 ]), | 175 ]), |
157 | 176 |
158 // Const constructors (factory or not) may not have a body. | 177 // Const constructors (factory or not) may not have a body. |
159 'CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY': new Message( | 178 'CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY': new Message( |
160 id: 'LGJGHW', | 179 id: 'LGJGHW', |
161 subId: 0, | 180 subId: 0, |
162 category: Category.parserError, | 181 category: Category.parserError, |
163 template: "Const constructor or factory can't have a body.", | 182 template: "Const constructor or factory can't have a body.", |
164 howToFix: "Remove the 'const' keyword or the body.", | 183 howToFix: "Remove the 'const' keyword or the body.", |
165 usedBy: [dart2js], | 184 usedBy: [ |
185 dart2js | |
186 ], | |
166 examples: const [ | 187 examples: const [ |
167 r""" | 188 r""" |
168 class C { | 189 class C { |
169 const C() {} | 190 const C() {} |
170 } | 191 } |
171 | 192 |
172 main() => new C();""", | 193 main() => new C();""", |
173 r""" | 194 r""" |
174 class C { | 195 class C { |
175 const factory C() {} | 196 const factory C() {} |
176 } | 197 } |
177 | 198 |
178 main() => new C();""" | 199 main() => new C();""" |
179 ]), | 200 ]), |
180 // Const constructors may not have a body. | 201 // Const constructors may not have a body. |
181 'CONST_CONSTRUCTOR_WITH_BODY': new Message( | 202 'CONST_CONSTRUCTOR_WITH_BODY': new Message( |
182 id: 'LGJGHW', | 203 id: 'LGJGHW', |
183 subId: 1, | 204 subId: 1, |
205 specializationOf: 0, | |
184 category: Category.parserError, | 206 category: Category.parserError, |
185 template: "Const constructor can't have a body.", | 207 template: "Const constructor can't have a body.", |
186 howToFix: "Try removing the 'const' keyword or the body.", | 208 howToFix: "Try removing the 'const' keyword or the body.", |
187 usedBy: [analyzer], | 209 usedBy: [ |
210 analyzer | |
211 ], | |
188 examples: const [ | 212 examples: const [ |
189 r""" | 213 r""" |
190 class C { | 214 class C { |
191 const C() {} | 215 const C() {} |
192 } | 216 } |
193 | 217 |
194 main() => new C();""" | 218 main() => new C();""" |
195 ]), | 219 ]), |
196 // Const constructor factories may only redirect (and must not have a body). | 220 // Const constructor factories may only redirect (and must not have a body). |
197 'CONST_FACTORY': new Message( | 221 'CONST_FACTORY': new Message( |
198 id: 'LGJGHW', | 222 id: 'LGJGHW', |
199 subId: 2, | 223 subId: 2, |
224 specializationOf: 0, | |
200 category: Category.parserError, | 225 category: Category.parserError, |
201 template: "Only redirecting factory constructors can be declared to " | 226 template: "Only redirecting factory constructors can be declared to " |
202 "be 'const'.", | 227 "be 'const'.", |
203 howToFix: "Try removing the 'const' keyword or replacing the body with " | 228 howToFix: "Try removing the 'const' keyword or replacing the body with " |
204 "'=' followed by a valid target", | 229 "'=' followed by a valid target.", |
205 usedBy: [analyzer], | 230 usedBy: [ |
231 analyzer | |
232 ], | |
206 examples: const [ | 233 examples: const [ |
207 r""" | 234 r""" |
208 class C { | 235 class C { |
209 const factory C() {} | 236 const factory C() {} |
210 } | 237 } |
211 | 238 |
212 main() => new C();""" | 239 main() => new C();""" |
213 ]), | 240 ]), |
241 | |
242 'EXTRANEOUS_MODIFIER': new Message( | |
243 id: 'GRKIQE', | |
244 subId: 0, | |
245 category: Category.parserError, | |
246 template: "Can't have modifier '#{modifier}' here.", | |
247 howToFix: "Try removing '#{modifier}'.", | |
248 usedBy: [ | |
249 dart2js | |
250 ], | |
251 examples: const [ | |
252 "var String foo; main(){}", | |
253 // "var get foo; main(){}", | |
254 "var set foo; main(){}", | |
255 "var final foo; main(){}", | |
256 "var var foo; main(){}", | |
257 "var const foo; main(){}", | |
258 "var abstract foo; main(){}", | |
259 "var static foo; main(){}", | |
260 "var external foo; main(){}", | |
261 "get var foo; main(){}", | |
262 "set var foo; main(){}", | |
263 "final var foo; main(){}", | |
264 "var var foo; main(){}", | |
265 "const var foo; main(){}", | |
266 "abstract var foo; main(){}", | |
267 "static var foo; main(){}", | |
268 "external var foo; main(){}" | |
269 ]), | |
270 | |
271 'EXTRANEOUS_MODIFIER_REPLACE': new Message( | |
272 id: 'GRKIQE', | |
273 subId: 1, | |
274 category: Category.parserError, | |
275 template: "Can't have modifier '#{modifier}' here.", | |
276 howToFix: "Try replacing modifier '#{modifier}' with 'var', 'final', " | |
277 "or a type.", | |
278 usedBy: [ | |
279 dart2js | |
280 ], | |
281 examples: const [ | |
282 // "get foo; main(){}", | |
283 "set foo; main(){}", | |
284 "abstract foo; main(){}", | |
285 "static foo; main(){}", | |
286 "external foo; main(){}" | |
287 ]), | |
288 | |
289 'CONST_CLASS': new Message( | |
290 id: 'GRKIQE', | |
291 subId: 2, | |
292 // The specialization could also be 1, but the example below triggers 0. | |
293 specializationOf: 0, | |
294 category: Category.parserError, | |
295 template: "Classes can't be declared to be 'const'", | |
296 howToFix: "Try removing the 'const' keyword or moving to the class'" | |
297 " constructor.", | |
Brian Wilkerson
2016/02/17 15:01:21
"constructor" --> "constructor(s)"
floitsch
2016/02/17 15:26:44
Done.
| |
298 usedBy: [ | |
299 analyzer | |
300 ], | |
301 examples: const [ | |
302 r""" | |
303 const class C {} | |
304 | |
305 main() => new C(); | |
306 """ | |
307 ]), | |
308 | |
309 'CONST_METHOD': new Message( | |
310 id: 'GRKIQE', | |
311 subId: 3, | |
312 // The specialization could also be 1, but the example below triggers 0. | |
313 specializationOf: 0, | |
314 category: Category.parserError, | |
315 template: "Getters, setters and methods can't be declared to be 'const'", | |
316 howToFix: "Try removing the 'const' keyword or moving to the class'" | |
317 " constructor.", | |
Brian Wilkerson
2016/02/17 15:01:20
Remove " or moving to the class' constructor"; it'
floitsch
2016/02/17 15:26:44
Done.
| |
318 usedBy: [ | |
319 analyzer | |
320 ], | |
321 examples: const [ | |
322 "const int foo() => 499; main() {}", | |
323 "const int get foo => 499; main() {}", | |
324 "const set foo(v) => 499; main() {}", | |
325 "class A { const int foo() => 499; } main() { new A(); }", | |
326 "class A { const int get foo => 499; } main() { new A(); }", | |
327 "class A { const set foo(v) => 499; } main() { new A(); }", | |
328 ]), | |
329 | |
330 'CONST_ENUM': new Message( | |
331 id: 'GRKIQE', | |
332 subId: 4, | |
333 // The specialization could also be 1, but the example below triggers 0. | |
334 specializationOf: 0, | |
335 category: Category.parserError, | |
336 template: "Enums can't be declared to be 'const'", | |
337 howToFix: "Try removing the 'const' keyword.", | |
338 usedBy: [analyzer], | |
339 examples: const ["const enum Foo { x } main() {}",]), | |
340 | |
341 'CONST_TYPEDEF': new Message( | |
342 id: 'GRKIQE', | |
343 subId: 5, | |
344 // The specialization could also be 1, but the example below triggers 0. | |
345 specializationOf: 0, | |
346 category: Category.parserError, | |
347 template: "Type aliases can't be declared to be 'const'", | |
348 howToFix: "Try removing the 'const' keyword.", | |
349 usedBy: [analyzer], | |
350 examples: const ["const typedef void Foo(); main() {}",]), | |
351 | |
352 'CONST_AND_FINAL': new Message( | |
353 id: 'GRKIQE', | |
354 subId: 6, | |
355 // The specialization could also be 1, but the example below triggers 0. | |
356 specializationOf: 0, | |
357 category: Category.parserError, | |
358 template: "Members cannot be declared to be both 'const' and 'final'", | |
Brian Wilkerson
2016/02/17 15:01:20
"cannot" --> "can't" (for consistency)
floitsch
2016/02/17 15:26:44
Done.
| |
359 howToFix: "Try removing the 'const' or 'final' keyword.", | |
Brian Wilkerson
2016/02/17 15:01:21
"removing the" --> "removing either the"
floitsch
2016/02/17 15:26:44
Done.
| |
360 usedBy: [ | |
361 analyzer | |
362 ], | |
363 examples: const [ | |
364 "final const int x = 499; main() {}", | |
365 "const final int x = 499; main() {}", | |
366 "class A { static final const int x = 499; } main() {}", | |
367 "class A { static const final int x = 499; } main() {}", | |
368 ]), | |
369 | |
370 'CONST_AND_VAR': new Message( | |
371 id: 'GRKIQE', | |
372 subId: 7, | |
373 // The specialization could also be 1, but the example below triggers 0. | |
374 specializationOf: 0, | |
375 category: Category.parserError, | |
376 template: "Members cannot be declared to be both 'const' and 'var'", | |
Brian Wilkerson
2016/02/17 15:01:21
"cannot" --> "can't"
floitsch
2016/02/17 15:26:44
Done.
| |
377 howToFix: "Try removing the 'const' or 'var' keyword.", | |
Brian Wilkerson
2016/02/17 15:01:21
"removing the" --> "removing either the"
floitsch
2016/02/17 15:26:44
Done.
| |
378 usedBy: [ | |
379 analyzer | |
380 ], | |
381 examples: const [ | |
382 "var const x = 499; main() {}", | |
383 "const var x = 499; main() {}", | |
384 "class A { var const x = 499; } main() {}", | |
385 "class A { const var x = 499; } main() {}", | |
386 ]), | |
387 | |
388 'CLASS_IN_CLASS': new Message( | |
389 id: 'DOTHQH', | |
390 category: Category.parserError, | |
391 template: "Classes can't be declared inside other classes.", | |
392 howToFix: "Try moving the class to the top-level.", | |
393 usedBy: [analyzer], | |
394 examples: const ["class A { class B {} } main() {}",]), | |
395 | |
396 'CONSTRUCTOR_WITH_RETURN_TYPE': new Message( | |
397 id: 'VOJBWY', | |
398 category: Category.parserError, | |
399 template: "Constructors cannot have a return type", | |
floitsch
2016/02/17 15:26:43
fixed that one too.
| |
400 howToFix: "Try removing the return-type.", | |
floitsch
2016/02/17 15:26:44
changed to "return type".
| |
401 usedBy: [analyzer], | |
402 examples: const ["class A { int A() {} } main() {}",]), | |
214 }; | 403 }; |
OLD | NEW |