@@ -9,8 +9,10 @@ import 'package:analysis_server/src/services/completion/dart/suggestion_builder.
99 show SuggestionBuilder;
1010import 'package:analyzer/dart/ast/ast.dart' ;
1111import 'package:analyzer/dart/element/element.dart' ;
12+ import 'package:analyzer/dart/element/element2.dart' ;
1213import 'package:analyzer/dart/element/type.dart' ;
1314import 'package:analyzer/dart/element/visitor.dart' ;
15+ import 'package:analyzer/src/utilities/extensions/element.dart' ;
1416import 'package:analyzer_plugin/src/utilities/completion/optype.dart' ;
1517
1618/// A visitor for building suggestions based upon the elements defined by
@@ -92,7 +94,11 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
9294 void visitExtensionElement (ExtensionElement element) {
9395 if (opType.includeReturnValueSuggestions) {
9496 if (element.name != null ) {
95- builder.suggestExtension (element, kind: kind, prefix: prefix);
97+ builder.suggestExtension (
98+ element.asElement2 as ExtensionElement2 ,
99+ kind: kind,
100+ prefix: prefix,
101+ );
96102 }
97103 }
98104 }
@@ -114,11 +120,19 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
114120 var returnType = element.returnType;
115121 if (returnType is VoidType ) {
116122 if (opType.includeVoidReturnSuggestions) {
117- builder.suggestTopLevelFunction (element, kind: kind, prefix: prefix);
123+ builder.suggestTopLevelFunction (
124+ element.asElement2 as TopLevelFunctionElement ,
125+ kind: kind,
126+ prefix: prefix,
127+ );
118128 }
119129 } else {
120130 if (opType.includeReturnValueSuggestions) {
121- builder.suggestTopLevelFunction (element, kind: kind, prefix: prefix);
131+ builder.suggestTopLevelFunction (
132+ element.asElement2 as TopLevelFunctionElement ,
133+ kind: kind,
134+ prefix: prefix,
135+ );
122136 }
123137 }
124138 }
@@ -152,29 +166,58 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
152166 if (element.isSynthetic) {
153167 if (element.isGetter) {
154168 if (variable is FieldElement ) {
155- builder.suggestField (variable, inheritanceDistance: 0.0 );
169+ builder.suggestField (
170+ variable.asElement2 as FieldElement2 ,
171+ inheritanceDistance: 0.0 ,
172+ );
156173 }
157174 }
158175 } else {
159- builder.suggestAccessor (element, inheritanceDistance: 0.0 );
176+ if (element.isGetter) {
177+ builder.suggestGetter (
178+ element.asElement2 as GetterElement ,
179+ inheritanceDistance: 0.0 ,
180+ );
181+ } else {
182+ builder.suggestSetter (
183+ element.asElement2 as SetterElement ,
184+ inheritanceDistance: 0.0 ,
185+ );
186+ }
160187 }
161188 } else {
162- builder.suggestTopLevelPropertyAccessor (element, prefix: prefix);
189+ if (element.isGetter) {
190+ builder.suggestTopLevelGetter (
191+ element.asElement2 as GetterElement ,
192+ prefix: prefix,
193+ );
194+ } else {
195+ builder.suggestTopLevelSetter (
196+ element.asElement2 as SetterElement ,
197+ prefix: prefix,
198+ );
199+ }
163200 }
164201 }
165202 }
166203
167204 @override
168205 void visitTopLevelVariableElement (TopLevelVariableElement element) {
169206 if (opType.includeReturnValueSuggestions && ! element.isSynthetic) {
170- builder.suggestTopLevelVariable (element, prefix: prefix);
207+ builder.suggestTopLevelVariable (
208+ element.asElement2 as TopLevelVariableElement2 ,
209+ prefix: prefix,
210+ );
171211 }
172212 }
173213
174214 @override
175215 void visitTypeAliasElement (TypeAliasElement element) {
176216 if (opType.includeTypeNameSuggestions) {
177- builder.suggestTypeAlias (element, prefix: prefix);
217+ builder.suggestTypeAlias (
218+ element.asElement2 as TypeAliasElement2 ,
219+ prefix: prefix,
220+ );
178221 }
179222 }
180223
@@ -199,13 +242,17 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
199242 if (onlyConst && ! constructor.isConst) {
200243 continue ;
201244 }
202- builder.suggestConstructor (constructor, kind: kind, prefix: prefix);
245+ builder.suggestConstructor (
246+ constructor.asElement2 as ConstructorElement2 ,
247+ kind: kind,
248+ prefix: prefix,
249+ );
203250 }
204251 }
205252
206253 void _visitInterfaceElement (InterfaceElement element) {
207254 if (opType.includeTypeNameSuggestions) {
208- builder.suggestInterface (element, prefix: prefix);
255+ builder.suggestInterface (element.asElement2 , prefix: prefix);
209256 }
210257 if (element is ClassElement ) {
211258 if (opType.includeConstructorSuggestions) {
@@ -226,14 +273,17 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
226273 if (field.isSynthetic) {
227274 var getter = field.getter;
228275 if (getter != null ) {
229- builder.suggestAccessor (
230- getter,
276+ builder.suggestGetter (
277+ getter.asElement2 as GetterElement ,
231278 inheritanceDistance: 0.0 ,
232279 withEnclosingName: true ,
233280 );
234281 }
235282 } else {
236- builder.suggestStaticField (field, prefix: prefix);
283+ builder.suggestStaticField (
284+ field.asElement2 as FieldElement2 ,
285+ prefix: prefix,
286+ );
237287 }
238288 }
239289 }
0 commit comments