Skip to content

Commit b5e12ec

Browse files
bwilkersonCommit Queue
authored andcommitted
Replace use of NodeLocator2 in CorrectionProducer
This is the last use of NodeLocator2 outside of the analyzer package itself that I'm aware of (at least in our code base). Change-Id: I57ba74571d60e820c60e2ca3d8d17e9374597073 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431440 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 797b076 commit b5e12ec

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class AddExplicitCast extends ResolvedCorrectionProducer {
126126
({Expression target, DartType fromType, DartType toType})?
127127
_computeTargetAndTypes() {
128128
var target = coveringNode;
129-
if (target is! Expression) {
129+
if (target is! Expression || target.endToken.isSynthetic) {
130130
return null;
131131
}
132132

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:math' as math;
6-
75
import 'package:analysis_server_plugin/edit/correction_utils.dart';
86
import 'package:analysis_server_plugin/edit/fix/dart_fix_context.dart';
97
import 'package:analysis_server_plugin/src/utilities/selection.dart';
@@ -22,7 +20,6 @@ import 'package:analyzer/file_system/file_system.dart';
2220
import 'package:analyzer/source/source_range.dart';
2321
import 'package:analyzer/src/dart/analysis/session_helper.dart';
2422
import 'package:analyzer/src/dart/ast/ast.dart';
25-
import 'package:analyzer/src/dart/ast/utilities.dart';
2623
import 'package:analyzer/src/dart/element/element.dart';
2724
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
2825
import 'package:analyzer/src/dart/element/type.dart';
@@ -171,9 +168,8 @@ sealed class CorrectionProducer<T extends ParsedUnitResult>
171168
}
172169
var errorOffset = diagnostic.problemMessage.offset;
173170
var errorLength = diagnostic.problemMessage.length;
174-
var endOffset = math.max(errorOffset + errorLength - 1, 0);
175171
return _coveringNode =
176-
NodeLocator2(errorOffset, endOffset).searchWithin(unit);
172+
unit.nodeCovering(offset: errorOffset, length: errorLength);
177173
}
178174

179175
/// The length of the source range associated with the error message being

0 commit comments

Comments
 (0)