@@ -28,7 +28,7 @@ class ConstructorMember extends ExecutableMember
2828 /// Initialize a newly created element to represent a constructor, based on
2929 /// the [declaration] , and applied [substitution] .
3030 ConstructorMember ({
31- required ConstructorElement super .declaration,
31+ required ConstructorElementImpl super .declaration,
3232 required super .substitution,
3333 }) : super (
3434 typeParameters: const < TypeParameterElementImpl > [],
@@ -90,7 +90,7 @@ class ConstructorMember extends ExecutableMember
9090 @override
9191 ConstructorElementMixin ? get redirectedConstructor {
9292 var element = declaration.redirectedConstructor;
93- return _from2 (element);
93+ return _redirect (element);
9494 }
9595
9696 @override
@@ -114,7 +114,7 @@ class ConstructorMember extends ExecutableMember
114114 @override
115115 ConstructorElement ? get superConstructor {
116116 var element = declaration.superConstructor;
117- return _from2 (element);
117+ return _redirect (element);
118118 }
119119
120120 @override
@@ -138,71 +138,61 @@ class ConstructorMember extends ExecutableMember
138138 builder.writeConstructorElement (this );
139139 }
140140
141- ConstructorMember ? _from2 (ConstructorElement ? element) {
142- if (element == null ) {
143- return null ;
144- }
145-
146- ConstructorElement declaration;
147- MapSubstitution substitution;
148- if (element is ConstructorMember ) {
149- declaration = element._declaration as ConstructorElement ;
150- var map = < TypeParameterElement2 , DartType > {};
151- var elementMap = element.substitution.map;
152- for (var typeParameter in elementMap.keys) {
153- var type = elementMap[typeParameter]! ;
154- map[typeParameter] = this .substitution.substituteType (type);
155- }
156- substitution = Substitution .fromMap2 (map);
157- } else {
158- declaration = element;
159- substitution = this .substitution;
141+ ConstructorElementMixin ? _redirect (ConstructorElementMixin ? element) {
142+ switch (element) {
143+ case null :
144+ return null ;
145+ case ConstructorElementImpl ():
146+ return element;
147+ case ConstructorMember ():
148+ var memberMap = element.substitution.map;
149+ var map = < TypeParameterElement2 , DartType > {
150+ for (var MapEntry (: key, : value) in memberMap.entries)
151+ key: substitution.substituteType (value),
152+ };
153+ return ConstructorMember (
154+ declaration: element.declaration,
155+ substitution: Substitution .fromMap2 (map),
156+ );
157+ default :
158+ throw UnimplementedError ('(${element .runtimeType }) $element ' );
160159 }
161-
162- return ConstructorMember (
163- declaration: declaration,
164- substitution: substitution,
165- );
166160 }
167161
168- /// If the given [constructor ] 's type is different when any type parameters
162+ /// If the given [element ] 's type is different when any type parameters
169163 /// from the defining type's declaration are replaced with the actual type
170164 /// arguments from the [definingType] , create a constructor member
171165 /// representing the given constructor. Return the member that was created, or
172166 /// the original constructor if no member was created.
173167 static ConstructorElementMixin from (
174- ConstructorElementMixin constructor, InterfaceType definingType) {
168+ ConstructorElementImpl element,
169+ InterfaceType definingType,
170+ ) {
175171 if (definingType.typeArguments.isEmpty) {
176- return constructor;
177- }
178-
179- if (constructor is ConstructorMember ) {
180- constructor = constructor.declaration;
172+ return element;
181173 }
182174
183175 return ConstructorMember (
184- declaration: constructor ,
176+ declaration: element ,
185177 substitution: Substitution .fromInterfaceType (definingType),
186178 );
187179 }
188180
189- /// If the given [constructor ] 's type is different when any type parameters
181+ /// If the given [element ] 's type is different when any type parameters
190182 /// from the defining type's declaration are replaced with the actual type
191183 /// arguments from the [definingType] , create a constructor member
192184 /// representing the given constructor. Return the member that was created, or
193185 /// the original constructor if no member was created.
194186 static ConstructorElementMixin2 from2 (
195- ConstructorElementMixin2 constructor, InterfaceType definingType) {
187+ ConstructorElementImpl2 element,
188+ InterfaceType definingType,
189+ ) {
196190 if (definingType.typeArguments.isEmpty) {
197- return constructor;
198- }
199-
200- if (constructor is ConstructorMember ) {
201- constructor = constructor.baseElement;
191+ return element;
202192 }
203193
204194 return ConstructorMember (
205- declaration: constructor .asElement,
195+ declaration: element .asElement,
206196 substitution: Substitution .fromInterfaceType (definingType),
207197 );
208198 }
0 commit comments