File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed
services/refactoring/legacy
analyzer_plugin/lib/src/utilities/change_builder Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import 'package:analyzer/dart/ast/ast.dart';
1111import 'package:analyzer/dart/element/element.dart' ;
1212import 'package:analyzer/source/source_range.dart' ;
1313import 'package:analyzer/src/dart/analysis/session_helper.dart' ;
14- import 'package:analyzer/src/dart/ast/utilities.dart' ;
1514import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
1615
1716/// Handles textDocument/colorPresentation.
@@ -232,7 +231,7 @@ class DocumentColorPresentationHandler
232231 /// `const` should be inserted if the existing expression is constant but
233232 /// we are not already in a constant context.
234233 bool _willRequireConstKeyword (int offset, ResolvedUnitResult unit) {
235- var node = NodeLocator2 (offset). searchWithin ( unit.unit);
234+ var node = unit.unit. nodeCovering (offset : offset );
236235 if (node is ! Expression ) {
237236 return false ;
238237 }
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ import 'package:analyzer/source/source_range.dart';
3030import 'package:analyzer/src/dart/analysis/session_helper.dart' ;
3131import 'package:analyzer/src/dart/ast/ast.dart' ;
3232import 'package:analyzer/src/dart/ast/extensions.dart' ;
33- import 'package:analyzer/src/dart/ast/utilities.dart' ;
3433import 'package:analyzer/src/dart/resolver/exit_detector.dart' ;
3534import 'package:analyzer/src/generated/java_core.dart' ;
3635import 'package:analyzer/src/utilities/extensions/ast.dart' ;
@@ -785,7 +784,7 @@ final class ExtractMethodRefactoringImpl extends RefactoringImpl
785784 return null ;
786785 }
787786 var offset = _selectionRange.offset;
788- var node = NodeLocator2 (offset, offset). searchWithin (_resolveResult.unit );
787+ var node = _resolveResult.unit. nodeCovering (offset: offset);
789788
790789 // Check for the parameter list of a FunctionExpression.
791790 {
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import 'package:analyzer/dart/element/type_provider.dart';
1313import 'package:analyzer/dart/element/type_system.dart' ;
1414import 'package:analyzer/source/line_info.dart' ;
1515import 'package:analyzer/source/source_range.dart' ;
16- import 'package:analyzer/src/dart/ast/utilities.dart' ;
1716import 'package:analyzer/src/dart/element/type.dart' ;
1817import 'package:analyzer/src/services/top_level_declarations.dart' ;
1918import 'package:analyzer_plugin/protocol/protocol_common.dart'
@@ -2684,8 +2683,13 @@ class _EnclosingElementFinder {
26842683
26852684 _EnclosingElementFinder ();
26862685
2687- void find (AstNode ? target, int offset) {
2688- var node = NodeLocator2 (offset).searchWithin (target);
2686+ void find (CompilationUnit target, int offset) {
2687+ var node = target.nodeCovering (offset: offset);
2688+ if (node != null && offset == node.end) {
2689+ // If the offset is just outside the node, then the element declared by
2690+ // the node isn't actually enclosing the offset.
2691+ node = node.parent;
2692+ }
26892693 while (node != null ) {
26902694 if (node is ClassDeclaration ) {
26912695 enclosingClass = node.declaredFragment? .element;
You can’t perform that action at this time.
0 commit comments