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 |
6 /** | 6 /** |
7 * The messages in this file should meet the following guide lines: | 7 * The messages in this file should meet the following guide lines: |
8 * | 8 * |
9 * 1. The message should be a complete sentence starting with an uppercase | 9 * 1. The message should be a complete sentence starting with an uppercase |
10 * letter, and ending with a period. | 10 * letter, and ending with a period. |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | 469 WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, |
470 YIELDING_MODIFIER_ON_ARROW_BODY, | 470 YIELDING_MODIFIER_ON_ARROW_BODY, |
471 } | 471 } |
472 | 472 |
473 /// A message template for an error, warning, hint or info message generated | 473 /// A message template for an error, warning, hint or info message generated |
474 /// by the compiler. Each template is associated with a [MessageKind] that | 474 /// by the compiler. Each template is associated with a [MessageKind] that |
475 /// uniquely identifies the message template. | 475 /// uniquely identifies the message template. |
476 // TODO(johnnniwinther): For Infos, consider adding a reference to the | 476 // TODO(johnnniwinther): For Infos, consider adding a reference to the |
477 // error/warning/hint that they belong to. | 477 // error/warning/hint that they belong to. |
478 class MessageTemplate { | 478 class MessageTemplate { |
479 final dynamic/*MessageKind | SharedMessageKind*/ kind; | 479 final MessageKind kind; |
480 | 480 |
481 /// Should describe what is wrong and why. | 481 /// Should describe what is wrong and why. |
482 final String template; | 482 final String template; |
483 | 483 |
484 /// Should describe how to fix the problem. Elided when using --terse option. | 484 /// Should describe how to fix the problem. Elided when using --terse option. |
485 final String howToFix; | 485 final String howToFix; |
486 | 486 |
487 /** | 487 /** |
488 * Examples will be checked by | 488 * Examples will be checked by |
489 * tests/compiler/dart2js/message_kind_test.dart. | 489 * tests/compiler/dart2js/message_kind_test.dart. |
(...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2587 | 2587 |
2588 main() {} | 2588 main() {} |
2589 """]), | 2589 """]), |
2590 | 2590 |
2591 MessageKind.READ_SELF_ERROR: | 2591 MessageKind.READ_SELF_ERROR: |
2592 const MessageTemplate(MessageKind.READ_SELF_ERROR, | 2592 const MessageTemplate(MessageKind.READ_SELF_ERROR, |
2593 "#{exception}", | 2593 "#{exception}", |
2594 // Don't know how to fix since the underlying error is unknown. | 2594 // Don't know how to fix since the underlying error is unknown. |
2595 howToFix: DONT_KNOW_HOW_TO_FIX), | 2595 howToFix: DONT_KNOW_HOW_TO_FIX), |
2596 | 2596 |
2597 MessageKind.EXTRANEOUS_MODIFIER: | |
2598 const MessageTemplate(MessageKind.EXTRANEOUS_MODIFIER, | |
2599 "Can't have modifier '#{modifier}' here.", | |
2600 howToFix: "Try removing '#{modifier}'.", | |
2601 examples: const [ | |
2602 "var String foo; main(){}", | |
2603 // "var get foo; main(){}", | |
2604 "var set foo; main(){}", | |
2605 "var final foo; main(){}", | |
2606 "var var foo; main(){}", | |
2607 "var const foo; main(){}", | |
2608 "var abstract foo; main(){}", | |
2609 "var static foo; main(){}", | |
2610 "var external foo; main(){}", | |
2611 "get var foo; main(){}", | |
2612 "set var foo; main(){}", | |
2613 "final var foo; main(){}", | |
2614 "var var foo; main(){}", | |
2615 "const var foo; main(){}", | |
2616 "abstract var foo; main(){}", | |
2617 "static var foo; main(){}", | |
2618 "external var foo; main(){}"]), | |
2619 | |
2620 MessageKind.EXTRANEOUS_MODIFIER_REPLACE: | |
2621 const MessageTemplate(MessageKind.EXTRANEOUS_MODIFIER_REPLACE, | |
2622 "Can't have modifier '#{modifier}' here.", | |
2623 howToFix: | |
2624 "Try replacing modifier '#{modifier}' with 'var', 'final', " | |
2625 "or a type.", | |
2626 examples: const [ | |
2627 // "get foo; main(){}", | |
2628 "set foo; main(){}", | |
2629 "abstract foo; main(){}", | |
2630 "static foo; main(){}", | |
2631 "external foo; main(){}"]), | |
2632 | |
2633 MessageKind.ABSTRACT_CLASS_INSTANTIATION: | 2597 MessageKind.ABSTRACT_CLASS_INSTANTIATION: |
2634 const MessageTemplate(MessageKind.ABSTRACT_CLASS_INSTANTIATION, | 2598 const MessageTemplate(MessageKind.ABSTRACT_CLASS_INSTANTIATION, |
2635 "Can't instantiate abstract class.", | 2599 "Can't instantiate abstract class.", |
2636 howToFix: DONT_KNOW_HOW_TO_FIX, | 2600 howToFix: DONT_KNOW_HOW_TO_FIX, |
2637 examples: const ["abstract class A {} main() { new A(); }"]), | 2601 examples: const ["abstract class A {} main() { new A(); }"]), |
2638 | 2602 |
2639 MessageKind.BODY_EXPECTED: | 2603 MessageKind.BODY_EXPECTED: |
2640 const MessageTemplate(MessageKind.BODY_EXPECTED, | 2604 const MessageTemplate(MessageKind.BODY_EXPECTED, |
2641 "Expected a function body or '=>'.", | 2605 "Expected a function body or '=>'.", |
2642 // TODO(ahe): In some scenarios, we can suggest removing the 'static' | 2606 // TODO(ahe): In some scenarios, we can suggest removing the 'static' |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3699 class Message { | 3663 class Message { |
3700 final MessageTemplate template; | 3664 final MessageTemplate template; |
3701 final Map arguments; | 3665 final Map arguments; |
3702 final bool terse; | 3666 final bool terse; |
3703 String message; | 3667 String message; |
3704 | 3668 |
3705 Message(this.template, this.arguments, this.terse) { | 3669 Message(this.template, this.arguments, this.terse) { |
3706 assert(() { computeMessage(); return true; }); | 3670 assert(() { computeMessage(); return true; }); |
3707 } | 3671 } |
3708 | 3672 |
3709 dynamic/*MessageKind | SharedMessageKind*/ get kind => template.kind; | 3673 MessageKind get kind => template.kind; |
3710 | 3674 |
3711 String computeMessage() { | 3675 String computeMessage() { |
3712 if (message == null) { | 3676 if (message == null) { |
3713 message = template.template; | 3677 message = template.template; |
3714 arguments.forEach((key, value) { | 3678 arguments.forEach((key, value) { |
3715 message = message.replaceAll('#{${key}}', convertToString(value)); | 3679 message = message.replaceAll('#{${key}}', convertToString(value)); |
3716 }); | 3680 }); |
3717 assert(invariant( | 3681 assert(invariant( |
3718 CURRENT_ELEMENT_SPANNABLE, | 3682 CURRENT_ELEMENT_SPANNABLE, |
3719 kind == MessageKind.GENERIC || | 3683 kind == MessageKind.GENERIC || |
(...skipping 24 matching lines...) Expand all Loading... |
3744 static String convertToString(value) { | 3708 static String convertToString(value) { |
3745 if (value is ErrorToken) { | 3709 if (value is ErrorToken) { |
3746 // Shouldn't happen. | 3710 // Shouldn't happen. |
3747 return value.assertionMessage; | 3711 return value.assertionMessage; |
3748 } else if (value is Token) { | 3712 } else if (value is Token) { |
3749 value = value.value; | 3713 value = value.value; |
3750 } | 3714 } |
3751 return '$value'; | 3715 return '$value'; |
3752 } | 3716 } |
3753 } | 3717 } |
OLD | NEW |