Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: pkg/dart_messages/lib/shared_messages.dart

Issue 1700243002: Share const-error messages. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Use double-quotes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dart_messages/lib/generated/shared_messages.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(s).",
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.",
317 usedBy: [
318 analyzer
319 ],
320 examples: const [
321 "const int foo() => 499; main() {}",
322 "const int get foo => 499; main() {}",
323 "const set foo(v) => 499; main() {}",
324 "class A { const int foo() => 499; } main() { new A(); }",
325 "class A { const int get foo => 499; } main() { new A(); }",
326 "class A { const set foo(v) => 499; } main() { new A(); }",
327 ]),
328
329 'CONST_ENUM': new Message(
330 id: 'GRKIQE',
331 subId: 4,
332 // The specialization could also be 1, but the example below triggers 0.
333 specializationOf: 0,
334 category: Category.parserError,
335 template: "Enums can't be declared to be 'const'",
336 howToFix: "Try removing the 'const' keyword.",
337 usedBy: [analyzer],
338 examples: const ["const enum Foo { x } main() {}",]),
339
340 'CONST_TYPEDEF': new Message(
341 id: 'GRKIQE',
342 subId: 5,
343 // The specialization could also be 1, but the example below triggers 0.
344 specializationOf: 0,
345 category: Category.parserError,
346 template: "Type aliases can't be declared to be 'const'",
347 howToFix: "Try removing the 'const' keyword.",
348 usedBy: [analyzer],
349 examples: const ["const typedef void Foo(); main() {}",]),
350
351 'CONST_AND_FINAL': new Message(
352 id: 'GRKIQE',
353 subId: 6,
354 // The specialization could also be 1, but the example below triggers 0.
355 specializationOf: 0,
356 category: Category.parserError,
357 template: "Members can't be declared to be both 'const' and 'final'",
358 howToFix: "Try removing either the 'const' or 'final' keyword.",
359 usedBy: [
360 analyzer
361 ],
362 examples: const [
363 "final const int x = 499; main() {}",
364 "const final int x = 499; main() {}",
365 "class A { static final const int x = 499; } main() {}",
366 "class A { static const final int x = 499; } main() {}",
367 ]),
368
369 'CONST_AND_VAR': new Message(
370 id: 'GRKIQE',
371 subId: 7,
372 // The specialization could also be 1, but the example below triggers 0.
373 specializationOf: 0,
374 category: Category.parserError,
375 template: "Members can't be declared to be both 'const' and 'var'",
376 howToFix: "Try removing either the 'const' or 'var' keyword.",
377 usedBy: [
378 analyzer
379 ],
380 examples: const [
381 "var const x = 499; main() {}",
382 "const var x = 499; main() {}",
383 "class A { var const x = 499; } main() {}",
384 "class A { const var x = 499; } main() {}",
385 ]),
386
387 'CLASS_IN_CLASS': new Message(
388 id: 'DOTHQH',
389 category: Category.parserError,
390 template: "Classes can't be declared inside other classes.",
391 howToFix: "Try moving the class to the top-level.",
392 usedBy: [analyzer],
393 examples: const ["class A { class B {} } main() {}",]),
394
395 'CONSTRUCTOR_WITH_RETURN_TYPE': new Message(
396 id: 'VOJBWY',
397 category: Category.parserError,
398 template: "Constructors can't have a return type",
399 howToFix: "Try removing the return type.",
400 usedBy: [analyzer],
401 examples: const ["class A { int A() {} } main() {}",]),
214 }; 402 };
OLDNEW
« no previous file with comments | « pkg/dart_messages/lib/generated/shared_messages.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698