22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // ignore_for_file: analyzer_use_new_elements
6-
7- import 'package:analyzer/dart/element/element.dart' ;
5+ import 'package:analyzer/dart/element/element2.dart' ;
86import 'package:analyzer/dart/element/scope.dart' ;
97import 'package:analyzer/dart/element/type.dart' ;
108import 'package:analyzer/error/listener.dart' ;
@@ -47,16 +45,14 @@ class AstRewriter {
4745 var typeNode = node.constructorName.type;
4846 var importPrefix = typeNode.importPrefix;
4947 if (importPrefix == null ) {
50- var element = nameScope.lookup (typeNode.name2.lexeme).getter;
51- if (element is FunctionElement ||
52- element is MethodElement ||
53- element is PropertyAccessorElement ) {
48+ var element = nameScope.lookup (typeNode.name2.lexeme).getter2;
49+ if (element is ExecutableElement2 ) {
5450 return _toMethodInvocationOfFunctionReference (
5551 node: node,
5652 function: SimpleIdentifierImpl (typeNode.name2),
5753 );
58- } else if (element is TypeAliasElementImpl &&
59- element.aliasedElement is GenericFunctionTypeElement ) {
54+ } else if (element is TypeAliasElementImpl2 &&
55+ element.aliasedElement2 is GenericFunctionTypeElement2 ) {
6056 return _toMethodInvocationOfAliasedTypeLiteral (
6157 node: node,
6258 function: SimpleIdentifierImpl (typeNode.name2),
@@ -65,11 +61,11 @@ class AstRewriter {
6561 }
6662 } else {
6763 var prefixName = importPrefix.name.lexeme;
68- var prefixElement = nameScope.lookup (prefixName).getter ;
69- if (prefixElement is PrefixElement ) {
64+ var prefixElement = nameScope.lookup (prefixName).getter2 ;
65+ if (prefixElement is PrefixElement2 ) {
7066 var prefixedName = typeNode.name2.lexeme;
71- var element = prefixElement.scope.lookup (prefixedName).getter ;
72- if (element is FunctionElement ) {
67+ var element = prefixElement.scope.lookup (prefixedName).getter2 ;
68+ if (element is TopLevelFunctionElement ) {
7369 return _toMethodInvocationOfFunctionReference (
7470 node: node,
7571 function: PrefixedIdentifierImpl (
@@ -78,8 +74,8 @@ class AstRewriter {
7874 identifier: SimpleIdentifierImpl (typeNode.name2),
7975 ),
8076 );
81- } else if (element is TypeAliasElementImpl &&
82- element.aliasedElement is GenericFunctionTypeElement ) {
77+ } else if (element is TypeAliasElementImpl2 &&
78+ element.aliasedElement2 is GenericFunctionTypeElement2 ) {
8379 return _toMethodInvocationOfAliasedTypeLiteral (
8480 node: node,
8581 function: PrefixedIdentifierImpl (
@@ -138,23 +134,23 @@ class AstRewriter {
138134 // This isn't a constructor invocation because it's in a cascade.
139135 return node;
140136 }
141- var element = nameScope.lookup (methodName.name).getter ;
142- if (element is InterfaceElement ) {
137+ var element = nameScope.lookup (methodName.name).getter2 ;
138+ if (element is InterfaceElement2 ) {
143139 return _toInstanceCreation_type (
144140 node: node,
145141 typeIdentifier: methodName,
146142 );
147- } else if (element is ExtensionElement ) {
143+ } else if (element is ExtensionElementImpl2 ) {
148144 var extensionOverride = ExtensionOverrideImpl (
149145 importPrefix: null ,
150146 name: methodName.token,
151- element : element,
147+ element2 : element,
152148 typeArguments: node.typeArguments,
153149 argumentList: node.argumentList,
154150 );
155151 NodeReplacer .replace (node, extensionOverride);
156152 return extensionOverride;
157- } else if (element is TypeAliasElement &&
153+ } else if (element is TypeAliasElement2 &&
158154 element.aliasedType is InterfaceType ) {
159155 return _toInstanceCreation_type (
160156 node: node,
@@ -167,8 +163,8 @@ class AstRewriter {
167163 // This isn't a constructor invocation because a null aware operator is
168164 // being used.
169165 }
170- var element = nameScope.lookup (target.name).getter ;
171- if (element is InterfaceElement ) {
166+ var element = nameScope.lookup (target.name).getter2 ;
167+ if (element is InterfaceElement2 ) {
172168 // class C { C.named(); }
173169 // C.named()
174170 return _toInstanceCreation_type_constructor (
@@ -177,37 +173,37 @@ class AstRewriter {
177173 constructorIdentifier: methodName,
178174 classElement: element,
179175 );
180- } else if (element is PrefixElement ) {
176+ } else if (element is PrefixElement2 ) {
181177 // Possible cases: p.C() or p.C<>()
182- var prefixedElement = element.scope.lookup (methodName.name).getter ;
183- if (prefixedElement is InterfaceElement ) {
178+ var prefixedElement = element.scope.lookup (methodName.name).getter2 ;
179+ if (prefixedElement is InterfaceElement2 ) {
184180 return _toInstanceCreation_prefix_type (
185181 node: node,
186182 prefixIdentifier: target,
187183 typeIdentifier: methodName,
188184 );
189- } else if (prefixedElement is ExtensionElement ) {
185+ } else if (prefixedElement is ExtensionElementImpl2 ) {
190186 var extensionOverride = ExtensionOverrideImpl (
191187 importPrefix: ImportPrefixReferenceImpl (
192188 name: target.token,
193189 period: operator ,
194- )..element = element,
190+ )..element2 = element,
195191 name: node.methodName.token,
196- element : prefixedElement,
192+ element2 : prefixedElement,
197193 typeArguments: node.typeArguments,
198194 argumentList: node.argumentList,
199195 );
200196 NodeReplacer .replace (node, extensionOverride);
201197 return extensionOverride;
202- } else if (prefixedElement is TypeAliasElement &&
198+ } else if (prefixedElement is TypeAliasElement2 &&
203199 prefixedElement.aliasedType is InterfaceType ) {
204200 return _toInstanceCreation_prefix_type (
205201 node: node,
206202 prefixIdentifier: target,
207203 typeIdentifier: methodName,
208204 );
209205 }
210- } else if (element is TypeAliasElement ) {
206+ } else if (element is TypeAliasElement2 ) {
211207 var aliasedType = element.aliasedType;
212208 if (aliasedType is InterfaceType ) {
213209 // class C { C.named(); }
@@ -217,32 +213,32 @@ class AstRewriter {
217213 node: node,
218214 typeIdentifier: target,
219215 constructorIdentifier: methodName,
220- classElement: aliasedType.element ,
216+ classElement: aliasedType.element3 ,
221217 );
222218 }
223219 }
224220 } else if (target is PrefixedIdentifierImpl ) {
225221 // Possible case: p.C.n()
226- var prefixElement = nameScope.lookup (target.prefix.name).getter ;
227- target.prefix.staticElement = prefixElement;
228- if (prefixElement is PrefixElement ) {
222+ var prefixElement = nameScope.lookup (target.prefix.name).getter2 ;
223+ target.prefix.element = prefixElement;
224+ if (prefixElement is PrefixElement2 ) {
229225 var prefixedName = target.identifier.name;
230- var element = prefixElement.scope.lookup (prefixedName).getter ;
231- if (element is InterfaceElement ) {
226+ var element = prefixElement.scope.lookup (prefixedName).getter2 ;
227+ if (element is InterfaceElement2 ) {
232228 return _instanceCreation_prefix_type_name (
233229 node: node,
234230 typeNameIdentifier: target,
235231 constructorIdentifier: methodName,
236232 classElement: element,
237233 );
238- } else if (element is TypeAliasElement ) {
234+ } else if (element is TypeAliasElement2 ) {
239235 var aliasedType = element.aliasedType;
240236 if (aliasedType is InterfaceType ) {
241237 return _instanceCreation_prefix_type_name (
242238 node: node,
243239 typeNameIdentifier: target,
244240 constructorIdentifier: methodName,
245- classElement: aliasedType.element ,
241+ classElement: aliasedType.element3 ,
246242 );
247243 }
248244 }
@@ -280,20 +276,20 @@ class AstRewriter {
280276 return node;
281277 }
282278 var prefix = node.prefix;
283- var prefixElement = nameScope.lookup (prefix.name).getter ;
284- if (parent is ConstantPattern && prefixElement is PrefixElement ) {
285- var element = prefixElement.scope.lookup (node.identifier.name).getter ;
286- if (element is TypeDefiningElement ) {
279+ var prefixElement = nameScope.lookup (prefix.name).getter2 ;
280+ if (parent is ConstantPattern && prefixElement is PrefixElement2 ) {
281+ var element = prefixElement.scope.lookup (node.identifier.name).getter2 ;
282+ if (element is TypeDefiningElement2 ) {
287283 return _toPatternTypeLiteral (parent, node);
288284 }
289285 }
290- if (prefixElement is InterfaceElement ) {
286+ if (prefixElement is InterfaceElement2 ) {
291287 // Example:
292288 // class C { C.named(); }
293289 // C.named
294290 return _toConstructorReference_prefixed (
295291 node: node, classElement: prefixElement);
296- } else if (prefixElement is TypeAliasElement ) {
292+ } else if (prefixElement is TypeAliasElement2 ) {
297293 var aliasedType = prefixElement.aliasedType;
298294 if (aliasedType is InterfaceType ) {
299295 // Example:
@@ -302,7 +298,7 @@ class AstRewriter {
302298 // X.named
303299 return _toConstructorReference_prefixed (
304300 node: node,
305- classElement: aliasedType.element ,
301+ classElement: aliasedType.element3 ,
306302 );
307303 }
308304 }
@@ -351,16 +347,16 @@ class AstRewriter {
351347 return node;
352348 }
353349
354- Element ? element;
350+ Element2 ? element;
355351 if (receiverIdentifier is SimpleIdentifierImpl ) {
356- element = nameScope.lookup (receiverIdentifier.name).getter ;
352+ element = nameScope.lookup (receiverIdentifier.name).getter2 ;
357353 } else if (receiverIdentifier is PrefixedIdentifierImpl ) {
358354 var prefixElement =
359- nameScope.lookup (receiverIdentifier.prefix.name).getter ;
360- if (prefixElement is PrefixElement ) {
355+ nameScope.lookup (receiverIdentifier.prefix.name).getter2 ;
356+ if (prefixElement is PrefixElement2 ) {
361357 element = prefixElement.scope
362358 .lookup (receiverIdentifier.identifier.name)
363- .getter ;
359+ .getter2 ;
364360 } else {
365361 // This expression is something like `foo.List<int>.filled` where `foo`
366362 // is not an import prefix.
@@ -370,7 +366,7 @@ class AstRewriter {
370366 }
371367 }
372368
373- if (element is InterfaceElement ) {
369+ if (element is InterfaceElement2 ) {
374370 // Example:
375371 // class C<T> { C.named(); }
376372 // C<int>.named
@@ -380,7 +376,7 @@ class AstRewriter {
380376 typeArguments: typeArguments,
381377 classElement: element,
382378 );
383- } else if (element is TypeAliasElement ) {
379+ } else if (element is TypeAliasElement2 ) {
384380 var aliasedType = element.aliasedType;
385381 if (aliasedType is InterfaceType ) {
386382 // Example:
@@ -391,7 +387,7 @@ class AstRewriter {
391387 node: node,
392388 receiver: receiverIdentifier,
393389 typeArguments: typeArguments,
394- classElement: aliasedType.element ,
390+ classElement: aliasedType.element3 ,
395391 );
396392 }
397393 }
@@ -414,8 +410,8 @@ class AstRewriter {
414410 AstNode simpleIdentifier (Scope nameScope, SimpleIdentifierImpl node) {
415411 var parent = node.parent;
416412 if (parent is ConstantPattern ) {
417- var element = nameScope.lookup (node.name).getter ;
418- if (element is TypeDefiningElement ) {
413+ var element = nameScope.lookup (node.name).getter2 ;
414+ if (element is TypeDefiningElement2 ) {
419415 return _toPatternTypeLiteral (parent, node);
420416 }
421417 }
@@ -427,10 +423,9 @@ class AstRewriter {
427423 required MethodInvocationImpl node,
428424 required PrefixedIdentifierImpl typeNameIdentifier,
429425 required SimpleIdentifierImpl constructorIdentifier,
430- required InterfaceElement classElement,
426+ required InterfaceElement2 classElement,
431427 }) {
432- var augmented = classElement.augmented ;
433- var constructorElement = augmented .getNamedConstructor (
428+ var constructorElement = classElement.getNamedConstructor2 (
434429 constructorIdentifier.name,
435430 );
436431 if (constructorElement == null ) {
@@ -472,12 +467,12 @@ class AstRewriter {
472467
473468 AstNode _toConstructorReference_prefixed ({
474469 required PrefixedIdentifierImpl node,
475- required InterfaceElement classElement,
470+ required InterfaceElement2 classElement,
476471 }) {
477472 var name = node.identifier.name;
478473 var constructorElement = name == 'new'
479- ? classElement.unnamedConstructor
480- : classElement.getNamedConstructor (name);
474+ ? classElement.unnamedConstructor2
475+ : classElement.getNamedConstructor2 (name);
481476 if (constructorElement == null ) {
482477 return node;
483478 }
@@ -504,12 +499,12 @@ class AstRewriter {
504499 required PropertyAccessImpl node,
505500 required IdentifierImpl receiver,
506501 required TypeArgumentListImpl ? typeArguments,
507- required InterfaceElement classElement,
502+ required InterfaceElement2 classElement,
508503 }) {
509504 var name = node.propertyName.name;
510505 var constructorElement = name == 'new'
511- ? classElement.unnamedConstructor
512- : classElement.getNamedConstructor (name);
506+ ? classElement.unnamedConstructor2
507+ : classElement.getNamedConstructor2 (name);
513508 if (constructorElement == null && typeArguments == null ) {
514509 // If there is no constructor by this name, and no type arguments,
515510 // do not rewrite the node. If there _are_ type arguments (like
@@ -594,11 +589,10 @@ class AstRewriter {
594589 required MethodInvocationImpl node,
595590 required SimpleIdentifierImpl typeIdentifier,
596591 required SimpleIdentifierImpl constructorIdentifier,
597- required InterfaceElement classElement,
592+ required InterfaceElement2 classElement,
598593 }) {
599594 var name = constructorIdentifier.name;
600- var augmented = classElement.augmented ;
601- var constructorElement = augmented .getNamedConstructor (name);
595+ var constructorElement = classElement.getNamedConstructor2 (name);
602596 if (constructorElement == null ) {
603597 return node;
604598 }
@@ -636,7 +630,7 @@ class AstRewriter {
636630 MethodInvocation _toMethodInvocationOfAliasedTypeLiteral ({
637631 required InstanceCreationExpressionImpl node,
638632 required Identifier function,
639- required TypeAliasElementImpl element,
633+ required TypeAliasElementImpl2 element,
640634 }) {
641635 var typeName = NamedTypeImpl (
642636 importPrefix: node.constructorName.type.importPrefix,
0 commit comments