Convert RefactoringProducer to use coveringNode

Change-Id: Iab2296aeba88085b1ec97afd755e03d4bf8de002
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264062
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2022-10-18 21:05:26 +00:00 committed by Commit Queue
parent d7852e4786
commit 3785d6f59a
2 changed files with 9 additions and 4 deletions

View file

@ -7,7 +7,9 @@ import 'package:analysis_server/src/services/correction/change_workspace.dart';
import 'package:analysis_server/src/services/correction/util.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/dart/analysis/session_helper.dart';
import 'package:analyzer/src/utilities/extensions/ast.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_workspace.dart';
/// The context in which a refactoring was requested.
@ -27,6 +29,10 @@ class RefactoringContext {
/// Utilities available to be used in the process of computing the edits.
late final CorrectionUtils utils = CorrectionUtils(resolvedResult);
/// The node that was selected, or `null` if the selection is not valid.
late final AstNode? selectedNode = resolvedResult.unit
.nodeCovering(offset: selectionOffset, length: selectionLength);
/// The helper used to efficiently access resolved units.
late final AnalysisSessionHelper sessionHelper =
AnalysisSessionHelper(session);

View file

@ -10,7 +10,6 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/src/dart/analysis/session_helper.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
/// An object that can compute a refactoring in a Dart file.
@ -35,9 +34,9 @@ abstract class RefactoringProducer {
/// invoked.
ResolvedUnitResult get result => _context.resolvedResult;
/// Return the node that was selected.
AstNode? get selectedNode =>
NodeLocator2(selectionOffset, selectionEnd).searchWithin(result.unit);
/// Return the node that was selected, or `null` if the selection is not
/// valid.
AstNode? get selectedNode => _context.selectedNode;
/// Return the offset of the first character after the selection range.
int get selectionEnd => selectionOffset + selectionLength;