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

Unified Diff: pkg/dart_messages/bin/publish.dart

Issue 1763373002: Support multiple categories per message. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
Index: pkg/dart_messages/bin/publish.dart
diff --git a/pkg/dart_messages/bin/publish.dart b/pkg/dart_messages/bin/publish.dart
index d6e3f87aafd9f214202a6be3d8b66c0b89a9c701..48f0c304c00c42f85a6ea2f4f64e025f14796c42 100644
--- a/pkg/dart_messages/bin/publish.dart
+++ b/pkg/dart_messages/bin/publish.dart
@@ -172,6 +172,19 @@ String convertToAnalyzerTemplate(String template, holeOrder) {
});
}
+String camlToAllCaps(String input) {
+ StringBuffer out = new StringBuffer();
+ for (int i = 0; i < input.length; i++) {
+ String c = input[i];
+ if (c.toUpperCase() == c) {
+ out.write("_$c");
+ } else {
+ out.write(c.toUpperCase());
+ }
+ }
+ return out.toString();
+}
+
/// Emits the messages in analyzer format.
///
/// Messages are encoded as instances of `ErrorCode` classes where the
@@ -200,21 +213,25 @@ void emitAnalyzer() {
"show ParserErrorCode;");
input.forEach((name, message) {
if (!message.usedBy.contains(Platform.analyzer)) return;
-
- Category category = message.category;
- String className = category.name + "Code";
- out.writeln();
- out.writeln("const $className $name = const $className(");
- out.writeln(" '$name',");
-
- String template = message.template;
- List holeOrder = message.templateHoleOrder;
- String analyzerTemplate = convertToAnalyzerTemplate(template, holeOrder);
- out.write(" ");
- out.write(escapeString(analyzerTemplate));
- out.write(",\n ");
- out.write(escapeString(message.howToFix));
- out.writeln("); // Generated. Don't edit.");
+ List<Category> categories = message.categories;
+ bool hasMultipleCategories = categories.length != 1;
+ for (Category category in categories) {
+ String className = category.name + "Code";
+ String analyzerName =
+ hasMultipleCategories ? "$name${camlToAllCaps(category.name)}" : name;
+ out.writeln();
+ out.writeln("const $className $analyzerName = const $className(");
+ out.writeln(" '$name',");
+
+ String template = message.template;
+ List holeOrder = message.templateHoleOrder;
+ String analyzerTemplate = convertToAnalyzerTemplate(template, holeOrder);
+ out.write(" ");
+ out.write(escapeString(analyzerTemplate));
+ out.write(",\n ");
+ out.write(escapeString(message.howToFix));
+ out.writeln("); // Generated. Don't edit.");
+ }
});
new io.File(outPath).writeAsStringSync(out.toString());
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/messages.dart ('k') | pkg/dart_messages/lib/generated/shared_messages.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698