|
17 | 17 | library; |
18 | 18 |
|
19 | 19 | import 'dart:convert'; |
20 | | -import 'dart:io'; |
21 | 20 |
|
22 | 21 | import 'package:analyzer_testing/package_root.dart' as pkg_root; |
23 | 22 | import 'package:analyzer_utilities/extensions/string.dart'; |
24 | 23 | import 'package:analyzer_utilities/messages.dart'; |
25 | 24 | import 'package:analyzer_utilities/tools.dart'; |
26 | 25 | import 'package:collection/collection.dart'; |
27 | | -import 'package:path/path.dart'; |
28 | 26 |
|
29 | 27 | import 'error_code_info.dart'; |
30 | 28 |
|
31 | 29 | Future<void> main() async { |
32 | 30 | await GeneratedContent.generateAll(pkg_root.packageRoot, allTargets); |
33 | | - |
34 | | - _SyntacticErrorGenerator().printSummary(); |
35 | 31 | } |
36 | 32 |
|
37 | 33 | /// A list of all targets generated by this code generator. |
@@ -297,88 +293,3 @@ import 'package:analyzer/src/pubspec/pubspec_warning_code.dart'; |
297 | 293 | ); |
298 | 294 | } |
299 | 295 | } |
300 | | - |
301 | | -class _SyntacticErrorGenerator { |
302 | | - final String errorConverterSource; |
303 | | - final String parserSource; |
304 | | - |
305 | | - factory _SyntacticErrorGenerator() { |
306 | | - String frontEndSharedPkgPath = normalize( |
307 | | - join(pkg_root.packageRoot, '_fe_analyzer_shared'), |
308 | | - ); |
309 | | - |
310 | | - String errorConverterSource = File( |
311 | | - join( |
312 | | - analyzerPkgPath, |
313 | | - joinAll(posix.split('lib/src/fasta/error_converter.dart')), |
314 | | - ), |
315 | | - ).readAsStringSync(); |
316 | | - String parserSource = File( |
317 | | - join( |
318 | | - frontEndSharedPkgPath, |
319 | | - joinAll(posix.split('lib/src/parser/parser.dart')), |
320 | | - ), |
321 | | - ).readAsStringSync(); |
322 | | - |
323 | | - return _SyntacticErrorGenerator._(errorConverterSource, parserSource); |
324 | | - } |
325 | | - |
326 | | - _SyntacticErrorGenerator._(this.errorConverterSource, this.parserSource); |
327 | | - |
328 | | - void printSummary() { |
329 | | - // Build a map of error message to ParserErrorCode |
330 | | - var messageToName = <String, String>{}; |
331 | | - for (var entry in analyzerMessages['ParserErrorCode']!.entries) { |
332 | | - String message = entry.value.problemMessage.replaceAll( |
333 | | - placeholderPattern, |
334 | | - '', |
335 | | - ); |
336 | | - messageToName[message] = entry.key; |
337 | | - } |
338 | | - |
339 | | - String messageFromEntryTemplate(ErrorCodeInfo entry) { |
340 | | - String problemMessage = entry.problemMessage; |
341 | | - String message = problemMessage.replaceAll(RegExp(r'#\w+'), ''); |
342 | | - return message; |
343 | | - } |
344 | | - |
345 | | - // Remove entries that have already been translated |
346 | | - for (ErrorCodeInfo entry |
347 | | - in sharedToAnalyzerErrorCodeTables.infoToAnalyzerCode.keys) { |
348 | | - messageToName.remove(messageFromEntryTemplate(entry)); |
349 | | - } |
350 | | - |
351 | | - // Print the # of autogenerated ParserErrorCodes. |
352 | | - print( |
353 | | - '${messageToName.length} of ' |
354 | | - '${sharedToAnalyzerErrorCodeTables.infoToAnalyzerCode.length} ParserErrorCodes generated.', |
355 | | - ); |
356 | | - |
357 | | - // List the ParserErrorCodes that could easily be auto generated |
358 | | - // but have not been already. |
359 | | - var analyzerToFasta = <String, List<String>>{}; |
360 | | - frontEndMessages.forEach((fastaName, entry) { |
361 | | - var analyzerName = messageToName[messageFromEntryTemplate(entry)]; |
362 | | - if (analyzerName != null) { |
363 | | - analyzerToFasta |
364 | | - .putIfAbsent(analyzerName, () => <String>[]) |
365 | | - .add(fastaName); |
366 | | - } |
367 | | - }); |
368 | | - if (analyzerToFasta.isNotEmpty) { |
369 | | - print(''); |
370 | | - print('The following ParserErrorCodes could be auto generated:'); |
371 | | - for (String analyzerName in analyzerToFasta.keys.toList()..sort()) { |
372 | | - List<String> fastaNames = analyzerToFasta[analyzerName]!; |
373 | | - if (fastaNames.length == 1) { |
374 | | - print(' $analyzerName = ${fastaNames.first}'); |
375 | | - } else { |
376 | | - print(' $analyzerName = $fastaNames'); |
377 | | - } |
378 | | - } |
379 | | - if (analyzerToFasta.length > 3) { |
380 | | - print(' ${analyzerToFasta.length} total'); |
381 | | - } |
382 | | - } |
383 | | - } |
384 | | -} |
0 commit comments