@@ -6,27 +6,27 @@ import 'package:analysis_server/plugin/analysis/occurrences/occurrences_core.dar
66import 'package:analysis_server/src/protocol_server.dart' as protocol;
77import 'package:analyzer/dart/ast/ast.dart' ;
88import 'package:analyzer/dart/ast/visitor.dart' ;
9- import 'package:analyzer/dart/element/element .dart' ;
9+ import 'package:analyzer/dart/element/element2 .dart' ;
1010import 'package:analyzer/src/dart/ast/extensions.dart' ;
1111import 'package:analyzer/src/dart/element/element.dart' ;
1212
1313void addDartOccurrences (OccurrencesCollector collector, CompilationUnit unit) {
1414 var visitor = _DartUnitOccurrencesComputerVisitor ();
1515 unit.accept (visitor);
1616 visitor.elementsOffsets.forEach ((engineElement, offsets) {
17- var length = engineElement.nameLength ;
18- var serverElement = protocol.convertElement (engineElement);
17+ var length = engineElement.name3 ? .length ?? 0 ;
18+ var serverElement = protocol.convertElement2 (engineElement);
1919 var occurrences = protocol.Occurrences (serverElement, offsets, length);
2020 collector.addOccurrences (occurrences);
2121 });
2222}
2323
2424class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor <void > {
25- final Map <Element , List <int >> elementsOffsets = < Element , List < int > > {};
25+ final Map <Element2 , List <int >> elementsOffsets = {};
2626
2727 @override
2828 void visitAssignedVariablePattern (AssignedVariablePattern node) {
29- var element = node.element ;
29+ var element = node.element2 ;
3030 if (element != null ) {
3131 _addOccurrence (element, node.name.offset);
3232 }
@@ -36,67 +36,67 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
3636
3737 @override
3838 void visitClassDeclaration (ClassDeclaration node) {
39- _addOccurrence (node.declaredElement ! , node.name.offset);
39+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
4040
4141 super .visitClassDeclaration (node);
4242 }
4343
4444 @override
4545 void visitClassTypeAlias (ClassTypeAlias node) {
46- _addOccurrence (node.declaredElement ! , node.name.offset);
46+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
4747
4848 super .visitClassTypeAlias (node);
4949 }
5050
5151 @override
5252 void visitConstructorDeclaration (ConstructorDeclaration node) {
5353 if (node.name case var name? ) {
54- _addOccurrence (node.declaredElement ! , name.offset);
54+ _addOccurrence (node.declaredFragment ! .element , name.offset);
5555 }
5656
5757 super .visitConstructorDeclaration (node);
5858 }
5959
6060 @override
6161 void visitDeclaredIdentifier (DeclaredIdentifier node) {
62- _addOccurrence (node.declaredElement ! , node.name.offset);
62+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
6363
6464 super .visitDeclaredIdentifier (node);
6565 }
6666
6767 @override
6868 void visitDeclaredVariablePattern (DeclaredVariablePattern node) {
69- _addOccurrence (node.declaredElement ! , node.name.offset);
69+ _addOccurrence (node.declaredElement2 ! , node.name.offset);
7070
7171 super .visitDeclaredVariablePattern (node);
7272 }
7373
7474 @override
7575 void visitEnumConstantDeclaration (EnumConstantDeclaration node) {
76- _addOccurrence (node.declaredElement ! , node.name.offset);
76+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
7777
7878 super .visitEnumConstantDeclaration (node);
7979 }
8080
8181 @override
8282 void visitEnumDeclaration (EnumDeclaration node) {
83- _addOccurrence (node.declaredElement ! , node.name.offset);
83+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
8484
8585 super .visitEnumDeclaration (node);
8686 }
8787
8888 @override
8989 void visitExtensionTypeDeclaration (ExtensionTypeDeclaration node) {
90- _addOccurrence (node.declaredElement ! , node.name.offset);
90+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
9191
9292 super .visitExtensionTypeDeclaration (node);
9393 }
9494
9595 @override
9696 void visitFieldFormalParameter (FieldFormalParameter node) {
97- var declaredElement = node.declaredElement ;
98- if (declaredElement is FieldFormalParameterElement ) {
99- var field = declaredElement.field ;
97+ var declaredElement = node.declaredFragment ? .element ;
98+ if (declaredElement is FieldFormalParameterElement2 ) {
99+ var field = declaredElement.field2 ;
100100 if (field != null ) {
101101 _addOccurrence (field, node.name.offset);
102102 }
@@ -107,40 +107,40 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
107107
108108 @override
109109 void visitFunctionDeclaration (FunctionDeclaration node) {
110- _addOccurrence (node.declaredElement ! , node.name.offset);
110+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
111111 super .visitFunctionDeclaration (node);
112112 }
113113
114114 @override
115115 void visitFunctionTypeAlias (FunctionTypeAlias node) {
116- _addOccurrence (node.declaredElement ! , node.name.offset);
116+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
117117
118118 super .visitFunctionTypeAlias (node);
119119 }
120120
121121 @override
122122 void visitGenericTypeAlias (GenericTypeAlias node) {
123- _addOccurrence (node.declaredElement ! , node.name.offset);
123+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
124124
125125 super .visitGenericTypeAlias (node);
126126 }
127127
128128 @override
129129 void visitMethodDeclaration (MethodDeclaration node) {
130- _addOccurrence (node.declaredElement ! , node.name.offset);
130+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
131131 super .visitMethodDeclaration (node);
132132 }
133133
134134 @override
135135 void visitMixinDeclaration (MixinDeclaration node) {
136- _addOccurrence (node.declaredElement ! , node.name.offset);
136+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
137137
138138 super .visitMixinDeclaration (node);
139139 }
140140
141141 @override
142142 void visitNamedType (NamedType node) {
143- var element = node.element ;
143+ var element = node.element2 ;
144144 if (element != null ) {
145145 _addOccurrence (element, node.name2.offset);
146146 }
@@ -150,7 +150,7 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
150150
151151 @override
152152 void visitPatternField (PatternField node) {
153- var element = node.element ;
153+ var element = node.element2 ;
154154 var pattern = node.pattern;
155155 // If no explicit field name, use the variables name.
156156 var name =
@@ -166,7 +166,10 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
166166 @override
167167 void visitRepresentationDeclaration (RepresentationDeclaration node) {
168168 if (node.constructorName case var constructorName? ) {
169- _addOccurrence (node.constructorElement! , constructorName.name.offset);
169+ _addOccurrence (
170+ node.constructorFragment! .element,
171+ constructorName.name.offset,
172+ );
170173 }
171174
172175 super .visitRepresentationDeclaration (node);
@@ -176,15 +179,15 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
176179 void visitSimpleFormalParameter (SimpleFormalParameter node) {
177180 var nameToken = node.name;
178181 if (nameToken != null ) {
179- _addOccurrence (node.declaredElement ! , nameToken.offset);
182+ _addOccurrence (node.declaredFragment ! .element , nameToken.offset);
180183 }
181184
182185 super .visitSimpleFormalParameter (node);
183186 }
184187
185188 @override
186189 void visitSimpleIdentifier (SimpleIdentifier node) {
187- var element = node.writeOrReadElement ;
190+ var element = node.writeOrReadElement2 ;
188191 if (element != null ) {
189192 _addOccurrence (element, node.offset);
190193 }
@@ -193,17 +196,17 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
193196
194197 @override
195198 void visitSuperFormalParameter (SuperFormalParameter node) {
196- _addOccurrence (node.declaredElement ! , node.name.offset);
199+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
197200 super .visitSuperFormalParameter (node);
198201 }
199202
200203 @override
201204 void visitVariableDeclaration (VariableDeclaration node) {
202- _addOccurrence (node.declaredElement ! , node.name.offset);
205+ _addOccurrence (node.declaredFragment ! .element , node.name.offset);
203206 super .visitVariableDeclaration (node);
204207 }
205208
206- void _addOccurrence (Element element, int offset) {
209+ void _addOccurrence (Element2 element, int offset) {
207210 var canonicalElement = _canonicalizeElement (element);
208211 if (canonicalElement == null || element == DynamicElementImpl .instance) {
209212 return ;
@@ -216,13 +219,13 @@ class _DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
216219 offsets.add (offset);
217220 }
218221
219- Element ? _canonicalizeElement (Element element) {
220- Element ? canonicalElement = element;
221- if (canonicalElement is FieldFormalParameterElement ) {
222- canonicalElement = canonicalElement.field ;
223- } else if (canonicalElement is PropertyAccessorElement ) {
224- canonicalElement = canonicalElement.variable2 ;
222+ Element2 ? _canonicalizeElement (Element2 element) {
223+ Element2 ? canonicalElement = element;
224+ if (canonicalElement is FieldFormalParameterElement2 ) {
225+ canonicalElement = canonicalElement.field2 ;
226+ } else if (canonicalElement is PropertyAccessorElement2 ) {
227+ canonicalElement = canonicalElement.variable3 ;
225228 }
226- return canonicalElement? .declaration ;
229+ return canonicalElement? .baseElement ;
227230 }
228231}
0 commit comments