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' ;
8- import 'package:analyzer/dart/element/element.dart' ;
96import 'package:analyzer/dart/element/element2.dart' ;
107import 'package:analyzer/dart/element/nullability_suffix.dart' ;
118import 'package:analyzer/dart/element/type.dart' ;
@@ -19,7 +16,6 @@ import 'package:analyzer/src/dart/element/type_visitor.dart';
1916import 'package:analyzer/src/summary2/link.dart' ;
2017import 'package:analyzer/src/summary2/type_builder.dart' ;
2118import 'package:analyzer/src/utilities/extensions/collection.dart' ;
22- import 'package:analyzer/src/utilities/extensions/element.dart' ;
2319
2420/// The type builder for a [NamedType] .
2521class NamedTypeBuilder extends TypeBuilder {
@@ -32,7 +28,7 @@ class NamedTypeBuilder extends TypeBuilder {
3228 final TypeSystemImpl typeSystem;
3329
3430 @override
35- final Element element ;
31+ final Element2 element3 ;
3632
3733 final List <DartType > arguments;
3834
@@ -50,15 +46,15 @@ class NamedTypeBuilder extends TypeBuilder {
5046 /// and set for the [node] .
5147 TypeImpl ? _type;
5248
53- NamedTypeBuilder (this .linker, this .typeSystem, this .element , this .arguments,
49+ NamedTypeBuilder (this .linker, this .typeSystem, this .element3 , this .arguments,
5450 this .nullabilitySuffix,
5551 {this .node});
5652
5753 factory NamedTypeBuilder .of (
5854 Linker linker,
5955 TypeSystemImpl typeSystem,
6056 NamedTypeImpl node,
61- Element element,
57+ Element2 element,
6258 NullabilitySuffix nullabilitySuffix,
6359 ) {
6460 List <DartType > arguments;
@@ -85,21 +81,16 @@ class NamedTypeBuilder extends TypeBuilder {
8581 return NamedTypeBuilder (
8682 linker,
8783 typeSystem,
88- element.asElement ! ,
84+ element,
8985 arguments,
9086 nullabilitySuffix,
9187 node: node,
9288 );
9389 }
9490
95- @override
96- Element2 get element3 {
97- return element.asElement2! ;
98- }
99-
10091 // TODO(scheglov): Only when enabled both in the element, and target?
10192 bool get _isNonFunctionTypeAliasesEnabled {
102- return element.library ! .featureSet.isEnabled (
93+ return element3.library2 ! .featureSet.isEnabled (
10394 Feature .nonfunction_type_aliases,
10495 );
10596 }
@@ -120,28 +111,28 @@ class NamedTypeBuilder extends TypeBuilder {
120111 return _type! ;
121112 }
122113
123- var element = this .element ;
124- if (element is InterfaceElementImpl ) {
125- var parameters = element.typeParameters ;
114+ var element3 = this .element3 ;
115+ if (element3 is InterfaceElementImpl2 ) {
116+ var parameters = element3.typeParameters2 ;
126117 var arguments = _buildArguments (parameters);
127- _type = element .instantiate (
118+ _type = element3 .instantiate (
128119 typeArguments: arguments,
129120 nullabilitySuffix: nullabilitySuffix,
130121 );
131- } else if (element is TypeAliasElementImpl ) {
132- var aliasedType = _getAliasedType (element );
133- var parameters = element.typeParameters ;
122+ } else if (element3 is TypeAliasElementImpl2 ) {
123+ var aliasedType = _getAliasedType (element3 );
124+ var parameters = element3.typeParameters2 ;
134125 var arguments = _buildArguments (parameters);
135- element .aliasedType = aliasedType;
136- _type = element .instantiate (
126+ element3 .aliasedType = aliasedType as TypeImpl ;
127+ _type = element3 .instantiate (
137128 typeArguments: arguments,
138129 nullabilitySuffix: nullabilitySuffix,
139130 );
140- } else if (element is NeverElementImpl ) {
131+ } else if (element3 is NeverElementImpl2 ) {
141132 _type = NeverTypeImpl .instance.withNullability (nullabilitySuffix);
142- } else if (element is TypeParameterElement ) {
143- _type = TypeParameterTypeImpl (
144- element: element ,
133+ } else if (element3 is TypeParameterElement2 ) {
134+ _type = TypeParameterTypeImpl . v2 (
135+ element: element3 ,
145136 nullabilitySuffix: nullabilitySuffix,
146137 );
147138 } else {
@@ -155,7 +146,7 @@ class NamedTypeBuilder extends TypeBuilder {
155146 @override
156147 String toString () {
157148 var buffer = StringBuffer ();
158- buffer.write (element .displayName);
149+ buffer.write (element3 .displayName);
159150 if (arguments.isNotEmpty) {
160151 buffer.write ('<' );
161152 buffer.write (arguments.join (', ' ));
@@ -171,11 +162,11 @@ class NamedTypeBuilder extends TypeBuilder {
171162 }
172163
173164 return NamedTypeBuilder (
174- linker, typeSystem, element , arguments, nullabilitySuffix,
165+ linker, typeSystem, element3 , arguments, nullabilitySuffix,
175166 node: node);
176167 }
177168
178- DartType _buildAliasedType (TypeAnnotation ? node) {
169+ TypeImpl _buildAliasedType (TypeAnnotation ? node) {
179170 if (_isNonFunctionTypeAliasesEnabled) {
180171 if (node != null ) {
181172 return _buildType (node.typeOrThrow);
@@ -186,9 +177,9 @@ class NamedTypeBuilder extends TypeBuilder {
186177 if (node is GenericFunctionType ) {
187178 return _buildType (node.typeOrThrow);
188179 } else {
189- return FunctionTypeImpl (
190- typeFormals : const < TypeParameterElement > [],
191- parameters : const < ParameterElement > [],
180+ return FunctionTypeImpl . v2 (
181+ typeParameters : const < TypeParameterElement2 > [],
182+ formalParameters : const < FormalParameterElement > [],
192183 returnType: _dynamicType,
193184 nullabilitySuffix: NullabilitySuffix .none,
194185 );
@@ -197,23 +188,23 @@ class NamedTypeBuilder extends TypeBuilder {
197188 }
198189
199190 /// Build arguments that correspond to the type [parameters] .
200- List <DartType > _buildArguments (List <TypeParameterElement > parameters) {
191+ List <DartType > _buildArguments (List <TypeParameterElement2 > parameters) {
201192 if (parameters.isEmpty) {
202193 return const < DartType > [];
203194 } else if (arguments.isNotEmpty) {
204195 if (arguments.length == parameters.length) {
205196 return List .generate (arguments.length, (index) {
206197 var type = arguments[index];
207- return _buildType (type);
198+ return _buildType (type as TypeImpl );
208199 }, growable: false );
209200 } else {
210201 return _listOfDynamic (parameters.length);
211202 }
212203 } else {
213204 return List .generate (parameters.length, (index) {
214- var parameter = parameters[index] as TypeParameterElementImpl ;
205+ var parameter = parameters[index] as TypeParameterElementImpl2 ;
215206 var defaultType = parameter.defaultType! ;
216- return _buildType (defaultType);
207+ return _buildType (defaultType as TypeImpl );
217208 }, growable: false );
218209 }
219210 }
@@ -235,7 +226,7 @@ class NamedTypeBuilder extends TypeBuilder {
235226 }
236227 }
237228
238- FunctionType _buildFunctionType ({
229+ FunctionTypeImpl _buildFunctionType ({
239230 required TypeParameterList ? typeParameterList,
240231 required TypeAnnotation ? returnTypeNode,
241232 required FormalParameterList parameterList,
@@ -245,9 +236,9 @@ class NamedTypeBuilder extends TypeBuilder {
245236 var typeParameters = _typeParameters (typeParameterList);
246237 var formalParameters = _formalParameters (parameterList);
247238
248- return FunctionTypeImpl (
249- typeFormals : typeParameters,
250- parameters : formalParameters,
239+ return FunctionTypeImpl . v2 (
240+ typeParameters : typeParameters,
241+ formalParameters : formalParameters,
251242 returnType: returnType,
252243 nullabilitySuffix: _getNullabilitySuffix (hasQuestion),
253244 );
@@ -261,18 +252,18 @@ class NamedTypeBuilder extends TypeBuilder {
261252 }
262253 }
263254
264- List <ParameterElementImpl > _formalParameters (FormalParameterList node) {
255+ List <FormalParameterElementImpl > _formalParameters (FormalParameterList node) {
265256 return node.parameters.asImpl.map ((parameter) {
266- return ParameterElementImpl .synthetic (
257+ return FormalParameterElementImpl .synthetic (
267258 parameter.name? .lexeme ?? '' ,
268259 _buildFormalParameterType (parameter),
269260 parameter.kind,
270261 );
271262 }).toFixedList ();
272263 }
273264
274- DartType _getAliasedType (TypeAliasElementImpl element) {
275- var typedefNode = linker.getLinkingNode (element);
265+ DartType _getAliasedType (TypeAliasElementImpl2 element) {
266+ var typedefNode = linker.getLinkingNode2 (element);
276267
277268 // If the element is not being linked, the types have already been built.
278269 if (typedefNode == null ) {
@@ -315,7 +306,7 @@ class NamedTypeBuilder extends TypeBuilder {
315306 }
316307
317308 /// If the [type] is a [TypeBuilder] , build it; otherwise return as is.
318- static DartType _buildType (DartType type) {
309+ static TypeImpl _buildType (TypeImpl type) {
319310 if (type is TypeBuilder ) {
320311 return type.build ();
321312 } else {
@@ -327,13 +318,13 @@ class NamedTypeBuilder extends TypeBuilder {
327318 return List <DartType >.filled (length, _dynamicType);
328319 }
329320
330- static List <TypeParameterElement > _typeParameters (TypeParameterList ? node) {
321+ static List <TypeParameterElement2 > _typeParameters (TypeParameterList ? node) {
331322 if (node != null ) {
332323 return node.typeParameters
333- .map <TypeParameterElement >((p) => p.declaredElement ! )
324+ .map <TypeParameterElement2 >((p) => p.declaredFragment ! .element )
334325 .toFixedList ();
335326 } else {
336- return const < TypeParameterElement > [];
327+ return const < TypeParameterElement2 > [];
337328 }
338329 }
339330}
0 commit comments