@@ -64,7 +64,8 @@ String _allActionDispatcherFieldsTemplate(ClassElement element) =>
6464 element, _reduxActionFieldTemplate, _needsReduxActions);
6565
6666String _actionDispatcherFieldTemplate (ClassElement e, FieldElement f) {
67- final genericType = _getActionGenericType (f);
67+ final genericType =
68+ _getActionGenericType ((f.type as InterfaceType ).typeArguments.first);
6869 return 'final ActionDispatcher<${genericType }> ${f .name } = new ActionDispatcher<${genericType }>(\' ${e .name }-${f .name }\' );' ;
6970}
7071
@@ -99,7 +100,8 @@ String _allActionNamesFieldsTemplate(ClassElement element) =>
99100 element, _actionNameTemplate, _isActionDispatcher);
100101
101102String _actionNameTemplate (ClassElement e, FieldElement f) {
102- final genericType = _getActionGenericType (f);
103+ final genericType =
104+ _getActionGenericType ((f.type as InterfaceType ).typeArguments.first);
103105 return 'static final ActionName<${genericType }> ${f .name } = new ActionName<${genericType }>(\' ${e .name }-${f .name }\' );' ;
104106}
105107
@@ -147,25 +149,36 @@ bool _hasSuperType(ClassElement classElement, String type) =>
147149 .any ((interfaceType) => interfaceType.name == type) &&
148150 ! classElement.displayName.startsWith ('_\$ ' );
149151
150- String _getActionGenericType (FieldElement e) {
151- var typeArgument =
152- (e.type as InterfaceType ).typeArguments.first as ParameterizedType ;
153- // generic type has generic type parameters?
154- if (typeArgument.typeArguments.isEmpty ||
155- typeArgument.typeArguments.every ((ta) => ta.name == 'dynamic' )) {
156- return typeArgument.name;
152+ String _getActionGenericType (DartType type) {
153+ if (type is FunctionType ) {
154+ final generics =
155+ _correctUnresolvedGenerics (type.typeArguments, type.typeParameters);
156+ if (generics.isEmpty) return typeNameOf (type);
157+ return typeNameOf (type) + '<${generics .join (',' )}>' ;
157158 }
158159
159- final typeArguments =
160- typeArgument.typeArguments.map ((ta) => ta.toString ()).toList ();
160+ if (type is ParameterizedType ) {
161+ final generics =
162+ _correctUnresolvedGenerics (type.typeArguments, type.typeParameters);
163+ if (generics.isEmpty) return type.name;
164+ return type.name + '<${generics .join (',' )}>' ;
165+ }
166+
167+ if (type.isVoid) return 'void' ;
168+
169+ return 'dynamic' ;
170+ }
161171
172+ List <String > _correctUnresolvedGenerics (
173+ List <DartType > args, List <TypeParameterElement > params) {
162174 // hack for thunks/repatches or any other type argument list where
163175 // any given argument is a Built and the proceding is a Builder
164176 // and the builder is dynamic in the typeArguments list becauses it is
165177 // yet to be generated. This is complex and a bit awkward but
166178 // it is written this way to be very careful not to make any unintended
167179 // changes the the typeArguments list.
168- final boundParams = typeArgument.typeParameters.map ((e) => e.bound);
180+ final typeArguments = args.map ((ta) => ta.toString ()).toList ();
181+ final boundParams = params.map ((e) => e.bound);
169182 for (int i = 0 ; i < boundParams.length; i++ ) {
170183 // get the bound param at this spot
171184 final b = boundParams.elementAt (i);
@@ -192,5 +205,5 @@ String _getActionGenericType(FieldElement e) {
192205 }
193206 }
194207
195- return '${ typeArgument . name }<${ typeArguments . join ( ',' )}>' ;
208+ return typeArguments;
196209}
0 commit comments