@@ -311,14 +311,24 @@ abstract class ExecutableMember extends Member
311311
312312 @override
313313 List <ParameterElementMixin > get parameters {
314- return declaration.parameters.map <ParameterElementMixin >((p) {
315- if (p is FieldFormalParameterElementImpl ) {
316- return FieldFormalParameterMember (p, substitution);
314+ return declaration.parameters.map <ParameterElementMixin >((element) {
315+ switch (element) {
316+ case FieldFormalParameterElementImpl ():
317+ return FieldFormalParameterMember (
318+ declaration: element,
319+ substitution: substitution,
320+ );
321+ case SuperFormalParameterElementImpl ():
322+ return SuperFormalParameterMember (
323+ declaration: element,
324+ substitution: substitution,
325+ );
326+ default :
327+ return ParameterMember (
328+ declaration: element,
329+ substitution: substitution,
330+ );
317331 }
318- if (p is SuperFormalParameterElementImpl ) {
319- return SuperFormalParameterMember (p, substitution);
320- }
321- return ParameterMember (p, substitution);
322332 }).toList ();
323333 }
324334
@@ -394,17 +404,20 @@ abstract class ExecutableMember extends Member
394404 ExecutableElement element,
395405 MapSubstitution substitution,
396406 ) {
407+ ExecutableElementImpl declaration;
397408 var combined = substitution;
398409 if (element is ExecutableMember ) {
399410 ExecutableMember member = element;
400- element = member.declaration;
411+ declaration = member.declaration;
401412
402413 var map = < TypeParameterElement2 , DartType > {
403414 for (var MapEntry (: key, : value) in member.substitution.map.entries)
404415 key: substitution.substituteType (value),
405416 ...substitution.map,
406417 };
407418 combined = Substitution .fromMap2 (map);
419+ } else {
420+ declaration = element as ExecutableElementImpl ;
408421 }
409422
410423 if (combined.map.isEmpty) {
@@ -413,17 +426,24 @@ abstract class ExecutableMember extends Member
413426 return element as ExecutableElementOrMember ;
414427 }
415428
416- if (element is ConstructorElement ) {
417- return ConstructorMember (
418- declaration: element,
419- substitution: combined,
420- );
421- } else if (element is MethodElement ) {
422- return MethodMember (element, combined);
423- } else if (element is PropertyAccessorElement ) {
424- return PropertyAccessorMember (element, combined);
425- } else {
426- throw UnimplementedError ('(${element .runtimeType }) $element ' );
429+ switch (declaration) {
430+ case ConstructorElementImpl ():
431+ return ConstructorMember (
432+ declaration: declaration,
433+ substitution: combined,
434+ );
435+ case MethodElementImpl ():
436+ return MethodMember (
437+ declaration: declaration,
438+ substitution: combined,
439+ );
440+ case PropertyAccessorElementImpl ():
441+ return PropertyAccessorMember (
442+ declaration: declaration,
443+ substitution: combined,
444+ );
445+ default :
446+ throw UnimplementedError ('(${declaration .runtimeType }) $element ' );
427447 }
428448 }
429449}
@@ -432,10 +452,10 @@ abstract class ExecutableMember extends Member
432452/// type parameters are known.
433453class FieldFormalParameterMember extends ParameterMember
434454 implements FieldFormalParameterElement {
435- factory FieldFormalParameterMember (
436- FieldFormalParameterElement declaration,
437- MapSubstitution substitution,
438- ) {
455+ factory FieldFormalParameterMember ({
456+ required FieldFormalParameterElement declaration,
457+ required MapSubstitution substitution,
458+ } ) {
439459 var freshTypeParameters = _SubstitutedTypeParameters (
440460 declaration.typeParameters,
441461 substitution,
@@ -532,7 +552,10 @@ class FieldMember extends VariableMember
532552 if (baseGetter == null ) {
533553 return null ;
534554 }
535- return PropertyAccessorMember (baseGetter, substitution);
555+ return PropertyAccessorMember (
556+ declaration: baseGetter,
557+ substitution: substitution,
558+ );
536559 }
537560
538561 @override
@@ -593,7 +616,10 @@ class FieldMember extends VariableMember
593616 if (baseSetter == null ) {
594617 return null ;
595618 }
596- return PropertyAccessorMember (baseSetter, substitution);
619+ return PropertyAccessorMember (
620+ declaration: baseSetter,
621+ substitution: substitution,
622+ );
597623 }
598624
599625 @override
@@ -998,10 +1024,10 @@ abstract class Member implements Element, ElementOrMember {
9981024/// type parameters are known.
9991025class MethodMember extends ExecutableMember
10001026 implements MethodElementOrMember , MethodElement2OrMember {
1001- factory MethodMember (
1002- MethodElement declaration,
1003- MapSubstitution substitution,
1004- ) {
1027+ factory MethodMember ({
1028+ required MethodElement declaration,
1029+ required MapSubstitution substitution,
1030+ } ) {
10051031 var freshTypeParameters = _SubstitutedTypeParameters (
10061032 declaration.typeParameters,
10071033 substitution,
@@ -1068,39 +1094,19 @@ class MethodMember extends ExecutableMember
10681094 return visitor.visitMethodElement (this );
10691095 }
10701096
1071- /// If the given [method] 's type is different when any type parameters from
1072- /// the defining type's declaration are replaced with the actual type
1073- /// arguments from the [definingType] , create a method member representing the
1074- /// given method. Return the member that was created, or the base method if no
1075- /// member was created.
1076- static MethodElementOrMember ? from (
1077- MethodElement ? method, InterfaceType definingType) {
1078- if (method == null || definingType.typeArguments.isEmpty) {
1079- // TODO(paulberry): eliminate this cast by changing the type of the
1080- // `method` parameter.
1081- return method as MethodElementOrMember ? ;
1082- }
1083-
1084- return MethodMember (
1085- method,
1086- Substitution .fromInterfaceType (definingType),
1087- );
1088- }
1089-
1090- /// If the given [method] 's type is different when any type parameters from
1091- /// the defining type's declaration are replaced with the actual type
1092- /// arguments from the [definingType] , create a method member representing the
1093- /// given method. Return the member that was created, or the base method if no
1094- /// member was created.
1097+ /// If [definingType] has type parameters, returns [MethodMember] with
1098+ /// type substitutions. Otherwise returns [element] as is.
10951099 static MethodElement2OrMember from2 (
1096- MethodElementImpl2 element, InterfaceType definingType) {
1100+ MethodElementImpl2 element,
1101+ InterfaceType definingType,
1102+ ) {
10971103 if (definingType.typeArguments.isEmpty) {
10981104 return element;
10991105 }
11001106
11011107 return MethodMember (
1102- element.asElement,
1103- Substitution .fromInterfaceType (definingType),
1108+ declaration : element.asElement,
1109+ substitution : Substitution .fromInterfaceType (definingType),
11041110 );
11051111 }
11061112}
@@ -1113,10 +1119,10 @@ class ParameterMember extends VariableMember
11131119 @override
11141120 final List <TypeParameterElement > typeParameters;
11151121
1116- factory ParameterMember (
1117- ParameterElement declaration,
1118- MapSubstitution substitution,
1119- ) {
1122+ factory ParameterMember ({
1123+ required ParameterElement declaration,
1124+ required MapSubstitution substitution,
1125+ } ) {
11201126 var freshTypeParameters = _SubstitutedTypeParameters (
11211127 declaration.typeParameters,
11221128 substitution,
@@ -1301,7 +1307,10 @@ class ParameterMember extends VariableMember
13011307 return element;
13021308 }
13031309
1304- return ParameterMember (element, combined);
1310+ return ParameterMember (
1311+ declaration: element,
1312+ substitution: combined,
1313+ );
13051314 }
13061315}
13071316
@@ -1311,10 +1320,10 @@ abstract class PropertyAccessorMember extends ExecutableMember
13111320 implements
13121321 PropertyAccessorElementOrMember ,
13131322 PropertyAccessorElement2OrMember {
1314- factory PropertyAccessorMember (
1315- PropertyAccessorElement declaration,
1316- MapSubstitution substitution,
1317- ) {
1323+ factory PropertyAccessorMember ({
1324+ required PropertyAccessorElement declaration,
1325+ required MapSubstitution substitution,
1326+ } ) {
13181327 var freshTypeParameters = _SubstitutedTypeParameters (
13191328 declaration.typeParameters,
13201329 substitution,
@@ -1346,7 +1355,10 @@ abstract class PropertyAccessorMember extends ExecutableMember
13461355 if (baseGetter == null ) {
13471356 return null ;
13481357 }
1349- return PropertyAccessorMember (baseGetter, substitution);
1358+ return PropertyAccessorMember (
1359+ declaration: baseGetter,
1360+ substitution: substitution,
1361+ );
13501362 }
13511363
13521364 @override
@@ -1355,7 +1367,10 @@ abstract class PropertyAccessorMember extends ExecutableMember
13551367 if (baseSetter == null ) {
13561368 return null ;
13571369 }
1358- return PropertyAccessorMember (baseSetter, substitution);
1370+ return PropertyAccessorMember (
1371+ declaration: baseSetter,
1372+ substitution: substitution,
1373+ );
13591374 }
13601375
13611376 @override
@@ -1425,8 +1440,8 @@ abstract class PropertyAccessorMember extends ExecutableMember
14251440 }
14261441
14271442 return PropertyAccessorMember (
1428- accessor,
1429- Substitution .fromInterfaceType (definingType),
1443+ declaration : accessor,
1444+ substitution : Substitution .fromInterfaceType (definingType),
14301445 );
14311446 }
14321447}
@@ -1509,10 +1524,10 @@ class SetterMember extends PropertyAccessorMember
15091524
15101525class SuperFormalParameterMember extends ParameterMember
15111526 implements SuperFormalParameterElement {
1512- factory SuperFormalParameterMember (
1513- SuperFormalParameterElement declaration,
1514- MapSubstitution substitution,
1515- ) {
1527+ factory SuperFormalParameterMember ({
1528+ required SuperFormalParameterElement declaration,
1529+ required MapSubstitution substitution,
1530+ } ) {
15161531 var freshTypeParameters = _SubstitutedTypeParameters (
15171532 declaration.typeParameters,
15181533 substitution,
0 commit comments