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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 // An update to this file must be followed by regenerating the corresponding 5 // An update to this file must be followed by regenerating the corresponding
6 // json file. Use `json_converter.dart` in the bin directory. 6 // json, dart2js and analyzer file. Use `publish.dart` in the bin directory.
7 // 7 //
8 // Every message in this file must have an id. Use `message_id.dart` in the 8 // Every message in this file must have an id. Use `message_id.dart` in the
9 // bin directory to generate a fresh one. 9 // bin directory to generate a fresh one.
10 10
11 // The messages in this file should meet the following guide lines: 11 // The messages in this file should meet the following guide lines:
12 // 12 //
13 // 1. The message should be a complete sentence starting with an uppercase 13 // 1. The message should be a complete sentence starting with an uppercase
14 // letter, and ending with a period. 14 // letter, and ending with a period.
15 // 15 //
16 // 2. Reserved words and embedded identifiers should be in single quotes, so 16 // 2. Reserved words and embedded identifiers should be in single quotes, so
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // 10. Prefer to not use imperative tone. That is, the message should not sound 51 // 10. Prefer to not use imperative tone. That is, the message should not sound
52 // accusing or like it is ordering the user around. The computer should 52 // accusing or like it is ordering the user around. The computer should
53 // describe the problem, not criticize for violating the specification. 53 // describe the problem, not criticize for violating the specification.
54 // 54 //
55 // Other things to keep in mind: 55 // Other things to keep in mind:
56 // 56 //
57 // Generally, we want to provide messages that consists of three sentences: 57 // Generally, we want to provide messages that consists of three sentences:
58 // 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we 58 // 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we
59 // combine the first two in [template] and the last in [howToFix]. 59 // combine the first two in [template] and the last in [howToFix].
60 60
61 final Map<String, Map> MESSAGES = { 61 import 'dart:convert';
62
63 /// Encodes the category of the message.
64 ///
65 /// This is currently only used in the analyzer.
66 // TODO(floitsch): encode severity and type in the category, so we can generate
67 // the corresponding ErrorCode subclasses.
68 class Category {
69 static final analysisOptionsError = new Category("AnalysisOptionsError");
70
71 static final analysisOptionsWarning = new Category("AnalysisOptionsWarning");
72
73 static final checkedModeCompileTimeError = new Category(
74 "CheckedModeCompileTimeError");
75
76 final String name;
77
78 Category(this.name);
79 }
80
81
82 class Message {
83 final String id;
84 final Category category;
85 final String template;
86 // The analyzer fills holes positionally (and not named). The following field
87 // overrides the order of the holes.
88 // For example the template "The argument #field in #cls is bad", could have
89 // the order `["cls", "field"]', which means that the analyzer would first
90 // provide the class `cls` and then only `field`.
91 // This list is generally `null`, but when it is provided it must contain all
92 // holes.
93 final List templateHoleOrder;
94 final String howToFix;
95 final List<String> options;
96 final List examples;
97
98 Message({this.id, this.category, this.template, this.templateHoleOrder,
99 this.howToFix, this.options, this.examples});
100 }
101
102 String get messagesAsJson {
103 var jsonified = {};
104 MESSAGES.forEach((String name, Message message) {
105 jsonified[name] = {
106 'id': message.id,
107 'category': message.category.name,
108 'template': message.template,
109 'howToFix': message.howToFix
110 };
111 });
112 return JSON.encode(jsonified);
113 }
114
115 final Map<String, Message> MESSAGES = {
116 'exampleMessage': new Message(
117 id: 'use an Id generated by bin/message_id.dart',
118 category: Category.analysisOptionsError,
119 template: "#use #named #arguments",
120 templateHoleOrder: ["arguments", "named", "use"],
121 howToFix: "an explanation on how to fix things",
122 examples: [r'''
123 Some multiline example;
124 That generates the bug.''',
125 {
126 'fileA.dart': '''
127 or a map from file to content.
128 again multiline''',
129 'fileB.dart': '''
130 with possibly multiple files.
131 muliline too'''
132 }
133 ]
134 ),
62 }; 135 };
OLDNEW
« 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