Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: pkg/compiler/lib/src/diagnostics/messages.dart

Issue 1582903003: Generate dart2js and analyzer files for shared messages. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments (and rebase) Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 import '../tokens/token.dart' show 66 import '../tokens/token.dart' show
67 ErrorToken, 67 ErrorToken,
68 Token; 68 Token;
69 69
70 import 'invariant.dart' show 70 import 'invariant.dart' show
71 invariant; 71 invariant;
72 import 'spannable.dart' show 72 import 'spannable.dart' show
73 CURRENT_ELEMENT_SPANNABLE; 73 CURRENT_ELEMENT_SPANNABLE;
74 74
75 import 'generated/shared_messages.dart' as shared_messages;
76
77 export 'generated/shared_messages.dart' show SharedMessageKind;
78
75 const DONT_KNOW_HOW_TO_FIX = "Computer says no!"; 79 const DONT_KNOW_HOW_TO_FIX = "Computer says no!";
76 80
77 /// Keys for the [MessageTemplate]s. 81 /// Keys for the [MessageTemplate]s.
78 enum MessageKind { 82 enum MessageKind {
79 ABSTRACT_CLASS_INSTANTIATION, 83 ABSTRACT_CLASS_INSTANTIATION,
80 ABSTRACT_GETTER, 84 ABSTRACT_GETTER,
81 ABSTRACT_METHOD, 85 ABSTRACT_METHOD,
82 ABSTRACT_SETTER, 86 ABSTRACT_SETTER,
83 ACCESSED_IN_CLOSURE, 87 ACCESSED_IN_CLOSURE,
84 ACCESSED_IN_CLOSURE_HERE, 88 ACCESSED_IN_CLOSURE_HERE,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, 470 WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
467 YIELDING_MODIFIER_ON_ARROW_BODY, 471 YIELDING_MODIFIER_ON_ARROW_BODY,
468 } 472 }
469 473
470 /// A message template for an error, warning, hint or info message generated 474 /// A message template for an error, warning, hint or info message generated
471 /// by the compiler. Each template is associated with a [MessageKind] that 475 /// by the compiler. Each template is associated with a [MessageKind] that
472 /// uniquely identifies the message template. 476 /// uniquely identifies the message template.
473 // TODO(johnnniwinther): For Infos, consider adding a reference to the 477 // TODO(johnnniwinther): For Infos, consider adding a reference to the
474 // error/warning/hint that they belong to. 478 // error/warning/hint that they belong to.
475 class MessageTemplate { 479 class MessageTemplate {
476 final MessageKind kind; 480 final dynamic/*MessageKind | SharedMessageKind*/ kind;
477 481
478 /// Should describe what is wrong and why. 482 /// Should describe what is wrong and why.
479 final String template; 483 final String template;
480 484
481 /// Should describe how to fix the problem. Elided when using --terse option. 485 /// Should describe how to fix the problem. Elided when using --terse option.
482 final String howToFix; 486 final String howToFix;
483 487
484 /** 488 /**
485 * Examples will be checked by 489 * Examples will be checked by
486 * tests/compiler/dart2js/message_kind_test.dart. 490 * tests/compiler/dart2js/message_kind_test.dart.
(...skipping 11 matching lines...) Expand all
498 this.kind, 502 this.kind,
499 this.template, 503 this.template,
500 {this.howToFix, 504 {this.howToFix,
501 this.examples, 505 this.examples,
502 this.options: const <String>[]}); 506 this.options: const <String>[]});
503 507
504 /// All templates used by the compiler. 508 /// All templates used by the compiler.
505 /// 509 ///
506 /// The map is complete mapping from [MessageKind] to their corresponding 510 /// The map is complete mapping from [MessageKind] to their corresponding
507 /// [MessageTemplate]. 511 /// [MessageTemplate].
508 static const Map<MessageKind, MessageTemplate> TEMPLATES = 512 // The key type is a union of MessageKind and SharedMessageKind.
509 const <MessageKind, MessageTemplate>{ 513 static final Map<dynamic, MessageTemplate> TEMPLATES =
514 <dynamic, MessageTemplate>{}
515 ..addAll(shared_messages.TEMPLATES)
516 ..addAll(const<MessageKind, MessageTemplate>{
510 /// Do not use this. It is here for legacy and debugging. It violates item 517 /// Do not use this. It is here for legacy and debugging. It violates item
511 /// 4 of the guide lines for error messages in the beginning of the file. 518 /// 4 of the guide lines for error messages in the beginning of the file.
512 MessageKind.GENERIC: 519 MessageKind.GENERIC:
513 const MessageTemplate(MessageKind.GENERIC, '#{text}'), 520 const MessageTemplate(MessageKind.GENERIC, '#{text}'),
514 521
515 MessageKind.NOT_ASSIGNABLE: 522 MessageKind.NOT_ASSIGNABLE:
516 const MessageTemplate(MessageKind.NOT_ASSIGNABLE, 523 const MessageTemplate(MessageKind.NOT_ASSIGNABLE,
517 "'#{fromType}' is not assignable to '#{toType}'."), 524 "'#{fromType}' is not assignable to '#{toType}'."),
518 525
519 MessageKind.FORIN_NOT_ASSIGNABLE: 526 MessageKind.FORIN_NOT_ASSIGNABLE:
(...skipping 3121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3641 const MessageTemplate(MessageKind.COMPLEX_RETURNING_NSM, 3648 const MessageTemplate(MessageKind.COMPLEX_RETURNING_NSM,
3642 "Overriding 'noSuchMethod' causes the compiler to generate " 3649 "Overriding 'noSuchMethod' causes the compiler to generate "
3643 "more code and prevents the compiler from doing some optimizations.", 3650 "more code and prevents the compiler from doing some optimizations.",
3644 howToFix: "Consider removing this 'noSuchMethod' implementation."), 3651 howToFix: "Consider removing this 'noSuchMethod' implementation."),
3645 3652
3646 MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP: 3653 MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP:
3647 const MessageTemplate(MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP, 3654 const MessageTemplate(MessageKind.UNRECOGNIZED_VERSION_OF_LOOKUP_MAP,
3648 "Unsupported version of package:lookup_map.", 3655 "Unsupported version of package:lookup_map.",
3649 howToFix: DONT_KNOW_HOW_TO_FIX), 3656 howToFix: DONT_KNOW_HOW_TO_FIX),
3650 3657
3651 }; // End of TEMPLATES. 3658 }); // End of TEMPLATES.
3652 3659
3653 /// Padding used before and between import chains in the message for 3660 /// Padding used before and between import chains in the message for
3654 /// [MessageKind.IMPORT_EXPERIMENTAL_MIRRORS]. 3661 /// [MessageKind.IMPORT_EXPERIMENTAL_MIRRORS].
3655 static const String IMPORT_EXPERIMENTAL_MIRRORS_PADDING = '\n* '; 3662 static const String IMPORT_EXPERIMENTAL_MIRRORS_PADDING = '\n* ';
3656 3663
3657 /// Padding used before and between import chains in the message for 3664 /// Padding used before and between import chains in the message for
3658 /// [MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND]. 3665 /// [MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND].
3659 static const String MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING = '\n '; 3666 static const String MIRRORS_NOT_SUPPORTED_BY_BACKEND_PADDING = '\n ';
3660 3667
3661 /// Padding used before and between import chains in the message for 3668 /// Padding used before and between import chains in the message for
(...skipping 12 matching lines...) Expand all
3674 class Message { 3681 class Message {
3675 final MessageTemplate template; 3682 final MessageTemplate template;
3676 final Map arguments; 3683 final Map arguments;
3677 final bool terse; 3684 final bool terse;
3678 String message; 3685 String message;
3679 3686
3680 Message(this.template, this.arguments, this.terse) { 3687 Message(this.template, this.arguments, this.terse) {
3681 assert(() { computeMessage(); return true; }); 3688 assert(() { computeMessage(); return true; });
3682 } 3689 }
3683 3690
3684 MessageKind get kind => template.kind; 3691 dynamic/*MessageKind | SharedMessageKind*/ get kind => template.kind;
3685 3692
3686 String computeMessage() { 3693 String computeMessage() {
3687 if (message == null) { 3694 if (message == null) {
3688 message = template.template; 3695 message = template.template;
3689 arguments.forEach((key, value) { 3696 arguments.forEach((key, value) {
3690 message = message.replaceAll('#{${key}}', convertToString(value)); 3697 message = message.replaceAll('#{${key}}', convertToString(value));
3691 }); 3698 });
3692 assert(invariant( 3699 assert(invariant(
3693 CURRENT_ELEMENT_SPANNABLE, 3700 CURRENT_ELEMENT_SPANNABLE,
3694 kind == MessageKind.GENERIC || 3701 kind == MessageKind.GENERIC ||
(...skipping 24 matching lines...) Expand all
3719 static String convertToString(value) { 3726 static String convertToString(value) {
3720 if (value is ErrorToken) { 3727 if (value is ErrorToken) {
3721 // Shouldn't happen. 3728 // Shouldn't happen.
3722 return value.assertionMessage; 3729 return value.assertionMessage;
3723 } else if (value is Token) { 3730 } else if (value is Token) {
3724 value = value.value; 3731 value = value.value;
3725 } 3732 }
3726 return '$value'; 3733 return '$value';
3727 } 3734 }
3728 } 3735 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/generated/shared_messages.dart ('k') | pkg/dart_messages/bin/json_converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698