Skip to content

Commit b0e12e5

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Migrate many uses of NodeLocator to nodeCovering
Change-Id: I97d4137c2daaa562332a83eec4e11208bb008c38 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423081 Auto-Submit: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 918b58a commit b0e12e5

13 files changed

+36
-35
lines changed

pkg/analysis_server/lib/src/analysis_server.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ import 'package:analyzer/src/dart/analysis/session.dart';
7575
import 'package:analyzer/src/dart/analysis/status.dart' as analysis;
7676
import 'package:analyzer/src/dart/analysis/unlinked_unit_store.dart';
7777
import 'package:analyzer/src/dart/ast/element_locator.dart';
78-
import 'package:analyzer/src/dart/ast/utilities.dart';
7978
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
8079
import 'package:analyzer/src/generated/sdk.dart';
8180
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
8281
import 'package:analyzer/src/util/performance/operation_performance.dart';
8382
import 'package:analyzer/src/utilities/extensions/analysis_session.dart';
8483
import 'package:analyzer/src/utilities/extensions/element.dart';
84+
import 'package:analyzer/utilities/extensions/ast.dart';
8585
import 'package:analyzer_plugin/protocol/protocol.dart';
8686
import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'
8787
as analyzer_plugin;
@@ -740,7 +740,7 @@ abstract class AnalysisServer {
740740
var result = await getResolvedUnit(file);
741741
var unit = result?.unit;
742742
if (unit != null) {
743-
return NodeLocator(offset).searchWithin(unit);
743+
return unit.nodeCovering(offset: offset);
744744
}
745745
return null;
746746
}

pkg/analysis_server/lib/src/cider/rename.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:analyzer/src/generated/java_core.dart';
1919
import 'package:analyzer/src/utilities/extensions/collection.dart';
2020
import 'package:analyzer/src/utilities/extensions/element.dart';
2121
import 'package:analyzer/src/utilities/extensions/flutter.dart';
22+
import 'package:analyzer/utilities/extensions/ast.dart';
2223

