Skip to content

Commit dadef9b

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Rename CorrectionProducer.errorLength and errorOffset to diagnostic names
Change-Id: I7578da7f1be1f996474b22621885e45ab3e86428 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434100 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 2bd5128 commit dadef9b

File tree

8 files changed

+33
-27
lines changed

8 files changed

+33
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class AddAwait extends ResolvedCorrectionProducer {
118118
);
119119
}
120120
builder.addSimpleInsertion(
121-
offset ?? errorOffset ?? node.offset,
121+
offset ?? diagnosticOffset ?? node.offset,
122122
'await ',
123123
);
124124
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer {
216216

217217
// Create fixes only when its the first diagnostic.
218218
if (propertyDiagnostics.isNotEmpty &&
219-
errorOffset != propertyDiagnostics.first.offset) {
219+
diagnosticOffset != propertyDiagnostics.first.offset) {
220220
return;
221221
}
222222

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class ConvertToIfNull extends ResolvedCorrectionProducer {
4444
Future<void> _preferIfNull(ChangeBuilder builder) async {
4545
var node = this.node;
4646
if (node is ConditionalExpression &&
47-
node.offset == errorOffset &&
48-
node.length == errorLength) {
47+
node.offset == diagnosticOffset &&
48+
node.length == diagnosticLength) {
4949
var condition = node.condition as BinaryExpression;
5050
Expression nullableExpression;
5151
Expression defaultExpression;
@@ -87,8 +87,8 @@ class ConvertToIfNull extends ResolvedCorrectionProducer {
8787
Future<void> _useToConvertNullsToBools(ChangeBuilder builder) async {
8888
var node = this.node;
8989
if (node is BinaryExpression &&
90-
node.offset == errorOffset &&
91-
node.length == errorLength &&
90+
node.offset == diagnosticOffset &&
91+
node.length == diagnosticLength &&
9292
(node.operator.type == TokenType.EQ_EQ ||
9393
node.operator.type == TokenType.BANG_EQ)) {
9494
var left = node.leftOperand;

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,13 @@ class RemoveConstructor extends ResolvedCorrectionProducer {
4848
}
4949

5050
ConstructorDeclaration? _findConstructor() {
51-
var errorOffset = this.errorOffset;
52-
if (errorOffset == null) {
53-
return null;
54-
}
55-
56-
var invalidNodes = (unit as CompilationUnitImpl).invalidNodes;
57-
for (var constructor in invalidNodes) {
58-
if (constructor is ConstructorDeclarationImpl) {
59-
if (range.node(constructor).contains(errorOffset)) {
60-
return constructor;
51+
if (diagnosticOffset case var diagnosticOffset?) {
52+
var invalidNodes = (unit as CompilationUnitImpl).invalidNodes;
53+
for (var constructor in invalidNodes) {
54+
if (constructor is ConstructorDeclarationImpl) {
55+
if (range.node(constructor).contains(diagnosticOffset)) {
56+
return constructor;
57+
}
6158
}
6259
}
6360
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class RemoveDeadCode extends ResolvedCorrectionProducer {
5454
);
5555
return;
5656
}
57-
if (node.offset == errorOffset) {
57+
if (node.offset == diagnosticOffset) {
5858
// The dead code warning starts at the beginning of `node`. Use this node
5959
// as the starting point for dead code removal, or, if there is a larger
6060
// AST node that is fully contained in the dead code range, use it as the
@@ -98,7 +98,7 @@ class RemoveDeadCode extends ResolvedCorrectionProducer {
9898
Future<void> _handleDeadAtEndOfNode(AstNode node) async {
9999
switch (node) {
100100
case BinaryExpression(:var leftOperand, :var operator)
101-
when operator.offset == errorOffset &&
101+
when operator.offset == diagnosticOffset &&
102102
const [
103103
TokenType.AMPERSAND_AMPERSAND,
104104
TokenType.BAR_BAR,
@@ -109,12 +109,13 @@ class RemoveDeadCode extends ResolvedCorrectionProducer {
109109
await _addEdit((builder) {
110110
builder.addDeletion(range.endEnd(leftOperand, node));
111111
});
112-
case Block(:var rightBracket) when rightBracket.offset == errorOffset:
112+
case Block(:var rightBracket)
113+
when rightBracket.offset == diagnosticOffset:
113114
// Dead code starts at the `}` of a block. It's not possible to remove
114115
// the `}`, but if any dead code follows the block, it may be removed.
115116
await _removeDeadCodeAfter(partiallyDeadNode: node);
116117
case DoStatement(:var body, :var whileKeyword)
117-
when whileKeyword.offset == errorOffset:
118+
when whileKeyword.offset == diagnosticOffset:
118119
// Dead code starts at the `while` keyword of a `do` loop. This means
119120
// the body of the loop is partially dead, so the situation is handled
120121
// by `_removeDeadCodeAfter`.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class UseEffectiveIntegerDivision extends ResolvedCorrectionProducer {
2727
Future<void> compute(ChangeBuilder builder) async {
2828
for (var n in node.withAncestors) {
2929
if (n is! MethodInvocation) continue;
30-
if (n.offset != errorOffset && n.length != errorLength) continue;
30+
if (n.offset != diagnosticOffset && n.length != diagnosticLength) {
31+
continue;
32+
}
3133

3234
var target = n.target;
3335
if (target != null) {

pkg/analysis_server_plugin/api.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ package:analysis_server_plugin/edit/dart/correction_producer.dart:
5656
canBeAppliedAcrossSingleFile (getter: bool)
5757
canBeAppliedAutomatically (getter: bool)
5858
coveringNode (getter: AstNode?)
59-
errorLength (getter: int?)
60-
errorOffset (getter: int?)
59+
diagnosticLength (getter: int?)
60+
diagnosticOffset (getter: int?)
61+
errorLength (getter: int?, deprecated)
62+
errorOffset (getter: int?, deprecated)
6163
fixArguments (getter: List<String>?)
6264
fixKind (getter: FixKind?)
6365
multiFixArguments (getter: List<String>?)

pkg/analysis_server_plugin/lib/edit/dart/correction_producer.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,17 @@ sealed class CorrectionProducer<T extends ParsedUnitResult>
174174

175175
/// The length of the source range associated with the diagnostic being
176176
/// fixed, or `null` if there is no diagnostic.
177-
// TODO(srawlins): Rename to 'diagnosticLength'.
178-
int? get errorLength => diagnostic?.problemMessage.length;
177+
int? get diagnosticLength => diagnostic?.problemMessage.length;
179178

180179
/// The offset of the source range associated with the diagnostic being
181180
/// fixed, or `null` if there is no diagnostic.
182-
// TODO(srawlins): Rename to 'diagnosticOffset'.
183-
int? get errorOffset => diagnostic?.problemMessage.offset;
181+
int? get diagnosticOffset => diagnostic?.problemMessage.offset;
182+
183+
@Deprecated("Use 'diagnosticLength' instead")
184+
int? get errorLength => diagnosticLength;
185+
186+
@Deprecated("Use 'diagnosticOffset' instead")
187+
int? get errorOffset => diagnosticOffset;
184188

185189
/// The arguments that should be used when composing the message for a fix, or
186190
/// `null` if the fix message has no parameters or if this producer doesn't

0 commit comments

Comments
 (0)