Chromium Code Reviews| 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_HAS_BODY': new Message( | |
| 160 id: 'LGJGHW', | |
| 161 category: Category.parserError, | |
|
Brian Wilkerson
2016/02/03 00:27:12
Missing subId?
floitsch
2016/02/03 17:50:25
Missing subid implies 0, but I added it.
Brian Wilkerson
2016/02/03 20:37:22
Good to know.
| |
| 162 template: "Const constructor or factory can't have a body.", | |
| 163 howToFix: "Remove the 'const' keyword or the body.", | |
| 164 usedBy: [dart2js], | |
| 165 examples: const [ | |
| 166 r""" | |
| 167 class C { | |
| 168 const C() {} | |
| 169 } | |
| 170 | |
| 171 main() => new C();""", | |
| 172 r""" | |
| 173 class C { | |
| 174 const factory C() {} | |
| 175 } | |
| 176 | |
| 177 main() => new C();""" | |
| 178 ]), | |
| 179 // Const constructors may not have a body. | |
| 180 'CONST_CONSTRUCTOR_WITH_BODY': new Message( | |
| 181 id: 'LGJGHW', | |
| 182 subId: 1, | |
| 183 category: Category.parserError, | |
| 184 template: "Const constructor or factory can't have a body.", | |
|
Brian Wilkerson
2016/02/03 00:27:12
The "or factory" is confusing. If the constructor
floitsch
2016/02/03 17:50:25
My mistake. Removed the factory part.
I don't want
Brian Wilkerson
2016/02/03 20:37:22
Like I said, every time we change a message we ris
floitsch
2016/02/03 21:15:39
The latest version is "Const constructor cannot ha
Brian Wilkerson
2016/02/03 21:30:59
Sounds good.
| |
| 185 howToFix: "Remove the 'const' keyword or the body.", | |
| 186 usedBy: [analyzer], | |
| 187 examples: const [ | |
| 188 r""" | |
| 189 class C { | |
| 190 const C() {} | |
| 191 } | |
| 192 | |
| 193 main() => new C();""" | |
| 194 ]), | |
| 195 // Const constructor factories may only redirect (and must not have a body). | |
| 196 'CONST_FACTORY': new Message( | |
| 197 id: 'LGJGHW', | |
| 198 subId: 2, | |
| 199 category: Category.parserError, | |
| 200 template: | |
| 201 "Only redirecting factory constructors can be declared to be 'const'", | |
| 202 howToFix: "Remove the 'const' keyword or replace the body with '=' " | |
| 203 "followed by a valid target", | |
| 204 usedBy: [analyzer], | |
| 205 examples: const [ | |
| 206 r""" | |
| 207 class C { | |
| 208 const factory C() {} | |
| 209 } | |
| 210 | |
| 211 main() => new C();""" | |
| 212 ]), | |
| 135 }; | 213 }; |
| OLD | NEW |