| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /// An error code associated with an [AnalysisError]. |
| 6 * An error code associated with an [AnalysisError]. | 6 /// |
| 7 * | 7 /// Generally, messages should follow the [Guide for Writing |
| 8 * Generally, we want to provide messages that consist of three sentences. From | 8 /// Diagnostics](../fasta/diagnostics.md). |
| 9 * the user's perspective these sentences should explain: | |
| 10 * | |
| 11 * 1. what is wrong, | |
| 12 * 2. why is it wrong, and | |
| 13 * 3. how do I fix it. | |
| 14 * | |
| 15 * However, we combine the first two in the [message] and the last in the | |
| 16 * [correction]. | |
| 17 * | |
| 18 * When composing messages (including correction messages) keep the following | |
| 19 * guidelines in mind. | |
| 20 * | |
| 21 * 1. The message should be a complete sentence starting with an uppercase | |
| 22 * letter, and ending with a period. | |
| 23 * | |
| 24 * 2. Reserved words and embedded identifiers should be in single quotes, so | |
| 25 * prefer double quotes for the complete message. For example, | |
| 26 * ``` | |
| 27 * "The class '{0}' can't use 'super'." | |
| 28 * ``` | |
| 29 * Notice that the word 'class' in the preceding message is not quoted as it | |
| 30 * refers to the concept 'class', not the reserved word. On the other hand, | |
| 31 * 'super' refers to the reserved word. Do not quote 'null' and numeric literals
. | |
| 32 * | |
| 33 * 3. Do not try to compose messages, as it can make translating them hard. | |
| 34 * | |
| 35 * 4. Try to keep the error messages short, but informative. | |
| 36 * | |
| 37 * 5. Use simple words and terminology, assume the reader of the message doesn't | |
| 38 * have an advanced degree in math, and that English is not the reader's native | |
| 39 * language. Do not assume any formal computer science training. For example, do | |
| 40 * not use Latin abbreviations (prefer "that is" over "i.e.", and "for example" | |
| 41 * over "e.g."). Also avoid phrases such as "if and only if" and "iff"; that | |
| 42 * level of precision is unnecessary. | |
| 43 * | |
| 44 * 6. Prefer contractions when they are in common use, for example, prefer | |
| 45 * "can't" over "cannot". Using "cannot", "must not", "shall not", etc. is | |
| 46 * off-putting to people new to programming. | |
| 47 * | |
| 48 * 7. Use common terminology, preferably from the Dart Language Specification. | |
| 49 * This increases the user's chance of finding a good explanation on the web. | |
| 50 * | |
| 51 * 8. Do not try to be cute or funny. It is extremely frustrating to work on a | |
| 52 * product that crashes with a "tongue-in-cheek" message, especially if you did | |
| 53 * not want to use this product to begin with. | |
| 54 * | |
| 55 * 9. Do not lie, that is, do not write error messages containing phrases like | |
| 56 * "can't happen". If the user ever saw this message, it would be a lie. Prefer | |
| 57 * messages like: "Internal error: This function should not be called when 'x' | |
| 58 * is null.". | |
| 59 * | |
| 60 * 10. Prefer to not use the imperative tone. That is, the message should not | |
| 61 * sound accusing or like it is ordering the user around. The computer should | |
| 62 * describe the problem, not criticize the user for violating the specification. | |
| 63 */ | |
| 64 abstract class ErrorCode { | 9 abstract class ErrorCode { |
| 65 /** | 10 /** |
| 66 * The name of the error code. | 11 * The name of the error code. |
| 67 */ | 12 */ |
| 68 final String name; | 13 final String name; |
| 69 | 14 |
| 70 /** | 15 /** |
| 71 * The template used to create the message to be displayed for this error. The | 16 * The template used to create the message to be displayed for this error. The |
| 72 * message should indicate what is wrong and why it is wrong. | 17 * message should indicate what is wrong and why it is wrong. |
| 73 */ | 18 */ |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 218 |
| 274 @override | 219 @override |
| 275 int get hashCode => ordinal; | 220 int get hashCode => ordinal; |
| 276 | 221 |
| 277 @override | 222 @override |
| 278 int compareTo(ErrorType other) => ordinal - other.ordinal; | 223 int compareTo(ErrorType other) => ordinal - other.ordinal; |
| 279 | 224 |
| 280 @override | 225 @override |
| 281 String toString() => name; | 226 String toString() => name; |
| 282 } | 227 } |
| OLD | NEW |