Skip to content

Commit 73d2e85

Browse files
srawlinsCommit Queue
authored andcommitted
Deprecate RangeFactory.error in favor of RangeFactory.diagnostic
Change-Id: I1d4c75ea58f9bdd763665ce009cb15f34b94240e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434983 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 1df157b commit 73d2e85

File tree

10 files changed

+21
-14
lines changed

10 files changed

+21
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class AddConst extends ResolvedCorrectionProducer {
182182
error.diagnosticCode == LinterLintCode.prefer_const_constructors,
183183
),
184184
];
185-
var ranges = diagnostics.map(range.error);
185+
var ranges = diagnostics.map(range.diagnostic);
186186
var variablesRanges = variables.map((v) {
187187
var initializer = v.initializer;
188188
if (initializer == null) return range.node(v);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ReplaceBooleanWithBool extends ResolvedCorrectionProducer {
2525
Future<void> compute(ChangeBuilder builder) async {
2626
if (diagnostic case var diagnostic?) {
2727
await builder.addDartFileEdit(file, (builder) {
28-
builder.addSimpleReplacement(range.error(diagnostic), 'bool');
28+
builder.addSimpleReplacement(range.diagnostic(diagnostic), 'bool');
2929
});
3030
}
3131
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ class ReplaceContainerWithColoredBox extends ResolvedCorrectionProducer {
2828
var diagnostic = this.diagnostic;
2929
if (diagnostic is Diagnostic) {
3030
await builder.addDartFileEdit(file, (builder) {
31-
builder.addSimpleReplacement(range.error(diagnostic), 'ColoredBox');
31+
builder.addSimpleReplacement(
32+
range.diagnostic(diagnostic),
33+
'ColoredBox',
34+
);
3235
});
3336
}
3437
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ReplaceContainerWithSizedBox extends ResolvedCorrectionProducer {
2828
var diagnostic = this.diagnostic;
2929
if (diagnostic is Diagnostic) {
3030
await builder.addDartFileEdit(file, (builder) {
31-
builder.addSimpleReplacement(range.error(diagnostic), 'SizedBox');
31+
builder.addSimpleReplacement(range.diagnostic(diagnostic), 'SizedBox');
3232
});
3333
}
3434
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ReplaceNullWithVoid extends ResolvedCorrectionProducer {
2727
var diagnostic = this.diagnostic;
2828
if (diagnostic is Diagnostic) {
2929
await builder.addDartFileEdit(file, (builder) {
30-
builder.addSimpleReplacement(range.error(diagnostic), 'void');
30+
builder.addSimpleReplacement(range.diagnostic(diagnostic), 'void');
3131
});
3232
}
3333
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ReplaceVarWithDynamic extends ResolvedCorrectionProducer {
2525
var diagnostic = this.diagnostic;
2626
if (diagnostic is Diagnostic) {
2727
await builder.addDartFileEdit(file, (builder) {
28-
builder.addSimpleReplacement(range.error(diagnostic), 'dynamic');
28+
builder.addSimpleReplacement(range.diagnostic(diagnostic), 'dynamic');
2929
});
3030
}
3131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ReplaceWithNamedConstant extends ResolvedCorrectionProducer {
3535
}
3636

3737
await builder.addDartFileEdit(file, (builder) {
38-
builder.addSimpleReplacement(range.error(diagnostic), correction);
38+
builder.addSimpleReplacement(range.diagnostic(diagnostic), correction);
3939
});
4040
}
4141
}

pkg/analyzer_plugin/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.13.2
2+
- Deprecated: `RangeFactory.error` is replaced by `RangeFactory.diagnostic`.
3+
14
## 0.13.1
25
- Updated SDK constraint to `^3.5.0`.
36
- Require version `7.4.x` of the `analyzer` package.

pkg/analyzer_plugin/lib/utilities/range_factory.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final RangeFactory range = RangeFactory();
1414

1515
/// A factory used to create instances of [SourceRange] based on various
1616
/// syntactic and semantic entities.
17+
// TODO(srawlins): Make this class final.
1718
class RangeFactory {
1819
/// Return a source range that covers all of the arguments in the
1920
/// [argumentList] between the [lower] and [upper] indices, inclusive. The
@@ -95,6 +96,10 @@ class RangeFactory {
9596
return startOffsetEndOffset(startOffset, endOffset);
9697
}
9798

99+
/// A source range that covers the same range as the given [diagnostic].
100+
SourceRange diagnostic(Diagnostic diagnostic) =>
101+
SourceRange(diagnostic.offset, diagnostic.length);
102+
98103
/// Return a source range that starts at the end of [leftEntity] and ends at
99104
/// the end of [rightEntity].
100105
SourceRange endEnd(SyntacticEntity leftEntity, SyntacticEntity rightEntity) {
@@ -123,12 +128,8 @@ class RangeFactory {
123128
return SourceRange(node.offset, node.length);
124129
}
125130

126-
/// Returns a source range that covers the same range as the given
127-
/// [diagnostic].
128-
// TODO(srawlins): Rename to 'diagnostic'.
129-
SourceRange error(Diagnostic diagnostic) {
130-
return SourceRange(diagnostic.offset, diagnostic.length);
131-
}
131+
@Deprecated("Use 'diagnostic' instead")
132+
SourceRange error(Diagnostic d) => diagnostic(d);
132133

133134
/// Returns a source range that covers the name of the given [fragment].
134135
///

pkg/analyzer_plugin/test/utilities/range_factory_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ const class B {}
538538
''');
539539
var result = await resolveFile(testFile);
540540
var diagnostic = result.diagnostics.single;
541-
expect(range.error(diagnostic), SourceRange(11, 5));
541+
expect(range.diagnostic(diagnostic), SourceRange(11, 5));
542542
}
543543

544544
Future<void> test_node() async {

0 commit comments

Comments
 (0)