OLD | NEW |
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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
7 | 7 |
8 import '../lib/shared_messages.dart'; | 8 import '../lib/shared_messages.dart'; |
9 | 9 |
10 const String jsonPath = '../lib/generated/shared_messages.json'; | 10 const String jsonPath = '../lib/generated/shared_messages.json'; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 out.writeln(",\n examples: const ["); | 114 out.writeln(",\n examples: const ["); |
115 | 115 |
116 String escapeExampleContent(String content) { | 116 String escapeExampleContent(String content) { |
117 if (content.contains("\n") || content.contains('"')) { | 117 if (content.contains("\n") || content.contains('"')) { |
118 return 'r"""\n$content"""'; | 118 return 'r"""\n$content"""'; |
119 } else if (content.contains("\\")) { | 119 } else if (content.contains("\\")) { |
120 return 'r"$content"'; | 120 return 'r"$content"'; |
121 } | 121 } |
122 return '"$content"'; | 122 return '"$content"'; |
123 } | 123 } |
| 124 |
124 for (var example in message.examples) { | 125 for (var example in message.examples) { |
125 if (example is String) { | 126 if (example is String) { |
126 out.write(" "); | 127 out.write(" "); |
127 out.write(escapeExampleContent(example)); | 128 out.write(escapeExampleContent(example)); |
128 } else if (example is Map) { | 129 } else if (example is Map) { |
129 out.writeln(" const {"); | 130 out.writeln(" const {"); |
130 example.forEach((String fileName, String content) { | 131 example.forEach((String fileName, String content) { |
131 out.writeln(" '$fileName': "); | 132 out.writeln(" '$fileName': "); |
132 out.write(escapeExampleContent(content)); | 133 out.write(escapeExampleContent(content)); |
133 out.writeln(","); | 134 out.writeln(","); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 /// Translates the shared messages in `../lib/shared_messages.dart` to JSON, | 242 /// Translates the shared messages in `../lib/shared_messages.dart` to JSON, |
242 /// dart2js, and analyzer formats. | 243 /// dart2js, and analyzer formats. |
243 /// | 244 /// |
244 /// Emits the json-output to [jsonPath], the dart2js-output to [dart2jsPath], | 245 /// Emits the json-output to [jsonPath], the dart2js-output to [dart2jsPath], |
245 /// and the analyzer-output to [analyzerPath]. | 246 /// and the analyzer-output to [analyzerPath]. |
246 void main() { | 247 void main() { |
247 emitJson(); | 248 emitJson(); |
248 emitDart2js(); | 249 emitDart2js(); |
249 emitAnalyzer(); | 250 emitAnalyzer(); |
250 } | 251 } |
OLD | NEW |