Skip to content

Commit 91e6829

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Move coveringNode to public API
NodeLocator and NodeLocator2 are being deprecated in favor of this extension method. We move it to the public API here and start using it in the analysis_server_plugin package. Change-Id: I4783bb1f511b798e52b3383dd600b154dccc6d5b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420420 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 8c5e062 commit 91e6829

File tree

16 files changed

+93
-83
lines changed

16 files changed

+93
-83
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:analyzer/dart/element/element2.dart' hide ElementLocation;
1313
import 'package:analyzer/dart/element/type.dart';
1414
import 'package:analyzer/source/source_range.dart';
1515
import 'package:analyzer/src/dart/element/element.dart';
16-
import 'package:analyzer/src/utilities/extensions/ast.dart';
16+
import 'package:analyzer/utilities/extensions/ast.dart';
1717

1818
/// A lazy computer for Type Hierarchies.
1919
///

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/src/dart/ast/element_locator.dart';
1212
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
13-
import 'package:analyzer/src/utilities/extensions/ast.dart';
13+
import 'package:analyzer/utilities/extensions/ast.dart';
1414

1515
/// A computer for the signature at the specified offset of a Dart
1616
/// [CompilationUnit].

pkg/analysis_server/lib/src/lsp/handlers/custom/editable_arguments/editable_arguments_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'package:analyzer/dart/element/element2.dart';
99
import 'package:analyzer/src/dart/ast/ast.dart';
1010
import 'package:analyzer/src/dart/element/element.dart';
1111
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
12-
import 'package:analyzer/src/utilities/extensions/ast.dart';
1312
import 'package:analyzer/src/utilities/extensions/flutter.dart';
13+
import 'package:analyzer/utilities/extensions/ast.dart';
1414

1515
/// Information about the arguments and parameters for an invocation.
1616
typedef EditableInvocationInfo =

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_augmentation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:analysis_server/src/lsp/error_or.dart';
88
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
99
import 'package:analysis_server/src/lsp/mapping.dart';
1010
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
11-
import 'package:analyzer/src/utilities/extensions/ast.dart';
11+
import 'package:analyzer/utilities/extensions/ast.dart';
1212

1313
class AugmentationHandler
1414
extends SharedMessageHandler<TextDocumentPositionParams, Location?> {

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_augmented.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:analysis_server/src/lsp/error_or.dart';
88
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
99
import 'package:analysis_server/src/lsp/mapping.dart';
1010
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
11-
import 'package:analyzer/src/utilities/extensions/ast.dart';
11+
import 'package:analyzer/utilities/extensions/ast.dart';
1212

1313
class AugmentedHandler
1414
extends SharedMessageHandler<TextDocumentPositionParams, Location?> {

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_imports.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import 'package:analyzer/dart/analysis/results.dart';
1212
import 'package:analyzer/dart/element/element2.dart';
1313
import 'package:analyzer/src/dart/ast/ast.dart';
1414
import 'package:analyzer/src/dart/ast/element_locator.dart';
15-
import 'package:analyzer/src/utilities/extensions/ast.dart';
1615
import 'package:analyzer/src/utilities/extensions/results.dart';
16+
import 'package:analyzer/utilities/extensions/ast.dart';
1717

1818
class ImportsHandler
1919
extends SharedMessageHandler<TextDocumentPositionParams, List<Location>?> {

pkg/analysis_server/lib/src/lsp/handlers/custom/handler_super.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:analyzer/dart/ast/ast.dart';
1111
import 'package:analyzer/dart/element/element2.dart';
1212
import 'package:analyzer/src/dart/analysis/session.dart';
1313
import 'package:analyzer/src/dart/ast/element_locator.dart';
14-
import 'package:analyzer/src/utilities/extensions/ast.dart';
14+
import 'package:analyzer/utilities/extensions/ast.dart';
1515

1616
class SuperHandler
1717
extends SharedMessageHandler<TextDocumentPositionParams, Location?> {

pkg/analysis_server/lib/src/services/flutter/widget_descriptions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import 'package:analyzer/dart/element/element2.dart';
1111
import 'package:analyzer/dart/element/type.dart';
1212
import 'package:analyzer/src/dart/analysis/session_helper.dart';
1313
import 'package:analyzer/src/dart/ast/extensions.dart';
14-
import 'package:analyzer/src/utilities/extensions/ast.dart';
1514
import 'package:analyzer/src/utilities/extensions/flutter.dart';
15+
import 'package:analyzer/utilities/extensions/ast.dart';
1616
import 'package:dart_style/dart_style.dart';
1717

1818
/// The result of [WidgetDescriptions.setPropertyValue] invocation.

pkg/analysis_server_plugin/lib/edit/correction_utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import 'package:analyzer/source/source.dart';
1212
import 'package:analyzer/source/source_range.dart';
1313
import 'package:analyzer/src/dart/ast/ast.dart';
1414
import 'package:analyzer/src/dart/ast/extensions.dart';
15-
import 'package:analyzer/src/dart/ast/utilities.dart';
1615
import 'package:analyzer/src/dart/scanner/reader.dart';
1716
import 'package:analyzer/src/dart/scanner/scanner.dart';
1817
import 'package:analyzer/src/utilities/extensions/string.dart';
18+
import 'package:analyzer/utilities/extensions/ast.dart';
1919
import 'package:analyzer_plugin/src/utilities/string_utilities.dart';
2020
import 'package:analyzer_plugin/utilities/range_factory.dart';
2121

@@ -57,7 +57,7 @@ final class CorrectionUtils {
5757
String get twoIndents => _twoIndents;
5858

5959
/// Returns the [AstNode] that encloses the given [offset].
60-
AstNode? findNode(int offset) => NodeLocator(offset).searchWithin(_unit);
60+
AstNode? findNode(int offset) => _unit.nodeCovering(offset: offset);
6161

6262
/// Skips whitespace characters and single EOL on the right from [index].
6363
///

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'package:analyzer/src/dart/element/element.dart';
2727
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
2828
import 'package:analyzer/src/dart/element/type.dart';
2929
import 'package:analyzer/src/utilities/extensions/ast.dart';
30+
import 'package:analyzer/utilities/extensions/ast.dart';
3031
import 'package:analyzer_plugin/utilities/assist/assist.dart';
3132
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
3233
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
@@ -294,9 +295,8 @@ final class CorrectionProducerContext {
294295
int selectionOffset = -1,
295296
int selectionLength = 0,
296297
}) {
297-
var selectionEnd = selectionOffset + selectionLength;
298-
var locator = NodeLocator(selectionOffset, selectionEnd);
299-
var node = locator.searchWithin(unitResult.unit);
298+
var node = unitResult.unit
299+
.nodeCovering(offset: selectionOffset, length: selectionLength);
300300
node ??= unitResult.unit;
301301

302302
var token = _tokenAt(node, selectionOffset) ?? node.beginToken;

0 commit comments

Comments
 (0)