OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.error.error; | 5 library analyzer.error.error; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void setProperty/*<V>*/(ErrorProperty/*<V>*/ property, Object/*=V*/ value) { | 228 void setProperty/*<V>*/(ErrorProperty/*<V>*/ property, Object/*=V*/ value) { |
229 _propertyMap[property] = value; | 229 _propertyMap[property] = value; |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
234 * An error code associated with an [AnalysisError]. | 234 * An error code associated with an [AnalysisError]. |
235 * | 235 * |
236 * Generally, we want to provide messages that consist of three sentences. From | 236 * Generally, we want to provide messages that consist of three sentences. From |
237 * the user's perspective these sentences should explain: | 237 * the user's perspective these sentences should explain: |
| 238 * |
238 * 1. what is wrong, | 239 * 1. what is wrong, |
239 * 2. why is it wrong, and | 240 * 2. why is it wrong, and |
240 * 3. how do I fix it. | 241 * 3. how do I fix it. |
| 242 * |
241 * However, we combine the first two in the [message] and the last in the | 243 * However, we combine the first two in the [message] and the last in the |
242 * [correction]. | 244 * [correction]. |
| 245 * |
| 246 * When composing messages (including correction messages) keep the following |
| 247 * guidelines in mind. |
| 248 * |
| 249 * 1. The message should be a complete sentence starting with an uppercase |
| 250 * letter, and ending with a period. |
| 251 * |
| 252 * 2. Reserved words and embedded identifiers should be in single quotes, so |
| 253 * prefer double quotes for the complete message. For example, |
| 254 * ``` |
| 255 * "The class '{0}' can't use 'super'." |
| 256 * ``` |
| 257 * Notice that the word 'class' in the preceding message is not quoted as it |
| 258 * refers to the concept 'class', not the reserved word. On the other hand, |
| 259 * 'super' refers to the reserved word. Do not quote 'null' and numeric literals
. |
| 260 * |
| 261 * 3. Do not try to compose messages, as it can make translating them hard. |
| 262 * |
| 263 * 4. Try to keep the error messages short, but informative. |
| 264 * |
| 265 * 5. Use simple words and terminology, assume the reader of the message doesn't |
| 266 * have an advanced degree in math, and that English is not the reader's native |
| 267 * language. Do not assume any formal computer science training. For example, do |
| 268 * not use Latin abbreviations (prefer "that is" over "i.e.", and "for example" |
| 269 * over "e.g."). Also avoid phrases such as "if and only if" and "iff"; that |
| 270 * level of precision is unnecessary. |
| 271 * |
| 272 * 6. Prefer contractions when they are in common use, for example, prefer |
| 273 * "can't" over "cannot". Using "cannot", "must not", "shall not", etc. is |
| 274 * off-putting to people new to programming. |
| 275 * |
| 276 * 7. Use common terminology, preferably from the Dart Language Specification. |
| 277 * This increases the user's chance of finding a good explanation on the web. |
| 278 * |
| 279 * 8. Do not try to be cute or funny. It is extremely frustrating to work on a |
| 280 * product that crashes with a "tongue-in-cheek" message, especially if you did |
| 281 * not want to use this product to begin with. |
| 282 * |
| 283 * 9. Do not lie, that is, do not write error messages containing phrases like |
| 284 * "can't happen". If the user ever saw this message, it would be a lie. Prefer |
| 285 * messages like: "Internal error: This function should not be called when 'x' |
| 286 * is null.". |
| 287 * |
| 288 * 10. Prefer to not use the imperative tone. That is, the message should not |
| 289 * sound accusing or like it is ordering the user around. The computer should |
| 290 * describe the problem, not criticize the user for violating the specification. |
243 */ | 291 */ |
244 abstract class ErrorCode { | 292 abstract class ErrorCode { |
245 /** | 293 /** |
246 * Engine error code values. | 294 * Engine error code values. |
247 */ | 295 */ |
248 static const List<ErrorCode> values = const [ | 296 static const List<ErrorCode> values = const [ |
249 // | 297 // |
250 // Manually generated. FWIW, this get's you most of the way there: | 298 // Manually generated. FWIW, this get's you most of the way there: |
251 // | 299 // |
252 // > grep 'static const .*Code' (error.dart|parser|scanner.dart) | 300 // > grep 'static const .*Code' (error.dart|parser|scanner.dart) |
(...skipping 17 matching lines...) Expand all Loading... |
270 CompileTimeErrorCode.AMBIGUOUS_EXPORT, | 318 CompileTimeErrorCode.AMBIGUOUS_EXPORT, |
271 CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS, | 319 CompileTimeErrorCode.ANNOTATION_WITH_NON_CLASS, |
272 CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_NON_PARAMETER, | 320 CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_NON_PARAMETER, |
273 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, | 321 CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, |
274 CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT, | 322 CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT, |
275 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, | 323 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, |
276 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, | 324 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, |
277 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME, | 325 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME, |
278 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, | 326 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, |
279 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, | 327 CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS, |
280 CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION, | |
281 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, | 328 CompileTimeErrorCode.CONFLICTING_GETTER_AND_METHOD, |
282 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, | 329 CompileTimeErrorCode.CONFLICTING_METHOD_AND_GETTER, |
283 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, | 330 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD, |
284 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, | 331 CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD, |
285 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, | 332 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_CLASS, |
286 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, | 333 CompileTimeErrorCode.CONFLICTING_TYPE_VARIABLE_AND_MEMBER, |
287 CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION, | 334 CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION, |
288 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST, | 335 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST, |
289 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, | 336 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_MIXIN, |
290 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, | 337 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE, | 539 HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE, |
493 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT, | 540 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT, |
494 HtmlErrorCode.PARSE_ERROR, | 541 HtmlErrorCode.PARSE_ERROR, |
495 HtmlWarningCode.INVALID_URI, | 542 HtmlWarningCode.INVALID_URI, |
496 HtmlWarningCode.URI_DOES_NOT_EXIST, | 543 HtmlWarningCode.URI_DOES_NOT_EXIST, |
497 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, | 544 StaticTypeWarningCode.EXPECTED_ONE_LIST_TYPE_ARGUMENTS, |
498 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, | 545 StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS, |
499 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, | 546 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, |
500 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, | 547 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, |
501 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, | 548 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, |
502 StaticTypeWarningCode.INACCESSIBLE_SETTER, | |
503 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, | 549 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, |
504 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, | 550 StaticTypeWarningCode.INSTANCE_ACCESS_TO_STATIC_MEMBER, |
505 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 551 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
506 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, | 552 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION, |
507 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, | 553 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, |
508 StaticTypeWarningCode.NON_BOOL_CONDITION, | 554 StaticTypeWarningCode.NON_BOOL_CONDITION, |
509 StaticTypeWarningCode.NON_BOOL_EXPRESSION, | 555 StaticTypeWarningCode.NON_BOOL_EXPRESSION, |
510 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, | 556 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, |
511 StaticTypeWarningCode.NON_BOOL_OPERAND, | 557 StaticTypeWarningCode.NON_BOOL_OPERAND, |
512 StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED, | 558 StaticTypeWarningCode.NON_NULLABLE_FIELD_NOT_INITIALIZED, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // parser.dart: | 701 // parser.dart: |
656 // | 702 // |
657 ParserErrorCode.ABSTRACT_CLASS_MEMBER, | 703 ParserErrorCode.ABSTRACT_CLASS_MEMBER, |
658 ParserErrorCode.ABSTRACT_ENUM, | 704 ParserErrorCode.ABSTRACT_ENUM, |
659 ParserErrorCode.ABSTRACT_STATIC_METHOD, | 705 ParserErrorCode.ABSTRACT_STATIC_METHOD, |
660 ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, | 706 ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION, |
661 ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, | 707 ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE, |
662 ParserErrorCode.ABSTRACT_TYPEDEF, | 708 ParserErrorCode.ABSTRACT_TYPEDEF, |
663 ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT, | 709 ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT, |
664 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, | 710 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER, |
665 ParserErrorCode.ASYNC_NOT_SUPPORTED, | |
666 ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, | 711 ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, |
667 ParserErrorCode.CLASS_IN_CLASS, | 712 ParserErrorCode.CLASS_IN_CLASS, |
668 ParserErrorCode.COLON_IN_PLACE_OF_IN, | 713 ParserErrorCode.COLON_IN_PLACE_OF_IN, |
669 ParserErrorCode.CONST_AND_FINAL, | 714 ParserErrorCode.CONST_AND_FINAL, |
670 ParserErrorCode.CONST_AND_VAR, | 715 ParserErrorCode.CONST_AND_VAR, |
671 ParserErrorCode.CONST_CLASS, | 716 ParserErrorCode.CONST_CLASS, |
672 ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, | 717 ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, |
673 ParserErrorCode.CONST_ENUM, | 718 ParserErrorCode.CONST_ENUM, |
674 ParserErrorCode.CONST_FACTORY, | 719 ParserErrorCode.CONST_FACTORY, |
675 ParserErrorCode.CONST_METHOD, | 720 ParserErrorCode.CONST_METHOD, |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 | 1154 |
1110 @override | 1155 @override |
1111 int get hashCode => ordinal; | 1156 int get hashCode => ordinal; |
1112 | 1157 |
1113 @override | 1158 @override |
1114 int compareTo(ErrorType other) => ordinal - other.ordinal; | 1159 int compareTo(ErrorType other) => ordinal - other.ordinal; |
1115 | 1160 |
1116 @override | 1161 @override |
1117 String toString() => name; | 1162 String toString() => name; |
1118 } | 1163 } |
OLD | NEW |