2324
class CanRenameResponse {
2425
final LineInfo lineInfo;
@@ -349,9 +350,9 @@ class CheckNameResponse {
349350
) async {
350351
var resolvedUnit = await canRename._fileResolver.resolve(path: path);
351352
var lineInfo = resolvedUnit.lineInfo;
352-
var node = NodeLocator(
353-
lineInfo.getOffsetOfLine(loc.lineNumber - 1) + loc.columnNumber,
354-
).searchWithin(resolvedUnit.unit);
353+
var node = resolvedUnit.unit.nodeCovering(
354+
offset: lineInfo.getOffsetOfLine(loc.lineNumber - 1) + loc.columnNumber,
355+
);
355356
if (node is SimpleIdentifier) {
356357
var parent = node.parent;
357358
if (parent is InterpolationExpression && parent.rightBracket == null) {

pkg/analysis_server/lib/src/computer/computer_call_hierarchy.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import 'package:analyzer/dart/ast/visitor.dart';
1010
import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/source/source_range.dart';
1212
import 'package:analyzer/src/dart/ast/element_locator.dart';
13-
import 'package:analyzer/src/dart/ast/utilities.dart';
1413
import 'package:analyzer/src/dart/element/element.dart';
14+
import 'package:analyzer/utilities/extensions/ast.dart';
1515

1616
/// Returns the container for [element] that should be used in Call Hierarchy.
1717
///
@@ -330,7 +330,7 @@ class DartCallHierarchyComputer {
330330

331331
/// Finds a target node for call hierarchy navigation at [offset].
332332
AstNode? _findTargetNode(int offset) {
333-
var node = NodeLocator(offset).searchWithin(_result.unit);
333+
var node = _result.unit.nodeCovering(offset: offset);
334334
if (node is SimpleIdentifier &&
335335
node.parent != null &&
336336
node.parent is! VariableDeclaration &&
@@ -436,7 +436,7 @@ class DartCallHierarchyComputer {
436436
);
437437

438438
if (result is ParsedUnitResult) {
439-
var node = NodeLocator(offset).searchWithin(result.unit);
439+
var node = result.unit.nodeCovering(offset: offset);
440440
if (node != null && !node.isSynthetic) {
441441
var parent = node.parent;
442442
// Handle named constructors which have their `.` included in the

pkg/analysis_server/lib/src/computer/computer_hover.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import 'package:analyzer/dart/ast/syntactic_entity.dart';
1010
import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/dart/element/type.dart';
1212
import 'package:analyzer/src/dart/ast/element_locator.dart';
13-
import 'package:analyzer/src/dart/ast/utilities.dart';
1413
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
14+
import 'package:analyzer/utilities/extensions/ast.dart';
1515
import 'package:path/path.dart' as path;
1616

1717
/// Information about a library to display in a hover.
@@ -35,7 +35,7 @@ class DartUnitHoverComputer {
3535

3636
/// Returns the computed hover, maybe `null`.
3737
HoverInformation? compute() {
38-
var node = NodeLocator(_offset).searchWithin(_unit);
38+
var node = _unit.nodeCovering(offset: _offset);
3939
if (node == null) {
4040
return null;
4141
}

pkg/analysis_server/lib/src/computer/computer_selection_ranges.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/ast.dart';
6-
import 'package:analyzer/src/dart/ast/utilities.dart';
6+
import 'package:analyzer/utilities/extensions/ast.dart';
77

88
/// Computes selection ranges for a specific offset of a Dart [CompilationUnit].
99
///
@@ -19,7 +19,7 @@ class DartSelectionRangeComputer {
1919
/// Returns selection ranges for nodes containing [_offset], starting with the
2020
/// closest working up to the outer-most node.
2121
List<SelectionRange> compute() {
22-
var node = NodeLocator(_offset).searchWithin(_unit);
22+
var node = _unit.nodeCovering(offset: _offset);
2323
if (node == null) {
2424
return [];
2525
}

pkg/analysis_server/lib/src/computer/computer_type_arguments_signature.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'package:analysis_server/src/lsp/mapping.dart';
99
import 'package:analyzer/dart/ast/ast.dart';
1010
import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/src/dart/ast/element_locator.dart';
12-
import 'package:analyzer/src/dart/ast/utilities.dart';
1312
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
13+
import 'package:analyzer/utilities/extensions/ast.dart';
1414

1515
/// A computer for the signature help information about the type parameters for
1616
/// the [TypeArgumentList] surrounding the specified offset of a Dart
@@ -29,7 +29,7 @@ class DartTypeArgumentsSignatureComputer {
2929
this.preferredFormats, {
3030
this.documentationPreference = DocumentationPreference.full,
3131
}) : _documentationComputer = DartDocumentationComputer(dartdocInfo),
32-
_node = NodeLocator(offset).searchWithin(unit);
32+
_node = unit.nodeCovering(offset: offset);
3333

3434
/// The [TypeArgumentList] node located by [compute].
3535
TypeArgumentList get argumentList => _argumentList;

pkg/analysis_server/lib/src/handler/legacy/edit_get_available_refactorings.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:analysis_server/protocol/protocol_generated.dart';
88
import 'package:analysis_server/src/handler/legacy/legacy_handler.dart';
99
import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart';
1010
import 'package:analyzer/dart/element/element2.dart';
11-
import 'package:analyzer/src/dart/ast/utilities.dart';
11+
import 'package:analyzer/utilities/extensions/ast.dart';
1212
import 'package:analyzer_plugin/protocol/protocol_common.dart';
1313

1414
/// The handler for the `edit.getAvailableRefactorings` request.
@@ -74,7 +74,7 @@ class EditGetAvailableRefactoringsHandler extends LegacyHandler {
7474
// check elements
7575
var resolvedUnit = await server.getResolvedUnit(file);
7676
if (resolvedUnit != null) {
77-
var node = NodeLocator(offset).searchWithin(resolvedUnit.unit);
77+
var node = resolvedUnit.unit.nodeCovering(offset: offset);
7878
var element = server.getElementOfNode(node);
7979
if (element != null) {
8080
var refactoringWorkspace = server.refactoringWorkspace;

pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import 'package:analyzer/dart/analysis/results.dart';
2626
import 'package:analyzer/dart/analysis/session.dart'
2727
show InconsistentAnalysisException;
2828
import 'package:analyzer/dart/element/element2.dart';
29-
import 'package:analyzer/src/dart/ast/utilities.dart';
3029
import 'package:analyzer/src/util/performance/operation_performance.dart';
30+
import 'package:analyzer/utilities/extensions/ast.dart';
3131

3232
/// Produces [CodeAction]s from Dart source commands, fixes, assists and
3333
/// refactors from the server.
@@ -400,7 +400,7 @@ class DartCodeActionsProducer extends AbstractCodeActionsProducer {
400400
if (shouldIncludeKind(CodeActionKind.RefactorRewrite)) {
401401
timer.restart();
402402

403-
var node = NodeLocator(offset).searchWithin(unitResult.unit);
403+
var node = unitResult.unit.nodeCovering(offset: offset);
404404
var element = server.getElementOfNode(node);
405405

406406
// Getter to Method

pkg/analysis_server/lib/src/lsp/handlers/commands/abstract_refactor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:analysis_server/src/protocol_server.dart';
1515
import 'package:analysis_server/src/services/refactoring/legacy/refactoring.dart';
1616
import 'package:analyzer/dart/analysis/results.dart';
1717
import 'package:analyzer/dart/element/element2.dart';
18-
import 'package:analyzer/src/dart/ast/utilities.dart';
18+
import 'package:analyzer/utilities/extensions/ast.dart';
1919

2020
final _manager = LspRefactorManager._();
2121

@@ -125,7 +125,7 @@ abstract class AbstractRefactorCommandHandler extends SimpleEditCommandHandler
125125
return success(refactor);
126126

127127
case RefactoringKind.CONVERT_GETTER_TO_METHOD:
128-
var node = NodeLocator(offset).searchWithin(result.unit);
128+
var node = result.unit.nodeCovering(offset: offset);
129129
var element = server.getElementOfNode(node);
130130
if (element is GetterElement) {
131131
var refactor = ConvertGetterToMethodRefactoring(
@@ -141,7 +141,7 @@ abstract class AbstractRefactorCommandHandler extends SimpleEditCommandHandler
141141
);
142142

143143
case RefactoringKind.CONVERT_METHOD_TO_GETTER:
144-
var node = NodeLocator(offset).searchWithin(result.unit);
144+
var node = result.unit.nodeCovering(offset: offset);
145145
var element = server.getElementOfNode(node);
146146
if (element is ExecutableElement2) {
147147
var refactor = ConvertMethodToGetterRefactoring(

pkg/analysis_server/lib/src/lsp/handlers/handler_implementation.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import 'package:analysis_server/src/lsp/registration/feature_registration.dart';
1111
import 'package:analysis_server/src/search/type_hierarchy.dart';
1212
import 'package:analyzer/dart/analysis/results.dart';
1313
import 'package:analyzer/dart/element/element2.dart';
14-
import 'package:analyzer/src/dart/ast/utilities.dart';
1514
import 'package:analyzer/src/util/performance/operation_performance.dart';
15+
import 'package:analyzer/utilities/extensions/ast.dart';
1616

1717
typedef StaticOptions =
1818
Either3<bool, ImplementationOptions, ImplementationRegistrationOptions>;
@@ -62,7 +62,7 @@ class ImplementationHandler
6262
CancellationToken token,
6363
OperationPerformanceImpl performance,
6464
) async {
65-
var node = NodeLocator(offset).searchWithin(result.unit);
65+
var node = result.unit.nodeCovering(offset: offset);
6666
var element = server.getElementOfNode(node);
6767
if (element == null) {
6868
return success([]);

0 commit comments

Comments
 (0)