| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /// The messages in this file should follow the [Guide for Writing |
| 6 * The messages in this file should meet the following guide lines: | 6 /// Diagnostics](../../../../front_end/lib/src/fasta/diagnostics.md). |
| 7 * | 7 /// |
| 8 * 1. The message should be a complete sentence starting with an uppercase | 8 /// Other things to keep in mind: |
| 9 * letter, and ending with a period. | 9 /// |
| 10 * | 10 /// An INFO message should always be preceded by a non-INFO message, and the |
| 11 * 2. Reserved words and embedded identifiers should be in single quotes, so | 11 /// INFO messages are additional details about the preceding non-INFO |
| 12 * prefer double quotes for the complete message. For example, "The | 12 /// message. For example, consider duplicated elements. First report a WARNING |
| 13 * class '#{className}' can't use 'super'." Notice that the word 'class' in the | 13 /// or ERROR about the duplicated element, and then report an INFO about the |
| 14 * preceding message is not quoted as it refers to the concept 'class', not the | 14 /// location of the existing element. |
| 15 * reserved word. On the other hand, 'super' refers to the reserved word. Do | |
| 16 * not quote 'null' and numeric literals. | |
| 17 * | |
| 18 * 3. Do not try to compose messages, as it can make translating them hard. | |
| 19 * | |
| 20 * 4. Try to keep the error messages short, but informative. | |
| 21 * | |
| 22 * 5. Use simple words and terminology, assume the reader of the message | |
| 23 * doesn't have an advanced degree in math, and that English is not the | |
| 24 * reader's native language. Do not assume any formal computer science | |
| 25 * training. For example, do not use Latin abbreviations (prefer "that is" over | |
| 26 * "i.e.", and "for example" over "e.g."). Also avoid phrases such as "if and | |
| 27 * only if" and "iff", that level of precision is unnecessary. | |
| 28 * | |
| 29 * 6. Prefer contractions when they are in common use, for example, prefer | |
| 30 * "can't" over "cannot". Using "cannot", "must not", "shall not", etc. is | |
| 31 * off-putting to people new to programming. | |
| 32 * | |
| 33 * 7. Use common terminology, preferably from the Dart Language | |
| 34 * Specification. This increases the user's chance of finding a good | |
| 35 * explanation on the web. | |
| 36 * | |
| 37 * 8. Do not try to be cute or funny. It is extremely frustrating to work on a | |
| 38 * product that crashes with a "tongue-in-cheek" message, especially if you did | |
| 39 * not want to use this product to begin with. | |
| 40 * | |
| 41 * 9. Do not lie, that is, do not write error messages containing phrases like | |
| 42 * "can't happen". If the user ever saw this message, it would be a | |
| 43 * lie. Prefer messages like: "Internal error: This function should not be | |
| 44 * called when 'x' is null.". | |
| 45 * | |
| 46 * 10. Prefer to not use imperative tone. That is, the message should not sound | |
| 47 * accusing or like it is ordering the user around. The computer should | |
| 48 * describe the problem, not criticize for violating the specification. | |
| 49 * | |
| 50 * Other things to keep in mind: | |
| 51 * | |
| 52 * An INFO message should always be preceded by a non-INFO message, and the | |
| 53 * INFO messages are additional details about the preceding non-INFO | |
| 54 * message. For example, consider duplicated elements. First report a WARNING | |
| 55 * or ERROR about the duplicated element, and then report an INFO about the | |
| 56 * location of the existing element. | |
| 57 * | |
| 58 * Generally, we want to provide messages that consists of three sentences: | |
| 59 * 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we | |
| 60 * combine the first two in [template] and the last in [howToFix]. | |
| 61 */ | |
| 62 | |
| 63 library dart2js.messages; | 15 library dart2js.messages; |
| 64 | 16 |
| 65 import 'package:front_end/src/fasta/scanner.dart' show ErrorToken, Token; | 17 import 'package:front_end/src/fasta/scanner.dart' show ErrorToken, Token; |
| 66 import 'generated/shared_messages.dart' as shared_messages; | 18 import 'generated/shared_messages.dart' as shared_messages; |
| 67 import 'invariant.dart' show invariant; | 19 import 'invariant.dart' show invariant; |
| 68 import 'spannable.dart' show CURRENT_ELEMENT_SPANNABLE; | 20 import 'spannable.dart' show CURRENT_ELEMENT_SPANNABLE; |
| 69 | 21 |
| 70 const DONT_KNOW_HOW_TO_FIX = "Computer says no!"; | 22 const DONT_KNOW_HOW_TO_FIX = "Computer says no!"; |
| 71 | 23 |
| 72 /// Keys for the [MessageTemplate]s. | 24 /// Keys for the [MessageTemplate]s. |
| (...skipping 3745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3818 static String convertToString(value) { | 3770 static String convertToString(value) { |
| 3819 if (value is ErrorToken) { | 3771 if (value is ErrorToken) { |
| 3820 // Shouldn't happen. | 3772 // Shouldn't happen. |
| 3821 return value.assertionMessage; | 3773 return value.assertionMessage; |
| 3822 } else if (value is Token) { | 3774 } else if (value is Token) { |
| 3823 value = value.value; | 3775 value = value.value; |
| 3824 } | 3776 } |
| 3825 return '$value'; | 3777 return '$value'; |
| 3826 } | 3778 } |
| 3827 } | 3779 } |
| OLD | NEW |