@@ -14,17 +14,16 @@ import 'package:analysis_server/src/services/search/hierarchy.dart';
1414import 'package:analyzer/dart/ast/ast.dart' ;
1515import 'package:analyzer/dart/ast/token.dart' ;
1616import 'package:analyzer/dart/ast/visitor.dart' ;
17- import 'package:analyzer/dart/element/element .dart' ;
17+ import 'package:analyzer/dart/element/element2 .dart' ;
1818import 'package:analyzer/source/source_range.dart' ;
1919import 'package:analyzer/src/dart/element/element.dart' ;
20- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2120
2221class ConflictValidatorVisitor extends RecursiveAstVisitor <void > {
2322 final RefactoringStatus result;
2423 final String newName;
25- final LocalElement target;
26- final Map <Element , SourceRange > visibleRangeMap;
27- final Set <Element > conflictingLocals = < Element > {};
24+ final LocalElement2 target;
25+ final Map <Element2 , SourceRange > visibleRangeMap;
26+ final Set <Element2 > conflictingLocals = < Element2 > {};
2827
2928 ConflictValidatorVisitor (
3029 this .result,
@@ -36,7 +35,7 @@ class ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
3635 @override
3736 void visitFunctionDeclaration (FunctionDeclaration node) {
3837 _checkDeclaration (
39- declaredElement: node.declaredElement ! ,
38+ declaredElement: node.declaredFragment ! .element ,
4039 nameToken: node.name,
4140 );
4241
@@ -45,8 +44,8 @@ class ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
4544
4645 @override
4746 void visitSimpleIdentifier (SimpleIdentifier node) {
48- var nodeElement = node.staticElement ;
49- if (nodeElement != null && nodeElement.name == newName) {
47+ var nodeElement = node.element ;
48+ if (nodeElement != null && nodeElement.name3 == newName) {
5049 if (conflictingLocals.contains (nodeElement)) {
5150 return ;
5251 }
@@ -56,11 +55,11 @@ class ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
5655 targetRange.contains (node.offset) &&
5756 ! node.isQualified &&
5857 ! _isNamedExpressionName (node)) {
59- nodeElement =
60- getSyntheticAccessorVariable (nodeElement.asElement2! ).asElement! ;
58+ nodeElement = getSyntheticAccessorVariable (nodeElement);
6159 var nodeKind = nodeElement.kind.displayName;
62- var nodeName = getElementQualifiedName (nodeElement.asElement2! );
63- var nameElementSourceName = nodeElement.source! .shortName;
60+ var nodeName = getElementQualifiedName (nodeElement);
61+ var nameElementSourceName =
62+ nodeElement.firstFragment.libraryFragment! .source.shortName;
6463 var refKind = target.kind.displayName;
6564 var message =
6665 'Usage of $nodeKind "$nodeName " declared in '
@@ -73,15 +72,15 @@ class ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
7372 @override
7473 void visitVariableDeclaration (VariableDeclaration node) {
7574 _checkDeclaration (
76- declaredElement: node.declaredElement ! ,
75+ declaredElement: node.declaredFragment ! .element ,
7776 nameToken: node.name,
7877 );
7978
8079 super .visitVariableDeclaration (node);
8180 }
8281
8382 void _checkDeclaration ({
84- required Element ? declaredElement,
83+ required Element2 ? declaredElement,
8584 required Token nameToken,
8685 }) {
8786 if (declaredElement != null && nameToken.lexeme == newName) {
@@ -90,19 +89,19 @@ class ConflictValidatorVisitor extends RecursiveAstVisitor<void> {
9089 conflictingLocals.add (declaredElement);
9190 var nodeKind = declaredElement.kind.displayName;
9291 var message = "Duplicate $nodeKind '$newName '." ;
93- result.addError (message, newLocation_fromElement (declaredElement));
92+ result.addError (message, newLocation_fromElement2 (declaredElement));
9493 return ;
9594 }
9695 }
9796 }
9897
99- SourceRange ? _getVisibleRange (LocalElement element) {
98+ SourceRange ? _getVisibleRange (LocalElement2 element) {
10099 return visibleRangeMap[element];
101100 }
102101
103102 /// Returns whether [element] and [target] are visible together.
104- bool _isVisibleWithTarget (Element element) {
105- if (element is LocalElement ) {
103+ bool _isVisibleWithTarget (Element2 element) {
104+ if (element is LocalElement2 ) {
106105 var targetRange = _getVisibleRange (target);
107106 var elementRange = _getVisibleRange (element);
108107 return elementRange != null && elementRange.intersects (targetRange);
@@ -121,15 +120,15 @@ class RenameLocalRefactoringImpl extends RenameRefactoringImpl {
121120 RenameLocalRefactoringImpl (
122121 super .workspace,
123122 super .sessionHelper,
124- LocalElement super .element,
125- );
123+ LocalElement2 super .element,
124+ ) : super . c2 () ;
126125
127126 @override
128- LocalElement get element => super .element as LocalElement ;
127+ LocalElement2 get element2 => super .element2 as LocalElement2 ;
129128
130129 @override
131130 String get refactoringName {
132- if (element is FunctionElement ) {
131+ if (element2 is LocalFunctionElement ) {
133132 return 'Rename Local Function' ;
134133 }
135134 return 'Rename Local Variable' ;
@@ -138,13 +137,13 @@ class RenameLocalRefactoringImpl extends RenameRefactoringImpl {
138137 @override
139138 Future <RefactoringStatus > checkFinalConditions () async {
140139 var result = RefactoringStatus ();
141- var resolvedUnit = await sessionHelper.getResolvedUnitByElement (element );
140+ var resolvedUnit = await sessionHelper.getResolvedUnitByElement2 (element2 );
142141 var unit = resolvedUnit? .unit;
143142 unit? .accept (
144143 ConflictValidatorVisitor (
145144 result,
146145 newName,
147- element ,
146+ element2 ,
148147 VisibleRangesComputer .forNode (unit),
149148 ),
150149 );
@@ -154,9 +153,9 @@ class RenameLocalRefactoringImpl extends RenameRefactoringImpl {
154153 @override
155154 RefactoringStatus checkNewName () {
156155 var result = super .checkNewName ();
157- if (element is LocalVariableElement ) {
156+ if (element2 is LocalVariableElement2 ) {
158157 result.addStatus (validateVariableName (newName));
159- } else if (element is FunctionElement ) {
158+ } else if (element2 is LocalFunctionElement ) {
160159 result.addStatus (validateFunctionName (newName));
161160 }
162161 return result;
@@ -166,36 +165,37 @@ class RenameLocalRefactoringImpl extends RenameRefactoringImpl {
166165 Future <void > fillChange () async {
167166 var processor = RenameProcessor (workspace, sessionHelper, change, newName);
168167
169- var element = this .element;
170- if (element is PatternVariableElementImpl ) {
171- var rootVariable = element.rootVariable;
172- var declaredElements =
168+ var element = element2;
169+ if (element is PatternVariableElement2 ) {
170+ var rootVariable =
171+ (element.firstFragment as PatternVariableElementImpl ).rootVariable;
172+ var declaredFragments =
173173 rootVariable is JoinPatternVariableElementImpl
174174 ? rootVariable.transitiveVariables
175175 .whereType <BindPatternVariableElementImpl >()
176176 .toList ()
177- : [element];
178- for (var declaredElement in declaredElements ) {
179- processor.addDeclarationEdit (declaredElement );
180- if (declaredElement is BindPatternVariableElementImpl ) {
177+ : [element.firstFragment ];
178+ for (var declaredFragment in declaredFragments ) {
179+ processor.addDeclarationEdit2 (declaredFragment.element );
180+ if (declaredFragment is BindPatternVariableElementImpl ) {
181181 // If a variable is used to resolve a named field with an implicit
182182 // name, we need to make the field name explicit.
183- var fieldName = declaredElement .node.fieldNameWithImplicitName;
183+ var fieldName = declaredFragment .node.fieldNameWithImplicitName;
184184 if (fieldName != null ) {
185- processor.replace (
185+ processor.replace2 (
186186 referenceElement: element,
187187 offset: fieldName.colon.offset,
188188 length: 0 ,
189- code: element.name ,
189+ code: element.name3 ! ,
190190 );
191191 }
192192 }
193193 }
194194 } else {
195- processor.addDeclarationEdit (element);
195+ processor.addDeclarationEdit2 (element);
196196 }
197197
198- var references = await searchEngine.searchReferences (element);
198+ var references = await searchEngine.searchReferences2 (element);
199199 processor.addReferenceEdits (references);
200200 }
201201}
0 commit comments