@@ -15,12 +15,10 @@ import 'package:analysis_server_plugin/src/utilities/selection.dart';
1515import 'package:analyzer/dart/analysis/results.dart' ;
1616import 'package:analyzer/dart/ast/ast.dart' ;
1717import 'package:analyzer/dart/ast/token.dart' ;
18- import 'package:analyzer/dart/element/element.dart' ;
1918import 'package:analyzer/dart/element/element2.dart' ;
2019import 'package:analyzer/src/dart/analysis/session_helper.dart' ;
2120import 'package:analyzer/src/dart/ast/extensions.dart' ;
2221import 'package:analyzer/src/utilities/extensions/collection.dart' ;
23- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2422import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
2523import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart' ;
2624import 'package:analyzer_plugin/utilities/range_factory.dart' ;
@@ -110,7 +108,7 @@ final class FormalParameterState {
110108 final int id;
111109
112110 /// The element, used internally for `super` conversion.
113- final ParameterElement element;
111+ final FormalParameterElement element;
114112
115113 /// The current kind of the formal parameter.
116114 final FormalParameterKind kind;
@@ -244,7 +242,7 @@ final class ValidSelectionState extends SelectionState {
244242
245243 /// The element of the target method, used to find corresponding methods
246244 /// in the class hierarchy.
247- final ExecutableElement element;
245+ final ExecutableElement2 element;
248246
249247 /// The current formal parameters.
250248 final List <FormalParameterState > formalParameters;
@@ -254,10 +252,6 @@ final class ValidSelectionState extends SelectionState {
254252 required this .element,
255253 required this .formalParameters,
256254 });
257-
258- /// The element of the target method, used to find corresponding methods
259- /// in the class hierarchy.
260- ExecutableElement2 get element2 => element.asElement2;
261255}
262256
263257class _AvailabilityAnalyzer {
@@ -306,8 +300,8 @@ class _AvailabilityAnalyzer {
306300 }
307301
308302 _Declaration ? buildDeclaration (Declaration node) {
309- var element = node.declaredElement ;
310- if (element is ExecutableElement ) {
303+ var element = node.declaredFragment ? .element ;
304+ if (element is ExecutableElement2 ) {
311305 return _Declaration (element: element, node: node, selected: selected);
312306 }
313307 return null ;
@@ -379,20 +373,20 @@ class _AvailabilityAnalyzer {
379373 Availability _executableElement () {
380374 var coveringNode = refactoringContext.coveringNode;
381375
382- Element ? element;
376+ Element2 ? element;
383377 if (coveringNode is SimpleIdentifier ) {
384378 var invocation = coveringNode.parent;
385379 if (invocation is MethodInvocation &&
386380 invocation.methodName == coveringNode) {
387- element = invocation.methodName.staticElement ;
381+ element = invocation.methodName.element ;
388382 }
389383 }
390384
391- if (element is ! ExecutableElement ) {
385+ if (element is ! ExecutableElement2 ) {
392386 return NotAvailableNoExecutableElement ();
393387 }
394388
395- var libraryFilePath = element.librarySource .fullName;
389+ var libraryFilePath = element.library2.firstFragment.source .fullName;
396390 if (! refactoringContext.workspace.containsFile (libraryFilePath)) {
397391 return NotAvailableExternalElement ();
398392 }
@@ -414,7 +408,7 @@ final class _AvailableWithDeclaration extends Available {
414408
415409 @override
416410 bool get hasPositionalParameters {
417- return declaration.element.parameters .any ((e) => e.isPositional);
411+ return declaration.element.formalParameters .any ((e) => e.isPositional);
418412 }
419413
420414 @override
@@ -479,7 +473,7 @@ final class _AvailableWithDeclaration extends Available {
479473}
480474
481475final class _AvailableWithExecutableElement extends Available {
482- final ExecutableElement element;
476+ final ExecutableElement2 element;
483477
484478 _AvailableWithExecutableElement ({
485479 required super .refactoringContext,
@@ -488,13 +482,13 @@ final class _AvailableWithExecutableElement extends Available {
488482
489483 @override
490484 bool get hasPositionalParameters {
491- return element.parameters .any ((e) => e.isPositional);
485+ return element.formalParameters .any ((e) => e.isPositional);
492486 }
493487}
494488
495489/// The target method declaration.
496490class _Declaration {
497- final ExecutableElement element;
491+ final ExecutableElement2 element;
498492 final AstNode node;
499493 final List <FormalParameter > selected;
500494
@@ -557,7 +551,7 @@ class _SelectionAnalyzer {
557551 return const UnexpectedSelectionState ();
558552 }
559553
560- var parameterElement = parameterNode.declaredElement ;
554+ var parameterElement = parameterNode.declaredFragment ? .element ;
561555 if (parameterElement == null ) {
562556 return const UnexpectedSelectionState ();
563557 }
@@ -599,9 +593,9 @@ class _SelectionAnalyzer {
599593 }
600594 }
601595
602- Future <AstNode ?> _elementDeclaration (ExecutableElement element) async {
596+ Future <AstNode ?> _elementDeclaration (ExecutableElement2 element) async {
603597 var helper = refactoringContext.sessionHelper;
604- var nodeResult = await helper.getElementDeclaration (element);
598+ var nodeResult = await helper.getElementDeclaration2 (element.firstFragment );
605599 return nodeResult? .node;
606600 }
607601}
@@ -659,27 +653,27 @@ class _SignatureUpdater {
659653 /// a function, only the elements itself has to be updated. If the target
660654 /// is a class method, then every element in this class hierarchy should
661655 /// be updated.
662- Future <List <ExecutableElement >> computeElements () async {
656+ Future <List <ExecutableElement2 >> computeElements () async {
663657 var element = selectionState.element;
664- if (element case ClassMemberElement member) {
665- var set = await getHierarchyMembers (searchEngine, member.asElement2! );
666- return set
667- .whereType <ExecutableElement2 >()
668- .map ((e) => e.asElement)
669- .toList ();
658+ switch (element) {
659+ case ConstructorElement2 ():
660+ case MethodElement2 ():
661+ var set = await getHierarchyMembers (searchEngine, element);
662+ return set .whereType <ExecutableElement2 >().toList ();
663+ default :
664+ return [element];
670665 }
671- return [element];
672666 }
673667
674- /// Returns the [MethodDeclaration] for a [MethodElement ] .
675- Future <AstNode ?> elementDeclaration (ExecutableElement element) async {
668+ /// Returns the [MethodDeclaration] for a [MethodElement2 ] .
669+ Future <AstNode ?> elementDeclaration (ExecutableElement2 element) async {
676670 var helper = sessionHelper;
677- var result = await helper.getElementDeclaration (element);
671+ var result = await helper.getElementDeclaration2 (element.firstFragment );
678672 return result? .node;
679673 }
680674
681675 /// Returns the [Selection] for the [reference] , using the resolved unit.
682- /// Used to find [MethodInvocation] s of a [MethodElement ] .
676+ /// Used to find [MethodInvocation] s of a [MethodElement2 ] .
683677 Future <Selection ?> referenceSelection (SearchMatch reference) async {
684678 var unitResult = await referenceUnitResult (reference);
685679 return unitResult? .unit.select (
@@ -690,8 +684,8 @@ class _SignatureUpdater {
690684
691685 /// Returns the resolved unit with [reference] .
692686 Future <ResolvedUnitResult ?> referenceUnitResult (SearchMatch reference) async {
693- var element = reference.element2.asElement ! ;
694- return await sessionHelper.getResolvedUnitByElement (element);
687+ var element = reference.element2;
688+ return await sessionHelper.getResolvedUnitByElement2 (element);
695689 }
696690
697691 /// Replaces [argumentList] with new code that has arguments as requested
@@ -746,12 +740,12 @@ class _SignatureUpdater {
746740 /// Replaces formal parameters of [element] with new code as requested
747741 /// by the formal parameter updates, reordering, changing kind, etc.
748742 Future <ChangeStatus > updateDeclaration ({
749- required ExecutableElement element,
743+ required ExecutableElement2 element,
750744 required ChangeBuilder builder,
751745 }) async {
752- var path = element.source.fullName;
746+ var path = element.firstFragment.libraryFragment. source.fullName;
753747
754- var unitResult = await sessionHelper.getResolvedUnitByElement (element);
748+ var unitResult = await sessionHelper.getResolvedUnitByElement2 (element);
755749 if (unitResult == null ) {
756750 return ChangeStatusFailure ();
757751 }
@@ -967,10 +961,10 @@ class _SignatureUpdater {
967961
968962 /// Updates arguments of invocations of [element] .
969963 Future <ChangeStatus > updateReferences ({
970- required ExecutableElement element,
964+ required ExecutableElement2 element,
971965 required ChangeBuilder builder,
972966 }) async {
973- var references = await searchEngine.searchReferences (element.asElement2 );
967+ var references = await searchEngine.searchReferences (element);
974968 for (var reference in references) {
975969 var unitResult = await referenceUnitResult (reference);
976970 if (unitResult == null ) {
@@ -1144,7 +1138,7 @@ class _SignatureUpdater {
11441138 return ChangeStatusSuccess ();
11451139 }
11461140
1147- var parameterElementsToSuper = < ParameterElement > {};
1141+ var parameterElementsToSuper = < FormalParameterElement > {};
11481142 for (var update in signatureUpdate.formalParameters) {
11491143 if (update.kind.isNamed) {
11501144 var existing = selectionState.formalParameters[update.id];
@@ -1154,8 +1148,8 @@ class _SignatureUpdater {
11541148 continue ;
11551149 }
11561150
1157- var parameterElement = argument.staticElement ;
1158- if (parameterElement is ! ParameterElement ) {
1151+ var parameterElement = argument.element ;
1152+ if (parameterElement is ! FormalParameterElement ) {
11591153 continue ;
11601154 }
11611155
0 commit comments