Skip to content

Commit f6828dd

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Simplify CorrectionProducer, et al.
Just a lot of tidying in preparation for this code being public API in the `analysis_server_plugin` package. A big change: * Convert `CorrectionProducer.assistArguments`, `CorrectionProducer.fixArguments`, and `CorrectionProducer.multiFixArguments` each from a `List<Object>?` to a `List<String>?`. This should be a no-op. Smaller changes: * Make private: `AssistProcessor.generators`, `.multiGenerators`, `.assistContext`, `.assists`, * Make private: `CorrectionProducerContext.selectionOffset`, `.selectionLength`, `.utils`, `.sessionHelper`, `.unitResult`, `.applyingBulkFixes`, `.diagnostic`, `.node`, `.token`. * Make private: `FixProcessor.fixContext`. * Remove `CorrectionProducerContext.selectionEnd`, `.unit`, `.file`, `.session`, `.workspace`, `.typeProvider`; these can be accessed via getters. * Remove unused `FixProcessor.computeFix()`. * Make doc comments more idiomatic. Change-Id: I100fe81aad612967191568fe207ff0b807f131b3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364420 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent b0535bd commit f6828dd

File tree

62 files changed

+243
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+243
-260
lines changed

pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import 'package:analyzer_plugin/utilities/change_builder/conflicting_edit_except
8484
/// The computer for Dart assists.
8585
class AssistProcessor {
8686
/// A list of the generators used to produce assists.
87-
static const List<ProducerGenerator> generators = [
87+
static const List<ProducerGenerator> _generators = [
8888
AddDiagnosticPropertyReference.new,
8989
AddReturnType.new,
9090
AddTypeAnnotation.bulkFixable,
@@ -155,23 +155,23 @@ class AssistProcessor {
155155
];
156156

157157
/// A list of the multi-generators used to produce assists.
158-
static const List<MultiProducerGenerator> multiGenerators = [
158+
static const List<MultiProducerGenerator> _multiGenerators = [
159159
FlutterWrap.new,
160160
SurroundWith.new,
161161
];
162162

163-
final DartAssistContext assistContext;
163+
final DartAssistContext _assistContext;
164164

165-
final List<Assist> assists = <Assist>[];
165+
final List<Assist> _assists = [];
166166

167-
AssistProcessor(this.assistContext);
167+
AssistProcessor(this._assistContext);
168168

169169
Future<List<Assist>> compute() async {
170-
if (isMacroGenerated(assistContext.resolveResult.file.path)) {
171-
return assists;
170+
if (isMacroGenerated(_assistContext.resolveResult.file.path)) {
171+
return _assists;
172172
}
173173
await _addFromProducers();
174-
return assists;
174+
return _assists;
175175
}
176176

177177
void _addAssistFromBuilder(ChangeBuilder builder, AssistKind kind,
@@ -182,24 +182,23 @@ class AssistProcessor {
182182
}
183183
change.id = kind.id;
184184
change.message = formatList(kind.message, args);
185-
assists.add(Assist(kind, change));
185+
_assists.add(Assist(kind, change));
186186
}
187187

188188
Future<void> _addFromProducers() async {
189189
var context = CorrectionProducerContext.createResolved(
190-
selectionOffset: assistContext.selectionOffset,
191-
selectionLength: assistContext.selectionLength,
192-
resolvedResult: assistContext.resolveResult,
193-
workspace: assistContext.workspace,
190+
selectionOffset: _assistContext.selectionOffset,
191+
selectionLength: _assistContext.selectionLength,
192+
resolvedResult: _assistContext.resolveResult,
194193
);
195194
if (context == null) {
196195
return;
197196
}
198197

199198
Future<void> compute(CorrectionProducer producer) async {
200199
producer.configure(context);
201-
var builder = ChangeBuilder(
202-
workspace: context.workspace, eol: context.utils.endOfLine);
200+
var builder =
201+
ChangeBuilder(workspace: _assistContext.workspace, eol: producer.eol);
203202
try {
204203
await producer.compute(builder);
205204
var assistKind = producer.assistKind;
@@ -210,21 +209,21 @@ class AssistProcessor {
210209
} on ConflictingEditException catch (exception, stackTrace) {
211210
// Handle the exception by (a) not adding an assist based on the
212211
// producer and (b) logging the exception.
213-
assistContext.instrumentationService
212+
_assistContext.instrumentationService
214213
.logException(exception, stackTrace);
215214
}
216215
}
217216

218-
for (var generator in generators) {
217+
for (var generator in _generators) {
219218
if (!_generatorAppliesToAnyLintRule(
220219
generator,
221-
assistContext.producerGeneratorsForLintRules[generator] ?? {},
220+
_assistContext.producerGeneratorsForLintRules[generator] ?? {},
222221
)) {
223222
var producer = generator();
224223
await compute(producer);
225224
}
226225
}
227-
for (var multiGenerator in multiGenerators) {
226+
for (var multiGenerator in _multiGenerators) {
228227
var multiProducer = multiGenerator();
229228
multiProducer.configure(context);
230229
for (var producer in await multiProducer.producers) {
@@ -240,17 +239,17 @@ class AssistProcessor {
240239
Set<String> errorCodes,
241240
) {
242241
var selectionEnd =
243-
assistContext.selectionOffset + assistContext.selectionLength;
244-
var locator = NodeLocator(assistContext.selectionOffset, selectionEnd);
245-
var node = locator.searchWithin(assistContext.resolveResult.unit);
242+
_assistContext.selectionOffset + _assistContext.selectionLength;
243+
var locator = NodeLocator(_assistContext.selectionOffset, selectionEnd);
244+
var node = locator.searchWithin(_assistContext.resolveResult.unit);
246245
if (node == null) {
247246
return false;
248247
}
249248

250249
var fileOffset = node.offset;
251-
for (var error in assistContext.resolveResult.errors) {
250+
for (var error in _assistContext.resolveResult.errors) {
252251
var errorSource = error.source;
253-
if (assistContext.resolveResult.path == errorSource.fullName) {
252+
if (_assistContext.resolveResult.path == errorSource.fullName) {
254253
if (fileOffset >= error.offset &&
255254
fileOffset <= error.offset + error.length) {
256255
if (errorCodes.contains(error.errorCode.name)) {
@@ -263,7 +262,7 @@ class AssistProcessor {
263262
}
264263

265264
static Map<ProducerGenerator, Set<String>> computeLintRuleMap() => {
266-
for (var generator in generators)
265+
for (var generator in _generators)
267266
generator: {
268267
for (var MapEntry(key: lintName, value: generators)
269268
in FixProcessor.lintProducerMap.entries)

pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ class BulkFixProcessor {
627627
resolvedResult: unit,
628628
selectionOffset: diagnostic.offset,
629629
selectionLength: diagnostic.length,
630-
workspace: workspace,
631630
);
632631
}
633632

@@ -721,7 +720,6 @@ class BulkFixProcessor {
721720
resolvedResult: result,
722721
selectionOffset: diagnostic.offset,
723722
selectionLength: diagnostic.length,
724-
workspace: workspace,
725723
);
726724
if (context == null) {
727725
return;
@@ -784,7 +782,6 @@ class BulkFixProcessor {
784782
resolvedResult: result,
785783
selectionOffset: diagnostic.offset,
786784
selectionLength: diagnostic.length,
787-
workspace: workspace,
788785
);
789786

790787
var errorCode = diagnostic.errorCode;
@@ -854,7 +851,7 @@ class BulkFixProcessor {
854851
await _applyProducer(context, producer);
855852
var newHash = computeChangeHash();
856853
if (newHash != oldHash) {
857-
changeMap.add(context.unitResult.path, code.toLowerCase());
854+
changeMap.add(context.path, code.toLowerCase());
858855
}
859856
}
860857

0 commit comments

Comments
 (0)