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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 /// Encodes the category of the message. | 63 /// Encodes the category of the message. |
64 /// | 64 /// |
65 /// This is currently only used in the analyzer. | 65 /// This is currently only used in the analyzer. |
66 // TODO(floitsch): encode severity and type in the category, so we can generate | 66 // TODO(floitsch): encode severity and type in the category, so we can generate |
67 // the corresponding ErrorCode subclasses. | 67 // the corresponding ErrorCode subclasses. |
68 class Category { | 68 class Category { |
69 static final analysisOptionsError = new Category("AnalysisOptionsError"); | 69 static final analysisOptionsError = new Category("AnalysisOptionsError"); |
70 | 70 |
71 static final analysisOptionsWarning = new Category("AnalysisOptionsWarning"); | 71 static final analysisOptionsWarning = new Category("AnalysisOptionsWarning"); |
72 | 72 |
73 static final checkedModeCompileTimeError = new Category( | 73 static final checkedModeCompileTimeError = |
74 "CheckedModeCompileTimeError"); | 74 new Category("CheckedModeCompileTimeError"); |
75 | |
76 static final parserError = new Category("ParserError"); | |
75 | 77 |
76 final String name; | 78 final String name; |
77 | 79 |
78 Category(this.name); | 80 Category(this.name); |
79 } | 81 } |
80 | 82 |
83 enum Platform { | |
84 dart2js, analyzer, | |
85 } | |
86 const dart2js = Platform.dart2js; | |
87 const analyzer = Platform.analyzer; | |
81 | 88 |
82 class Message { | 89 class Message { |
83 final String id; | 90 final String id; |
91 final int subId; | |
84 final Category category; | 92 final Category category; |
85 final String template; | 93 final String template; |
86 // The analyzer fills holes positionally (and not named). The following field | 94 // The analyzer fills holes positionally (and not named). The following field |
87 // overrides the order of the holes. | 95 // overrides the order of the holes. |
88 // For example the template "The argument #field in #cls is bad", could have | 96 // For example the template "The argument #field in #cls is bad", could have |
89 // the order `["cls", "field"]', which means that the analyzer would first | 97 // the order `["cls", "field"]', which means that the analyzer would first |
90 // provide the class `cls` and then only `field`. | 98 // provide the class `cls` and then only `field`. |
91 // This list is generally `null`, but when it is provided it must contain all | 99 // This list is generally `null`, but when it is provided it must contain all |
92 // holes. | 100 // holes. |
93 final List templateHoleOrder; | 101 final List<String> templateHoleOrder; |
94 final String howToFix; | 102 final String howToFix; |
95 final List<String> options; | 103 final List<String> options; |
96 final List examples; | 104 final List examples; |
105 final List<Platform> usedBy; | |
97 | 106 |
98 Message({this.id, this.category, this.template, this.templateHoleOrder, | 107 Message( |
99 this.howToFix, this.options, this.examples}); | 108 {this.id, |
109 this.subId: 0, | |
110 this.category, | |
111 this.template, | |
112 this.templateHoleOrder, | |
113 this.howToFix, | |
114 this.options, | |
115 this.usedBy: const [], | |
116 this.examples}); | |
100 } | 117 } |
101 | 118 |
102 String get messagesAsJson { | 119 String get messagesAsJson { |
103 var jsonified = {}; | 120 var jsonified = {}; |
104 MESSAGES.forEach((String name, Message message) { | 121 MESSAGES.forEach((String name, Message message) { |
105 jsonified[name] = { | 122 jsonified[name] = { |
106 'id': message.id, | 123 'id': message.id, |
124 'subId': message.subId, | |
107 'category': message.category.name, | 125 'category': message.category.name, |
108 'template': message.template, | 126 'template': message.template, |
109 'howToFix': message.howToFix | 127 'templateHoleOrder': message.templateHoleOrder, |
128 'howToFix': message.howToFix, | |
129 'options': message.options, | |
130 'usedBy': message.usedBy.map((platform) => platform.toString()).toList(), | |
131 'examples': message.examples, | |
110 }; | 132 }; |
111 }); | 133 }); |
112 return JSON.encode(jsonified); | 134 return JSON.encode(jsonified); |
113 } | 135 } |
114 | 136 |
115 final Map<String, Message> MESSAGES = { | 137 final Map<String, Message> MESSAGES = { |
116 'exampleMessage': new Message( | 138 'exampleMessage': new Message( |
117 id: 'use an Id generated by bin/message_id.dart', | 139 id: 'use an Id generated by bin/message_id.dart', |
118 category: Category.analysisOptionsError, | 140 category: Category.analysisOptionsError, |
119 template: "#use #named #arguments", | 141 template: "#use #named #arguments", |
120 templateHoleOrder: ["arguments", "named", "use"], | 142 templateHoleOrder: ["arguments", "named", "use"], |
121 howToFix: "an explanation on how to fix things", | 143 howToFix: "an explanation on how to fix things", |
122 examples: [r''' | 144 examples: [ |
145 r''' | |
123 Some multiline example; | 146 Some multiline example; |
124 That generates the bug.''', | 147 That generates the bug.''', |
125 { | 148 { |
126 'fileA.dart': ''' | 149 'fileA.dart': ''' |
127 or a map from file to content. | 150 or a map from file to content. |
128 again multiline''', | 151 again multiline''', |
129 'fileB.dart': ''' | 152 'fileB.dart': ''' |
130 with possibly multiple files. | 153 with possibly multiple files. |
131 muliline too''' | 154 muliline too''' |
132 } | 155 } |
133 ] | 156 ]), |
134 ), | 157 |
158 // Const constructors (factory or not) may not have a body. | |
159 'CONST_CONSTRUCTOR_OR_FACTORY_WITH_BODY': new Message( | |
160 id: 'LGJGHW', | |
161 subId: 0, | |
162 category: Category.parserError, | |
163 template: "Const constructor or factory cannot have a body.", | |
Johnni Winther
2016/02/04 08:40:11
`cannot` -> `can't` ? (cf. item 6 in the dartdoc)
floitsch
2016/02/04 10:44:41
Done.
| |
164 howToFix: "Remove the 'const' keyword or the body.", | |
Johnni Winther
2016/02/04 08:40:11
I think the [howToFix] should be a suggestion and
floitsch
2016/02/04 10:44:41
Done.
| |
165 usedBy: [dart2js], | |
166 examples: const [ | |
167 r""" | |
168 class C { | |
169 const C() {} | |
170 } | |
171 | |
172 main() => new C();""", | |
173 r""" | |
174 class C { | |
175 const factory C() {} | |
176 } | |
177 | |
178 main() => new C();""" | |
179 ]), | |
180 // Const constructors may not have a body. | |
181 'CONST_CONSTRUCTOR_WITH_BODY': new Message( | |
182 id: 'LGJGHW', | |
183 subId: 1, | |
184 category: Category.parserError, | |
185 template: "Const constructor cannot have a body.", | |
186 howToFix: "Remove the 'const' keyword or the body.", | |
187 usedBy: [analyzer], | |
188 examples: const [ | |
189 r""" | |
190 class C { | |
191 const C() {} | |
192 } | |
193 | |
194 main() => new C();""" | |
195 ]), | |
196 // Const constructor factories may only redirect (and must not have a body). | |
197 'CONST_FACTORY': new Message( | |
198 id: 'LGJGHW', | |
199 subId: 2, | |
200 category: Category.parserError, | |
201 template: | |
202 "Only redirecting factory constructors can be declared to be 'const'", | |
Johnni Winther
2016/02/04 08:40:11
Add period to finish the sentence.
floitsch
2016/02/04 10:44:41
Done.
| |
203 howToFix: "Remove the 'const' keyword or replace the body with '=' " | |
204 "followed by a valid target", | |
Johnni Winther
2016/02/04 08:40:11
Ditto.
floitsch
2016/02/04 10:44:41
Done.
| |
205 usedBy: [analyzer], | |
206 examples: const [ | |
207 r""" | |
208 class C { | |
209 const factory C() {} | |
210 } | |
211 | |
212 main() => new C();""" | |
213 ]), | |
135 }; | 214 }; |
OLD | NEW |