Skip to content

Commit 1029af6

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Rename FixContext.error to .diagnostic
Work towards #60635 Change-Id: I2a789749393efa3688ad0cf6b0d0e93e97136492 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434540 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 5ce8093 commit 1029af6

File tree

6 files changed

+36
-27
lines changed

6 files changed

+36
-27
lines changed

pkg/analysis_server/test/src/services/correction/fix/fix_processor.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ abstract class BaseFixProcessorTest extends AbstractSingleUnitTest {
3838
return DartChangeWorkspace([await session]);
3939
}
4040

41-
/// Computes fixes for the given [error] in [testUnit].
42-
Future<List<Fix>> _computeFixes(Diagnostic error) async {
41+
/// Computes fixes for the given [diagnostic] in [testUnit].
42+
Future<List<Fix>> _computeFixes(Diagnostic diagnostic) async {
4343
var libraryResult = testLibraryResult;
4444
if (libraryResult == null) {
4545
return const [];
@@ -49,7 +49,7 @@ abstract class BaseFixProcessorTest extends AbstractSingleUnitTest {
4949
workspace: await workspace,
5050
libraryResult: libraryResult,
5151
unitResult: testAnalysisResult,
52-
error: error,
52+
error: diagnostic,
5353
);
5454
return await computeFixes(context);
5555
}
@@ -648,9 +648,9 @@ abstract class FixProcessorTest extends BaseFixProcessorTest {
648648
}
649649
}
650650

651-
/// Computes fixes for the given [error] in [testUnit].
651+
/// Computes fixes for the given [diagnostic] in [testUnit].
652652
@override
653-
Future<List<Fix>> _computeFixes(Diagnostic error) async {
653+
Future<List<Fix>> _computeFixes(Diagnostic diagnostic) async {
654654
var libraryResult = testLibraryResult;
655655
if (libraryResult == null) {
656656
return const [];
@@ -660,7 +660,7 @@ abstract class FixProcessorTest extends BaseFixProcessorTest {
660660
workspace: await workspace,
661661
libraryResult: libraryResult,
662662
unitResult: testAnalysisResult,
663-
error: error,
663+
error: diagnostic,
664664
);
665665
return await computeFixes(context);
666666
}

pkg/analysis_server_plugin/api.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ package:analysis_server_plugin/edit/fix/dart_fix_context.dart:
115115
new (constructor: DartFixContext Function({bool autoTriggered, CorrectionUtils? correctionUtils, required Diagnostic error, required InstrumentationService instrumentationService, required ResolvedLibraryResult libraryResult, required ResolvedUnitResult unitResult, required ChangeWorkspace workspace}))
116116
autoTriggered (getter: bool)
117117
correctionUtils (getter: CorrectionUtils)
118+
diagnostic (getter: Diagnostic)
118119
error (getter: Diagnostic)
119120
instrumentationService (getter: InstrumentationService)
120121
libraryResult (getter: ResolvedLibraryResult)
@@ -131,7 +132,8 @@ package:analysis_server_plugin/edit/fix/fix.dart:
131132
toString (method: String Function())
132133
package:analysis_server_plugin/edit/fix/fix_context.dart:
133134
FixContext (class extends Object):
134-
error (getter: Diagnostic)
135+
diagnostic (getter: Diagnostic)
136+
error (getter: Diagnostic, deprecated)
135137
package:analysis_server_plugin/plugin.dart:
136138
Plugin (class extends Object):
137139
new (constructor: Plugin Function())

pkg/analysis_server_plugin/lib/edit/fix/dart_fix_context.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,22 @@ class DartFixContext implements FixContext {
5353
_cachedTopLevelDeclarations = {};
5454

5555
@override
56-
final Diagnostic error;
56+
final Diagnostic diagnostic;
5757

5858
DartFixContext({
5959
required this.instrumentationService,
6060
required this.workspace,
6161
required this.libraryResult,
6262
required this.unitResult,
63-
required this.error,
63+
// TODO(srawlins): Rename to `diagnostic`.
64+
required Diagnostic error,
6465
this.autoTriggered = false,
6566
CorrectionUtils? correctionUtils,
66-
}) : correctionUtils = correctionUtils ?? CorrectionUtils(unitResult);
67+
}) : diagnostic = error,
68+
correctionUtils = correctionUtils ?? CorrectionUtils(unitResult);
69+
70+
@override
71+
Diagnostic get error => diagnostic;
6772

6873
/// Returns the mapping from each library (that is available to this context)
6974
/// to a top-level declaration that is exported (not necessary declared) by

pkg/analysis_server_plugin/lib/edit/fix/fix_context.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
1010
/// Clients may not extend, implement or mix-in this class.
1111
abstract interface class FixContext {
1212
/// The diagnostic to fix.
13-
// TODO(srawlins): Rename to 'diagnostic'.
13+
Diagnostic get diagnostic;
14+
15+
@Deprecated("Use 'diagnostic' instead")
1416
Diagnostic get error;
1517
}

pkg/analysis_server_plugin/lib/src/correction/fix_in_file_processor.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ final class FixInFileProcessor {
2626
FixInFileProcessor(this._fixContext, {this.alreadyCalculated});
2727

2828
Future<List<Fix>> compute() async {
29-
var error = _fixContext.error;
29+
var diagnostic = _fixContext.diagnostic;
3030

31-
var generators = _getGenerators(error.diagnosticCode);
31+
var generators = _getGenerators(diagnostic.diagnosticCode);
3232

3333
String getAlreadyCalculatedValue(ProducerGenerator generator) {
34-
return '${generator.hashCode}|${error.diagnosticCode.name}';
34+
return '${generator.hashCode}|${diagnostic.diagnosticCode.name}';
3535
}
3636

3737
// Remove generators for which we've already calculated and we were asked to
@@ -48,7 +48,7 @@ final class FixInFileProcessor {
4848
}
4949

5050
var diagnostics = _fixContext.unitResult.diagnostics
51-
.where((e) => error.diagnosticCode.name == e.diagnosticCode.name);
51+
.where((e) => diagnostic.diagnosticCode.name == e.diagnosticCode.name);
5252
if (diagnostics.length < 2) {
5353
return const <Fix>[];
5454
}
@@ -68,28 +68,28 @@ final class FixInFileProcessor {
6868
workspace: _fixContext.workspace,
6969
libraryResult: _fixContext.libraryResult,
7070
unitResult: _fixContext.unitResult,
71-
error: error,
71+
error: diagnostic,
7272
correctionUtils: _fixContext.correctionUtils,
7373
);
74-
fixState = await _fixDiagnostic(fixContext, fixState, generator, error);
74+
fixState =
75+
await _fixDiagnostic(fixContext, fixState, generator, diagnostic);
7576

7677
// The original error was not fixable; continue to next generator.
7778
if (!(fixState.builder as ChangeBuilderImpl).hasEdits) {
7879
continue;
7980
}
8081

8182
// Compute fixes for the rest of the errors.
82-
for (var diagnostic in diagnostics.where((item) => item != error)) {
83+
for (var d in diagnostics.where((item) => item != diagnostic)) {
8384
var fixContext = DartFixContext(
8485
instrumentationService: _fixContext.instrumentationService,
8586
workspace: _fixContext.workspace,
8687
libraryResult: _fixContext.libraryResult,
8788
unitResult: _fixContext.unitResult,
88-
error: diagnostic,
89+
error: d,
8990
correctionUtils: _fixContext.correctionUtils,
9091
);
91-
fixState =
92-
await _fixDiagnostic(fixContext, fixState, generator, diagnostic);
92+
fixState = await _fixDiagnostic(fixContext, fixState, generator, d);
9393
}
9494
if (fixState is _NotEmptyFixState) {
9595
var sourceChange = fixState.builder.sourceChange;

pkg/analysis_server_plugin/lib/src/correction/fix_processor.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ class FixProcessor {
8181
}
8282

8383
Future<void> _addFromProducers() async {
84-
var error = _fixContext.error;
84+
var diagnostic = _fixContext.diagnostic;
8585
var context = CorrectionProducerContext.createResolved(
8686
libraryResult: _fixContext.libraryResult,
8787
unitResult: _fixContext.unitResult,
8888
dartFixContext: _fixContext,
89-
diagnostic: error,
90-
selectionOffset: _fixContext.error.offset,
91-
selectionLength: _fixContext.error.length,
89+
diagnostic: diagnostic,
90+
selectionOffset: _fixContext.diagnostic.offset,
91+
selectionLength: _fixContext.diagnostic.length,
9292
);
9393

9494
Future<void> compute(CorrectionProducer producer) async {
@@ -122,7 +122,7 @@ class FixProcessor {
122122
}
123123
}
124124

125-
var diagnosticCode = error.diagnosticCode;
125+
var diagnosticCode = diagnostic.diagnosticCode;
126126
List<ProducerGenerator>? generators;
127127
List<MultiProducerGenerator>? multiGenerators;
128128
if (diagnosticCode is LintCode) {
@@ -157,7 +157,7 @@ class FixProcessor {
157157
if (producer.fixKind == ignoreErrorAnalysisFileKind) {
158158
if (alreadyCalculated?.add('${generator.hashCode}|'
159159
'${ignoreErrorAnalysisFileKind.id}|'
160-
'${error.diagnosticCode.name}') ==
160+
'${diagnostic.diagnosticCode.name}') ==
161161
false) {
162162
// We did this before and was asked to not do it again. Skip.
163163
continue;

0 commit comments

Comments
 (0)