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-
75import 'package:analyzer/dart/analysis/features.dart' ;
86import 'package:analyzer/dart/ast/token.dart' ;
9- import 'package:analyzer/dart/element/element .dart' ;
7+ import 'package:analyzer/dart/element/element2 .dart' ;
108import 'package:analyzer/dart/element/scope.dart' ;
119import 'package:analyzer/dart/element/type.dart' ;
1210import 'package:analyzer/error/error.dart' ;
@@ -22,7 +20,6 @@ import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
2220import 'package:analyzer/src/diagnostic/diagnostic_factory.dart' ;
2321import 'package:analyzer/src/error/codes.dart' ;
2422import 'package:analyzer/src/generated/scope_helpers.dart' ;
25- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2623
2724/// Helper for resolving types.
2825///
@@ -41,7 +38,7 @@ class NamedTypeResolver with ScopeHelpers {
4138
4239 /// If not `null` , the element of the [ClassDeclaration] , or the
4340 /// [ClassTypeAlias] being resolved.
44- InterfaceElementImpl ? enclosingClass;
41+ InterfaceElementImpl2 ? enclosingClass;
4542
4643 /// If not `null` , a direct child of an [ExtendsClause] , [WithClause] ,
4744 /// or [ImplementsClause] .
@@ -74,9 +71,9 @@ class NamedTypeResolver with ScopeHelpers {
7471 }) : typeSystem = libraryElement.typeSystem;
7572
7673 bool get _genericMetadataIsEnabled =>
77- enclosingClass! .library .featureSet.isEnabled (Feature .generic_metadata);
74+ enclosingClass! .library2 .featureSet.isEnabled (Feature .generic_metadata);
7875
79- bool get _inferenceUsingBoundsIsEnabled => enclosingClass! .library .featureSet
76+ bool get _inferenceUsingBoundsIsEnabled => enclosingClass! .library2 .featureSet
8077 .isEnabled (Feature .inference_using_bounds);
8178
8279 /// Resolve the given [NamedType] - set its element and static type. Only the
@@ -92,16 +89,16 @@ class NamedTypeResolver with ScopeHelpers {
9289 if (importPrefix != null ) {
9390 var prefixToken = importPrefix.name;
9491 var prefixName = prefixToken.lexeme;
95- var prefixElement = nameScope.lookup (prefixName).getter ;
96- importPrefix.element = prefixElement;
92+ var prefixElement = nameScope.lookup (prefixName).getter2 ;
93+ importPrefix.element2 = prefixElement;
9794
9895 if (prefixElement == null ) {
9996 _resolveToElement (node, null , dataForTesting: dataForTesting);
10097 return ;
10198 }
10299
103- if (prefixElement is InterfaceElement ||
104- prefixElement is TypeAliasElement ) {
100+ if (prefixElement is InterfaceElement2 ||
101+ prefixElement is TypeAliasElement2 ) {
105102 _rewriteToConstructorName (
106103 node: node,
107104 importPrefix: importPrefix,
@@ -111,7 +108,7 @@ class NamedTypeResolver with ScopeHelpers {
111108 return ;
112109 }
113110
114- if (prefixElement is PrefixElement ) {
111+ if (prefixElement is PrefixElement2 ) {
115112 var nameToken = node.name2;
116113 var element = _lookupGetter (prefixElement.scope, nameToken);
117114 _resolveToElement (node, element, dataForTesting: dataForTesting);
@@ -171,13 +168,15 @@ class NamedTypeResolver with ScopeHelpers {
171168
172169 /// We are resolving the [NamedType] in a redirecting constructor of the
173170 /// [enclosingClass] .
174- InterfaceTypeImpl _inferRedirectedConstructor (InterfaceElementImpl element,
175- {required TypeConstraintGenerationDataForTesting ? dataForTesting,
176- required AstNodeImpl ? nodeForTesting}) {
171+ InterfaceTypeImpl _inferRedirectedConstructor (
172+ InterfaceElementImpl2 element, {
173+ required TypeConstraintGenerationDataForTesting ? dataForTesting,
174+ required AstNodeImpl ? nodeForTesting,
175+ }) {
177176 if (element == enclosingClass) {
178177 return element.thisType;
179178 } else {
180- var typeParameters = element.asElement2. typeParameters2;
179+ var typeParameters = element.typeParameters2;
181180 if (typeParameters.isEmpty) {
182181 return element.thisType;
183182 } else {
@@ -202,27 +201,27 @@ class NamedTypeResolver with ScopeHelpers {
202201 }
203202 }
204203
205- TypeImpl _instantiateElement (NamedTypeImpl node, Element element,
204+ TypeImpl _instantiateElement (NamedTypeImpl node, Element2 element,
206205 {required TypeConstraintGenerationDataForTesting ? dataForTesting}) {
207206 var nullability = _getNullability (node);
208207
209208 var argumentList = node.typeArguments;
210209 if (argumentList != null ) {
211- if (element is InterfaceElementImpl ) {
210+ if (element is InterfaceElementImpl2 ) {
212211 var typeArguments = _buildTypeArguments (
213212 node,
214213 argumentList,
215- element.typeParameters .length,
214+ element.typeParameters2 .length,
216215 );
217216 return element.instantiate (
218217 typeArguments: typeArguments,
219218 nullabilitySuffix: nullability,
220219 );
221- } else if (element is TypeAliasElementImpl ) {
220+ } else if (element is TypeAliasElementImpl2 ) {
222221 var typeArguments = _buildTypeArguments (
223222 node,
224223 argumentList,
225- element.typeParameters .length,
224+ element.typeParameters2 .length,
226225 );
227226 var type = element.instantiate (
228227 typeArguments: typeArguments,
@@ -232,13 +231,13 @@ class NamedTypeResolver with ScopeHelpers {
232231 } else if (_isInstanceCreation (node)) {
233232 _ErrorHelper (errorReporter).reportNewWithNonType (node);
234233 return InvalidTypeImpl .instance;
235- } else if (element is DynamicElementImpl ) {
234+ } else if (element is DynamicElementImpl2 ) {
236235 _buildTypeArguments (node, argumentList, 0 );
237236 return DynamicTypeImpl .instance;
238- } else if (element is NeverElementImpl ) {
237+ } else if (element is NeverElementImpl2 ) {
239238 _buildTypeArguments (node, argumentList, 0 );
240239 return _instantiateElementNever (nullability);
241- } else if (element is TypeParameterElementImpl ) {
240+ } else if (element is TypeParameterElementImpl2 ) {
242241 _buildTypeArguments (node, argumentList, 0 );
243242 return element.instantiate (
244243 nullabilitySuffix: nullability,
@@ -249,10 +248,10 @@ class NamedTypeResolver with ScopeHelpers {
249248 }
250249 }
251250
252- if (element is InterfaceElementImpl ) {
251+ if (element is InterfaceElementImpl2 ) {
253252 if (identical (node, withClause_namedType)) {
254253 for (var mixin in enclosingClass! .mixins) {
255- if (mixin .element == element) {
254+ if (mixin .element3 == element) {
256255 return mixin ;
257256 }
258257 }
@@ -264,23 +263,23 @@ class NamedTypeResolver with ScopeHelpers {
264263 }
265264
266265 return typeSystem.instantiateInterfaceToBounds2 (
267- element: element.asElement2 ,
266+ element: element,
268267 nullabilitySuffix: nullability,
269268 );
270- } else if (element is TypeAliasElementImpl ) {
271- var type = typeSystem.instantiateTypeAliasToBounds (
269+ } else if (element is TypeAliasElementImpl2 ) {
270+ var type = typeSystem.instantiateTypeAliasToBounds2 (
272271 element: element,
273272 nullabilitySuffix: nullability,
274273 );
275274 return _verifyTypeAliasForContext (node, element, type);
276275 } else if (_isInstanceCreation (node)) {
277276 _ErrorHelper (errorReporter).reportNewWithNonType (node);
278277 return InvalidTypeImpl .instance;
279- } else if (element is DynamicElementImpl ) {
278+ } else if (element is DynamicElementImpl2 ) {
280279 return DynamicTypeImpl .instance;
281- } else if (element is NeverElementImpl ) {
280+ } else if (element is NeverElementImpl2 ) {
282281 return _instantiateElementNever (nullability);
283- } else if (element is TypeParameterElementImpl ) {
282+ } else if (element is TypeParameterElementImpl2 ) {
284283 return element.instantiate (
285284 nullabilitySuffix: nullability,
286285 );
@@ -294,18 +293,18 @@ class NamedTypeResolver with ScopeHelpers {
294293 return NeverTypeImpl .instance.withNullability (nullability);
295294 }
296295
297- Element ? _lookupGetter (Scope scope, Token nameToken) {
296+ Element2 ? _lookupGetter (Scope scope, Token nameToken) {
298297 var scopeLookupResult = scope.lookup (nameToken.lexeme);
299298 reportDeprecatedExportUseGetter (
300299 scopeLookupResult: scopeLookupResult,
301300 nameToken: nameToken,
302301 );
303- return scopeLookupResult.getter ;
302+ return scopeLookupResult.getter2 ;
304303 }
305304
306- void _resolveToElement (NamedTypeImpl node, Element ? element,
305+ void _resolveToElement (NamedTypeImpl node, Element2 ? element,
307306 {required TypeConstraintGenerationDataForTesting ? dataForTesting}) {
308- node.element2 = element.asElement2 ;
307+ node.element2 = element;
309308
310309 if (element == null ) {
311310 node.type = InvalidTypeImpl .instance;
@@ -315,7 +314,7 @@ class NamedTypeResolver with ScopeHelpers {
315314 return ;
316315 }
317316
318- if (element is MultiplyDefinedElement ) {
317+ if (element is MultiplyDefinedElement2 ) {
319318 node.type = InvalidTypeImpl .instance;
320319 return ;
321320 }
@@ -327,12 +326,12 @@ class NamedTypeResolver with ScopeHelpers {
327326 }
328327
329328 /// We parse `foo.bar` as `prefix.Name` with the expectation that `prefix`
330- /// will be a [PrefixElement ] . But when we resolved the `prefix` it turned
331- /// out to be a [ClassElement ] , so it is probably a `Class.constructor` .
329+ /// will be a [PrefixElement2 ] . But when we resolved the `prefix` it turned
330+ /// out to be a [ClassElement2 ] , so it is probably a `Class.constructor` .
332331 void _rewriteToConstructorName ({
333332 required NamedTypeImpl node,
334333 required ImportPrefixReferenceImpl importPrefix,
335- required Element importPrefixElement,
334+ required Element2 importPrefixElement,
336335 required Token nameToken,
337336 }) {
338337 var constructorName = node.parent;
@@ -356,7 +355,7 @@ class NamedTypeResolver with ScopeHelpers {
356355 name2: importPrefix.name,
357356 typeArguments: null ,
358357 question: null ,
359- )..element2 = importPrefixElement.asElement2 ;
358+ )..element2 = importPrefixElement;
360359 if (identical (node, redirectedConstructor_namedType)) {
361360 redirectedConstructor_namedType = namedType;
362361 }
@@ -421,7 +420,7 @@ class NamedTypeResolver with ScopeHelpers {
421420
422421 TypeImpl _verifyTypeAliasForContext (
423422 NamedType node,
424- TypeAliasElement element,
423+ TypeAliasElement2 element,
425424 TypeImpl type,
426425 ) {
427426 // If a type alias that expands to a type parameter.
@@ -517,7 +516,7 @@ class _ErrorHelper {
517516 return false ;
518517 }
519518
520- void reportNullOrNonTypeElement (NamedType node, Element ? element) {
519+ void reportNullOrNonTypeElement (NamedType node, Element2 ? element) {
521520 if (node.name2.isSynthetic) {
522521 return ;
523522 }
@@ -610,14 +609,12 @@ class _ErrorHelper {
610609 return ;
611610 }
612611
613- if (element is LocalVariableElement ||
614- (element is FunctionElement &&
615- element.enclosingElement3 is ExecutableElement )) {
612+ if (element is LocalVariableElement2 || element is LocalFunctionElement ) {
616613 errorReporter.reportError (
617614 DiagnosticFactory ().referencedBeforeDeclaration (
618615 errorReporter.source,
619616 nameToken: node.name2,
620- element : element! ,
617+ element2 : element! ,
621618 ),
622619 );
623620 return ;
@@ -659,7 +656,7 @@ class _ErrorHelper {
659656 var firstToken = node.name2;
660657 var importPrefix = node.importPrefix;
661658 if (importPrefix != null ) {
662- if (! skipImportPrefix || importPrefix.element is ! PrefixElement ) {
659+ if (! skipImportPrefix || importPrefix.element2 is ! PrefixElement2 ) {
663660 firstToken = importPrefix.name;
664661 }
665662 }
0 commit comments