1010
1111import 'dart:io' ;
1212
13+ import 'package:analyzer/diagnostic/diagnostic.dart' ;
1314import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart' ;
1415import 'package:analyzer/dart/ast/ast.dart' ;
1516import 'package:analyzer/src/generated/source.dart' ;
@@ -127,6 +128,7 @@ main(List<String> args) async {
127128 assert (listener.numExceptions == 0 );
128129 for (var package in packages) {
129130 print ('Migrating $package ' );
131+ listener.currentPackage = package.name;
130132 var testUri = thisSdkUri.resolve (package.packagePath);
131133 var contextCollection = AnalysisContextCollectionImpl (
132134 includedPaths: [testUri.toFilePath ()], sdkPath: sdk.sdkPath);
@@ -140,11 +142,17 @@ main(List<String> args) async {
140142 var migration = NullabilityMigration (listener, permissive: true );
141143 for (var file in localFiles) {
142144 var resolvedUnit = await context.currentSession.getResolvedUnit (file);
143- migration.prepareInput (resolvedUnit);
145+ if (! resolvedUnit.errors.any ((e) => e.severity == Severity .error)) {
146+ migration.prepareInput (resolvedUnit);
147+ } else {
148+ print ('Skipping $file , it has errors.' );
149+ }
144150 }
145151 for (var file in localFiles) {
146152 var resolvedUnit = await context.currentSession.getResolvedUnit (file);
147- migration.processInput (resolvedUnit);
153+ if (! resolvedUnit.errors.any ((e) => e.severity == Severity .error)) {
154+ migration.processInput (resolvedUnit);
155+ }
148156 }
149157 migration.finish ();
150158 }
@@ -161,10 +169,17 @@ main(List<String> args) async {
161169 print ('${listener .numExceptions } exceptions in '
162170 '${listener .groupedExceptions .length } categories' );
163171 print ('Exception categories:' );
164- var sortedExceptions = listener.groupedExceptions.entries.toList ();
165- sortedExceptions.sort ((e1, e2) => e2.value.length.compareTo (e1.value.length));
172+ var sortedExceptions = listener.groupedExceptions.entries
173+ .map ((entry) => MapEntry (
174+ entry.key,
175+ entry.value.entries.toList ()
176+ ..sort ((e1, e2) => e2.value.compareTo (e1.value))))
177+ .toList ()
178+ ..sort ((e1, e2) => e2.value.length.compareTo (e1.value.length));
166179 for (var entry in sortedExceptions) {
167- print (' ${entry .key } (x${entry .value .length })' );
180+ final packages =
181+ entry.value.map ((entry) => "${entry .key } x${entry .value }" ).join (', ' );
182+ print (' ${entry .key } ($packages )' );
168183 }
169184
170185 if (categoryOfInterest == null ) {
@@ -212,7 +227,8 @@ class _Listener implements NullabilityMigrationListener {
212227 /// if its category contains the string.
213228 final String categoryOfInterest;
214229
215- final groupedExceptions = < String , List <String >> {};
230+ /// Exception mapped to a map of packages & exception counts.
231+ final groupedExceptions = < String , Map <String , int >> {};
216232
217233 int numExceptions = 0 ;
218234
@@ -226,6 +242,8 @@ class _Listener implements NullabilityMigrationListener {
226242
227243 int numDeadCodeSegmentsFound = 0 ;
228244
245+ String currentPackage;
246+
229247 _Listener (this .categoryOfInterest, {this .printExceptionNodeOnly = false });
230248
231249 @override
@@ -272,7 +290,8 @@ $stackTrace
272290 print (detail);
273291 }
274292 }
275- (groupedExceptions[category] ?? = []).add (detail);
293+ (groupedExceptions[category] ?? = < String , int > {})
294+ .update (currentPackage, (value) => ++ value, ifAbsent: () => 1 );
276295 ++ numExceptions;
277296 }
278297
0 commit comments