| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 const DONT_KNOW_HOW_TO_FIX = ""; | 7 const DONT_KNOW_HOW_TO_FIX = ""; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * The messages in this file should meet the following guide lines: | 10 * The messages in this file should meet the following guide lines: |
| (...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 ''']); | 1831 ''']); |
| 1832 | 1832 |
| 1833 static const MessageKind UNTERMINATED_COMMENT = const MessageKind( | 1833 static const MessageKind UNTERMINATED_COMMENT = const MessageKind( |
| 1834 "Comment starting with '/*' must end with '*/'.", | 1834 "Comment starting with '/*' must end with '*/'.", |
| 1835 howToFix: DONT_KNOW_HOW_TO_FIX, | 1835 howToFix: DONT_KNOW_HOW_TO_FIX, |
| 1836 examples: const [r""" | 1836 examples: const [r""" |
| 1837 main() { | 1837 main() { |
| 1838 } | 1838 } |
| 1839 /*"""]); | 1839 /*"""]); |
| 1840 | 1840 |
| 1841 static const MessageKind MISSING_TOKEN_BEFORE_THIS = const MessageKind( |
| 1842 "Expected '#{token}' before this.", |
| 1843 // Consider the second example below: the parser expects a ')' before |
| 1844 // 'y', but a ',' would also have worked. We don't have enough |
| 1845 // information to give a good suggestion. |
| 1846 howToFix: DONT_KNOW_HOW_TO_FIX, |
| 1847 examples: const [ |
| 1848 "main() => true ? 1;", |
| 1849 "main() => foo(x: 1 y: 2);", |
| 1850 ]); |
| 1851 |
| 1852 static const MessageKind MISSING_TOKEN_AFTER_THIS = const MessageKind( |
| 1853 "Expected '#{token}' after this.", |
| 1854 // See [MISSING_TOKEN_BEFORE_THIS], we don't have enough information to |
| 1855 // give a good suggestion. |
| 1856 howToFix: DONT_KNOW_HOW_TO_FIX, |
| 1857 examples: const ["main(x) {x}"]); |
| 1858 |
| 1841 static const MessageKind COMPILER_CRASHED = const MessageKind( | 1859 static const MessageKind COMPILER_CRASHED = const MessageKind( |
| 1842 "The compiler crashed when compiling this element."); | 1860 "The compiler crashed when compiling this element."); |
| 1843 | 1861 |
| 1844 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' | 1862 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' |
| 1845 The compiler is broken. | 1863 The compiler is broken. |
| 1846 | 1864 |
| 1847 When compiling the above element, the compiler crashed. It is not | 1865 When compiling the above element, the compiler crashed. It is not |
| 1848 possible to tell if this is caused by a problem in your program or | 1866 possible to tell if this is caused by a problem in your program or |
| 1849 not. Regardless, the compiler should not crash. | 1867 not. Regardless, the compiler should not crash. |
| 1850 | 1868 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 String message; | 2043 String message; |
| 2026 | 2044 |
| 2027 Message(this.kind, this.arguments, this.terse) { | 2045 Message(this.kind, this.arguments, this.terse) { |
| 2028 assert(() { computeMessage(); return true; }); | 2046 assert(() { computeMessage(); return true; }); |
| 2029 } | 2047 } |
| 2030 | 2048 |
| 2031 String computeMessage() { | 2049 String computeMessage() { |
| 2032 if (message == null) { | 2050 if (message == null) { |
| 2033 message = kind.template; | 2051 message = kind.template; |
| 2034 arguments.forEach((key, value) { | 2052 arguments.forEach((key, value) { |
| 2035 message = message.replaceAll('#{${key}}', value.toString()); | 2053 message = message.replaceAll('#{${key}}', convertToString(value)); |
| 2036 }); | 2054 }); |
| 2037 assert(invariant( | 2055 assert(invariant( |
| 2038 CURRENT_ELEMENT_SPANNABLE, | 2056 CURRENT_ELEMENT_SPANNABLE, |
| 2039 kind == MessageKind.GENERIC || | 2057 kind == MessageKind.GENERIC || |
| 2040 !message.contains(new RegExp(r'#\{.+\}')), | 2058 !message.contains(new RegExp(r'#\{.+\}')), |
| 2041 message: 'Missing arguments in error message: "$message"')); | 2059 message: 'Missing arguments in error message: "$message"')); |
| 2042 if (!terse && kind.hasHowToFix) { | 2060 if (!terse && kind.hasHowToFix) { |
| 2043 String howToFix = kind.howToFix; | 2061 String howToFix = kind.howToFix; |
| 2044 arguments.forEach((key, value) { | 2062 arguments.forEach((key, value) { |
| 2045 howToFix = howToFix.replaceAll('#{${key}}', value.toString()); | 2063 howToFix = howToFix.replaceAll('#{${key}}', convertToString(value)); |
| 2046 }); | 2064 }); |
| 2047 message = '$message\n$howToFix'; | 2065 message = '$message\n$howToFix'; |
| 2048 } | 2066 } |
| 2049 } | 2067 } |
| 2050 return message; | 2068 return message; |
| 2051 } | 2069 } |
| 2052 | 2070 |
| 2053 String toString() { | 2071 String toString() { |
| 2054 return computeMessage(); | 2072 return computeMessage(); |
| 2055 } | 2073 } |
| 2056 | 2074 |
| 2057 bool operator==(other) { | 2075 bool operator==(other) { |
| 2058 if (other is !Message) return false; | 2076 if (other is !Message) return false; |
| 2059 return (kind == other.kind) && (toString() == other.toString()); | 2077 return (kind == other.kind) && (toString() == other.toString()); |
| 2060 } | 2078 } |
| 2061 | 2079 |
| 2062 int get hashCode => throw new UnsupportedError('Message.hashCode'); | 2080 int get hashCode => throw new UnsupportedError('Message.hashCode'); |
| 2081 |
| 2082 static String convertToString(value) { |
| 2083 if (value is ErrorToken) { |
| 2084 // Shouldn't happen. |
| 2085 return value.assertionMessage; |
| 2086 } else if (value is Token) { |
| 2087 value = value.value; |
| 2088 } |
| 2089 return '$value'; |
| 2090 } |
| 2063 } | 2091 } |
| OLD | NEW |