Index: pkg/dart_messages/bin/publish.dart |
diff --git a/pkg/dart_messages/bin/publish.dart b/pkg/dart_messages/bin/publish.dart |
index c7b9c113b5b27857e99a467ea4d9dbe1cb8de2e4..4b497b8113323e9908a9146240217e04e536399c 100644 |
--- a/pkg/dart_messages/bin/publish.dart |
+++ b/pkg/dart_messages/bin/publish.dart |
@@ -3,7 +3,7 @@ |
// BSD-style license that can be found in the LICENSE file. |
import 'dart:convert'; |
-import 'dart:io'; |
+import 'dart:io' as io; |
import '../lib/shared_messages.dart'; |
@@ -35,11 +35,11 @@ void markAsReadonly(String path) { |
void emitJson() { |
var input = MESSAGES; |
- var outPath = Platform.script.resolve(jsonPath).toFilePath(); |
+ var outPath = io.Platform.script.resolve(jsonPath).toFilePath(); |
print("Emitting JSON:"); |
print(" Input: ${input.length} entries"); |
print(" Output: $outPath"); |
- new File(outPath).writeAsStringSync(messagesAsJson); |
+ new io.File(outPath).writeAsStringSync(messagesAsJson); |
print("Emitting JSON done."); |
} |
@@ -82,30 +82,24 @@ String escapeString(String str) { |
/// }; |
void emitDart2js() { |
var input = MESSAGES; |
- var outPath = Platform.script.resolve(dart2jsPath).toFilePath(); |
+ var outPath = io.Platform.script.resolve(dart2jsPath).toFilePath(); |
print("Emitting dart2js:"); |
print(" Input: ${input.length} entries"); |
print(" Output: $outPath"); |
- var enumIds = input.keys.toList(); |
- |
StringBuffer out = new StringBuffer(); |
out.writeln(copyrightHeader); |
out.writeln(dontEditWarning); |
- out.writeln("import '../messages.dart' show MessageTemplate;"); |
- out.writeln(); |
- out.write(("enum SharedMessageKind {\n ")); |
- // We generate on one line on purpose, so that users are less likely to |
- // modify the generated file. |
- out.writeln(enumIds.join(",\n ")); |
- out.writeln("}"); |
+ out.writeln("import '../messages.dart' show MessageKind, MessageTemplate;"); |
out.writeln(); |
- out.writeln("const Map<SharedMessageKind, MessageTemplate> TEMPLATES = " |
- "const <SharedMessageKind, MessageTemplate>{ "); |
+ out.writeln("const Map<MessageKind, MessageTemplate> TEMPLATES = " |
+ "const <MessageKind, MessageTemplate>{ "); |
input.forEach((name, message) { |
- out.writeln(" SharedMessageKind.$name: const MessageTemplate("); |
+ if (!message.usedBy.contains(Platform.dart2js)) return; |
+ |
+ out.writeln(" MessageKind.$name: const MessageTemplate("); |
// TODO(floitsch): include id. |
- out.writeln(" SharedMessageKind.$name,"); |
+ out.writeln(" MessageKind.$name,"); |
out.write(" "); |
out.write(escapeString(message.template)); |
if (message.howToFix != null) { |
@@ -140,7 +134,7 @@ void emitDart2js() { |
}); |
out.writeln("};"); |
- new File(outPath).writeAsStringSync(out.toString()); |
+ new io.File(outPath).writeAsStringSync(out.toString()); |
print("Emitting dart2js done."); |
} |
@@ -182,7 +176,7 @@ String convertToAnalyzerTemplate(String template, holeOrder) { |
/// "Just don't do it"); |
void emitAnalyzer() { |
var input = MESSAGES; |
- var outPath = Platform.script.resolve(analyzerPath).toFilePath(); |
+ var outPath = io.Platform.script.resolve(analyzerPath).toFilePath(); |
print("Emitting analyzer:"); |
print(" Input: ${input.length} entries"); |
print(" Output: $outPath"); |
@@ -191,10 +185,14 @@ void emitAnalyzer() { |
out.writeln(copyrightHeader); |
out.writeln(dontEditWarning); |
out.writeln("import 'package:analyzer/src/generated/error.dart';"); |
- out.writeln(); |
+ out.writeln("import 'package:analyzer/src/generated/parser.dart' " |
+ "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',"); |
@@ -208,7 +206,7 @@ void emitAnalyzer() { |
out.writeln("); // Generated. Don't edit."); |
}); |
- new File(outPath).writeAsStringSync(out.toString()); |
+ new io.File(outPath).writeAsStringSync(out.toString()); |
print("Emitting analyzer done."); |
} |