|
5 | 5 | import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
|
6 | 6 | import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
|
7 | 7 | import 'package:analysis_server/src/services/correction/base_processor.dart';
|
| 8 | +import 'package:analysis_server/src/services/correction/bulk_fix_processor.dart'; |
8 | 9 | import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
|
9 | 10 | import 'package:analysis_server/src/services/correction/dart/add_async.dart';
|
10 | 11 | import 'package:analysis_server/src/services/correction/dart/add_await.dart';
|
@@ -376,6 +377,9 @@ class FixInFileProcessor {
|
376 | 377 |
|
377 | 378 | /// The computer for Dart fixes.
|
378 | 379 | class FixProcessor extends BaseProcessor {
|
| 380 | + /// Cached results of [canBulkFix]. |
| 381 | + static final Map<ErrorCode, bool> _bulkFixableErrorCodes = {}; |
| 382 | + |
379 | 383 | static final Map<String, List<MultiProducerGenerator>> lintMultiProducerMap =
|
380 | 384 | {
|
381 | 385 | LintNames.deprecated_member_use_from_same_package: [
|
@@ -1821,6 +1825,36 @@ class FixProcessor extends BaseProcessor {
|
1821 | 1825 | }
|
1822 | 1826 | }
|
1823 | 1827 |
|
| 1828 | + /// Returns whether [errorCode] is an error that can be fixed in bulk. |
| 1829 | + static bool canBulkFix(ErrorCode errorCode) { |
| 1830 | + bool hasBulkFixProducers(List<ProducerGenerator>? producers) { |
| 1831 | + return producers != null && |
| 1832 | + producers.any((producer) => producer().canBeAppliedInBulk); |
| 1833 | + } |
| 1834 | + |
| 1835 | + return _bulkFixableErrorCodes.putIfAbsent(errorCode, () { |
| 1836 | + if (errorCode is LintCode) { |
| 1837 | + final producers = FixProcessor.lintProducerMap[errorCode.name]; |
| 1838 | + if (hasBulkFixProducers(producers)) { |
| 1839 | + return true; |
| 1840 | + } |
| 1841 | + |
| 1842 | + return FixProcessor.lintMultiProducerMap.containsKey(errorCode.name); |
| 1843 | + } |
| 1844 | + |
| 1845 | + final producers = FixProcessor.nonLintProducerMap[errorCode]; |
| 1846 | + if (hasBulkFixProducers(producers)) { |
| 1847 | + return true; |
| 1848 | + } |
| 1849 | + |
| 1850 | + // We can't do detailed checks on multi-producers because the set of |
| 1851 | + // producers may vary depending on the resolved unit (we must configure |
| 1852 | + // them before we can determine the producers). |
| 1853 | + return FixProcessor.nonLintMultiProducerMap.containsKey(errorCode) || |
| 1854 | + BulkFixProcessor.nonLintMultiProducerMap.containsKey(errorCode); |
| 1855 | + }); |
| 1856 | + } |
| 1857 | + |
1824 | 1858 | /// Associate the given correction producer [generator] with the lint with the
|
1825 | 1859 | /// given [lintName].
|
1826 | 1860 | static void registerFixForLint(String lintName, ProducerGenerator generator) {
|
|
0 commit comments