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

Unified Diff: pkg/dart_messages/lib/shared_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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/dart_messages/lib/generated/shared_messages.json ('k') | pkg/dart_messages/lib/shared_messages.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dart_messages/lib/shared_messages.dart
diff --git a/pkg/dart_messages/lib/shared_messages.dart b/pkg/dart_messages/lib/shared_messages.dart
index bd51f581934a31c2f75267c359de6f5ba33f490e..896f52ad546ca0ba5ac6e68adc638515fe891263 100644
--- a/pkg/dart_messages/lib/shared_messages.dart
+++ b/pkg/dart_messages/lib/shared_messages.dart
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
// An update to this file must be followed by regenerating the corresponding
-// json file. Use `json_converter.dart` in the bin directory.
+// json, dart2js and analyzer file. Use `publish.dart` in the bin directory.
//
// Every message in this file must have an id. Use `message_id.dart` in the
// bin directory to generate a fresh one.
@@ -58,5 +58,78 @@
// 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we
// combine the first two in [template] and the last in [howToFix].
-final Map<String, Map> MESSAGES = {
+import 'dart:convert';
+
+/// Encodes the category of the message.
+///
+/// This is currently only used in the analyzer.
+// TODO(floitsch): encode severity and type in the category, so we can generate
+// the corresponding ErrorCode subclasses.
+class Category {
+ static final analysisOptionsError = new Category("AnalysisOptionsError");
+
+ static final analysisOptionsWarning = new Category("AnalysisOptionsWarning");
+
+ static final checkedModeCompileTimeError = new Category(
+ "CheckedModeCompileTimeError");
+
+ final String name;
+
+ Category(this.name);
+}
+
+
+class Message {
+ final String id;
+ final Category category;
+ final String template;
+ // The analyzer fills holes positionally (and not named). The following field
+ // overrides the order of the holes.
+ // For example the template "The argument #field in #cls is bad", could have
+ // the order `["cls", "field"]', which means that the analyzer would first
+ // provide the class `cls` and then only `field`.
+ // This list is generally `null`, but when it is provided it must contain all
+ // holes.
+ final List templateHoleOrder;
+ final String howToFix;
+ final List<String> options;
+ final List examples;
+
+ Message({this.id, this.category, this.template, this.templateHoleOrder,
+ this.howToFix, this.options, this.examples});
+}
+
+String get messagesAsJson {
+ var jsonified = {};
+ MESSAGES.forEach((String name, Message message) {
+ jsonified[name] = {
+ 'id': message.id,
+ 'category': message.category.name,
+ 'template': message.template,
+ 'howToFix': message.howToFix
+ };
+ });
+ return JSON.encode(jsonified);
+}
+
+final Map<String, Message> MESSAGES = {
+ 'exampleMessage': new Message(
+ id: 'use an Id generated by bin/message_id.dart',
+ category: Category.analysisOptionsError,
+ template: "#use #named #arguments",
+ templateHoleOrder: ["arguments", "named", "use"],
+ howToFix: "an explanation on how to fix things",
+ examples: [r'''
+ Some multiline example;
+ That generates the bug.''',
+ {
+ 'fileA.dart': '''
+ or a map from file to content.
+ again multiline''',
+ 'fileB.dart': '''
+ with possibly multiple files.
+ muliline too'''
+ }
+ ]
+ ),
};
« no previous file with comments | « pkg/dart_messages/lib/generated/shared_messages.json ('k') | pkg/dart_messages/lib/shared_messages.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698