Chromium Code Reviews| 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 = ""; | |
| 8 | |
| 7 /** | 9 /** |
| 8 * The messages in this file should meet the following guide lines: | 10 * The messages in this file should meet the following guide lines: |
| 9 * | 11 * |
| 10 * 1. The message should start with exactly one of "Error", "Internal error", | 12 * 1. The message should start with exactly one of "Error", "Internal error", |
| 11 * "Warning", "Info", or "Hint" followed by a colon. It is crucial to users to | 13 * "Warning", "Info", or "Hint" followed by a colon. It is crucial to users to |
| 12 * be able to locate errors in the midst of warnings. | 14 * be able to locate errors in the midst of warnings. |
| 13 * TODO(ahe): Remove these prefixes from the error message. | 15 * TODO(ahe): Remove these prefixes from the error message. |
| 14 * | 16 * |
| 15 * 2. After the colon, one space and a complete sentence starting with an | 17 * 2. After the colon, one space and a complete sentence starting with an |
| 16 * uppercase letter, and ending with a period. | 18 * uppercase letter, and ending with a period. |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 535 |
| 534 static const DualKind CANNOT_RESOLVE_GETTER = const DualKind( | 536 static const DualKind CANNOT_RESOLVE_GETTER = const DualKind( |
| 535 error: const MessageKind('Error: Cannot resolve getter.'), | 537 error: const MessageKind('Error: Cannot resolve getter.'), |
| 536 warning: const MessageKind('Warning: Cannot resolve getter.')); | 538 warning: const MessageKind('Warning: Cannot resolve getter.')); |
| 537 | 539 |
| 538 static const DualKind CANNOT_RESOLVE_SETTER = const DualKind( | 540 static const DualKind CANNOT_RESOLVE_SETTER = const DualKind( |
| 539 error: const MessageKind('Error: Cannot resolve setter.'), | 541 error: const MessageKind('Error: Cannot resolve setter.'), |
| 540 warning: const MessageKind('Warning: Cannot resolve setter.')); | 542 warning: const MessageKind('Warning: Cannot resolve setter.')); |
| 541 | 543 |
| 542 static const MessageKind VOID_NOT_ALLOWED = const MessageKind( | 544 static const MessageKind VOID_NOT_ALLOWED = const MessageKind( |
| 543 'Error: Type "void" is only allowed in a return type.'); | 545 "Error: Type 'void' can't be used here because it isn't a return type.", |
| 546 howToFix: "Try removing 'void' keyword or replace it with 'var', 'final'," | |
| 547 " or a type.", | |
| 548 examples: const [ | |
| 549 "void x; main() {}", | |
| 550 "foo(void x) {} main() { foo(null); }", | |
| 551 ]); | |
| 544 | 552 |
| 545 static const MessageKind BEFORE_TOP_LEVEL = const MessageKind( | 553 static const MessageKind BEFORE_TOP_LEVEL = const MessageKind( |
| 546 'Error: Part header must come before top-level definitions.'); | 554 'Error: Part header must come before top-level definitions.'); |
| 547 | 555 |
| 548 static const MessageKind LIBRARY_NAME_MISMATCH = const MessageKind( | 556 static const MessageKind LIBRARY_NAME_MISMATCH = const MessageKind( |
| 549 'Warning: Expected part of library name "#{libraryName}".'); | 557 'Warning: Expected part of library name "#{libraryName}".'); |
| 550 | 558 |
| 551 static const MessageKind MISSING_PART_OF_TAG = const MessageKind( | 559 static const MessageKind MISSING_PART_OF_TAG = const MessageKind( |
| 552 'Error: This file has no part-of tag, but it is being used as a part.'); | 560 'Error: This file has no part-of tag, but it is being used as a part.'); |
| 553 | 561 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 """ | 755 """ |
| 748 // 'addAll' is misspelled. | 756 // 'addAll' is misspelled. |
| 749 @MirrorsUsed(targets: 'dart.core.List.addAl') | 757 @MirrorsUsed(targets: 'dart.core.List.addAl') |
| 750 import 'dart:mirrors'; | 758 import 'dart:mirrors'; |
| 751 | 759 |
| 752 main() {} | 760 main() {} |
| 753 """]); | 761 """]); |
| 754 | 762 |
| 755 static const MessageKind READ_SCRIPT_ERROR = const MessageKind( | 763 static const MessageKind READ_SCRIPT_ERROR = const MessageKind( |
| 756 "Error: Can't read '#{uri}' (#{exception}).", | 764 "Error: Can't read '#{uri}' (#{exception}).", |
| 765 // Don't know how to fix since the underlying error is unknown. | |
| 766 howToFix: DONT_KNOW_HOW_TO_FIX, | |
| 757 examples: const [ | 767 examples: const [ |
| 758 """ | 768 """ |
| 759 // 'foo.dart' does not exist. | 769 // 'foo.dart' does not exist. |
| 760 import 'foo.dart'; | 770 import 'foo.dart'; |
| 761 | 771 |
| 762 main() {} | 772 main() {} |
| 763 """]); | 773 """]); |
| 764 | 774 |
| 775 static const MessageKind EXTRANEOUS_MODIFIER = const MessageKind( | |
| 776 "Error: Can't have modifier '#{modifier}' here.", | |
| 777 howToFix: "Try removing '#{modifier}'.", | |
| 778 examples: const [ | |
| 779 "var String foo; main(){}", | |
| 780 // "var get foo; main(){}", | |
| 781 "var set foo; main(){}", | |
| 782 "var final foo; main(){}", | |
| 783 "var var foo; main(){}", | |
| 784 "var const foo; main(){}", | |
| 785 "var abstract foo; main(){}", | |
| 786 "var static foo; main(){}", | |
| 787 "var external foo; main(){}", | |
| 788 "get var foo; main(){}", | |
| 789 "set var foo; main(){}", | |
| 790 "final var foo; main(){}", | |
| 791 "var var foo; main(){}", | |
| 792 "const var foo; main(){}", | |
| 793 "abstract var foo; main(){}", | |
| 794 "static var foo; main(){}", | |
| 795 "external var foo; main(){}"]); | |
| 796 | |
| 797 static const MessageKind EXTRANEOUS_MODIFIER_REPLACE = const MessageKind( | |
| 798 "Error: Can't have modifier '#{modifier}' here.", | |
| 799 howToFix: "Try replacing modifier '#{modifier}' with 'var', 'final'," | |
| 800 " or a type.", | |
| 801 examples: const [ | |
| 802 // "get foo; main(){}", | |
| 803 "set foo; main(){}", | |
| 804 "abstract foo; main(){}", | |
| 805 "static foo; main(){}", | |
| 806 "external foo; main(){}"]); | |
| 807 | |
| 808 static const MessageKind BODY_EXPECTED = const MessageKind( | |
| 809 "Error: Expected a function body or '=>'.", | |
| 810 howToFix: "Try adding {}, or removing 'static' keyword.", | |
|
Johnni Winther
2013/09/02 11:02:08
This is a bad how-to-fix if you haven't got a 'sta
ahe
2013/09/02 17:49:59
I've added a todo and changed the suggestion to: "
| |
| 811 examples: const [ | |
| 812 "main();"]); | |
| 813 | |
| 765 static const MessageKind COMPILER_CRASHED = const MessageKind( | 814 static const MessageKind COMPILER_CRASHED = const MessageKind( |
| 766 'Error: The compiler crashed when compiling this element.'); | 815 'Error: The compiler crashed when compiling this element.'); |
| 767 | 816 |
| 768 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' | 817 static const MessageKind PLEASE_REPORT_THE_CRASH = const MessageKind(''' |
| 769 The compiler is broken. | 818 The compiler is broken. |
| 770 | 819 |
| 771 When compiling the above element, the compiler crashed. It is not | 820 When compiling the above element, the compiler crashed. It is not |
| 772 possible to tell if this is caused by a problem in your program or | 821 possible to tell if this is caused by a problem in your program or |
| 773 not. Regardless, the compiler should not crash. | 822 not. Regardless, the compiler should not crash. |
| 774 | 823 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 | 886 |
| 838 static const MessageKind PATCH_POINT_TO_CONSTRUCTOR = const MessageKind( | 887 static const MessageKind PATCH_POINT_TO_CONSTRUCTOR = const MessageKind( |
| 839 'Info: This is the constructor patch "#{constructorName}".'); | 888 'Info: This is the constructor patch "#{constructorName}".'); |
| 840 | 889 |
| 841 static const MessageKind PATCH_POINT_TO_PARAMETER = const MessageKind( | 890 static const MessageKind PATCH_POINT_TO_PARAMETER = const MessageKind( |
| 842 'Info: This is the patch parameter "#{parameterName}".'); | 891 'Info: This is the patch parameter "#{parameterName}".'); |
| 843 | 892 |
| 844 static const MessageKind PATCH_NON_EXISTING = const MessageKind( | 893 static const MessageKind PATCH_NON_EXISTING = const MessageKind( |
| 845 'Error: Origin does not exist for patch "#{name}".'); | 894 'Error: Origin does not exist for patch "#{name}".'); |
| 846 | 895 |
| 896 // TODO(ahe): Eventually, this error should be removed as it will be handled | |
| 897 // by the regular parser. | |
| 847 static const MessageKind PATCH_NONPATCHABLE = const MessageKind( | 898 static const MessageKind PATCH_NONPATCHABLE = const MessageKind( |
| 848 'Error: Only classes and functions can be patched.'); | 899 'Error: Only classes and functions can be patched.'); |
| 849 | 900 |
| 850 static const MessageKind PATCH_NON_EXTERNAL = const MessageKind( | 901 static const MessageKind PATCH_NON_EXTERNAL = const MessageKind( |
| 851 'Error: Only external functions can be patched.'); | 902 'Error: Only external functions can be patched.'); |
| 852 | 903 |
| 853 static const MessageKind PATCH_NON_CLASS = const MessageKind( | 904 static const MessageKind PATCH_NON_CLASS = const MessageKind( |
| 854 'Error: Patching non-class with class patch "#{className}".'); | 905 'Error: Patching non-class with class patch "#{className}".'); |
| 855 | 906 |
| 856 static const MessageKind PATCH_NON_GETTER = const MessageKind( | 907 static const MessageKind PATCH_NON_GETTER = const MessageKind( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 879 | 930 |
| 880 toString() => template; | 931 toString() => template; |
| 881 | 932 |
| 882 Message message([Map arguments = const {}, bool terse = false]) { | 933 Message message([Map arguments = const {}, bool terse = false]) { |
| 883 return new Message(this, arguments, terse); | 934 return new Message(this, arguments, terse); |
| 884 } | 935 } |
| 885 | 936 |
| 886 CompilationError error([Map arguments = const {}, bool terse = false]) { | 937 CompilationError error([Map arguments = const {}, bool terse = false]) { |
| 887 return new CompilationError(this, arguments, terse); | 938 return new CompilationError(this, arguments, terse); |
| 888 } | 939 } |
| 940 | |
| 941 bool get hasHowToFix => howToFix != null && howToFix != DONT_KNOW_HOW_TO_FIX; | |
| 889 } | 942 } |
| 890 | 943 |
| 891 class DualKind { | 944 class DualKind { |
| 892 final MessageKind error; | 945 final MessageKind error; |
| 893 final MessageKind warning; | 946 final MessageKind warning; |
| 894 | 947 |
| 895 const DualKind({this.error, this.warning}); | 948 const DualKind({this.error, this.warning}); |
| 896 } | 949 } |
| 897 | 950 |
| 898 class Message { | 951 class Message { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 909 if (message == null) { | 962 if (message == null) { |
| 910 message = kind.template; | 963 message = kind.template; |
| 911 arguments.forEach((key, value) { | 964 arguments.forEach((key, value) { |
| 912 String string = slowToString(value); | 965 String string = slowToString(value); |
| 913 message = message.replaceAll('#{${key}}', string); | 966 message = message.replaceAll('#{${key}}', string); |
| 914 }); | 967 }); |
| 915 assert(invariant( | 968 assert(invariant( |
| 916 CURRENT_ELEMENT_SPANNABLE, | 969 CURRENT_ELEMENT_SPANNABLE, |
| 917 !message.contains(new RegExp(r'#\{.+\}')), | 970 !message.contains(new RegExp(r'#\{.+\}')), |
| 918 message: 'Missing arguments in error message: "$message"')); | 971 message: 'Missing arguments in error message: "$message"')); |
| 919 if (!terse && kind.howToFix != null) { | 972 if (!terse && kind.hasHowToFix) { |
| 920 String howToFix = kind.howToFix; | 973 String howToFix = kind.howToFix; |
| 921 arguments.forEach((key, value) { | 974 arguments.forEach((key, value) { |
| 922 String string = slowToString(value); | 975 String string = slowToString(value); |
| 923 howToFix = howToFix.replaceAll('#{${key}}', string); | 976 howToFix = howToFix.replaceAll('#{${key}}', string); |
| 924 }); | 977 }); |
| 925 message = '$message\n$howToFix'; | 978 message = '$message\n$howToFix'; |
| 926 } | 979 } |
| 927 } | 980 } |
| 928 return message; | 981 return message; |
| 929 } | 982 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 967 | 1020 |
| 968 class CompileTimeConstantError extends Diagnostic { | 1021 class CompileTimeConstantError extends Diagnostic { |
| 969 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) | 1022 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) |
| 970 : super(kind, arguments, terse); | 1023 : super(kind, arguments, terse); |
| 971 } | 1024 } |
| 972 | 1025 |
| 973 class CompilationError extends Diagnostic { | 1026 class CompilationError extends Diagnostic { |
| 974 CompilationError(MessageKind kind, Map arguments, bool terse) | 1027 CompilationError(MessageKind kind, Map arguments, bool terse) |
| 975 : super(kind, arguments, terse); | 1028 : super(kind, arguments, terse); |
| 976 } | 1029 } |
| OLD | NEW |