@@ -64,7 +64,8 @@ String _allActionDispatcherFieldsTemplate(ClassElement element) =>
64
64
element, _reduxActionFieldTemplate, _needsReduxActions);
65
65
66
66
String _actionDispatcherFieldTemplate (ClassElement e, FieldElement f) {
67
- final genericType = _getActionGenericType (f);
67
+ final genericType =
68
+ _getActionGenericType ((f.type as InterfaceType ).typeArguments.first);
68
69
return 'final ActionDispatcher<${genericType }> ${f .name } = new ActionDispatcher<${genericType }>(\' ${e .name }-${f .name }\' );' ;
69
70
}
70
71
@@ -99,7 +100,8 @@ String _allActionNamesFieldsTemplate(ClassElement element) =>
99
100
element, _actionNameTemplate, _isActionDispatcher);
100
101
101
102
String _actionNameTemplate (ClassElement e, FieldElement f) {
102
- final genericType = _getActionGenericType (f);
103
+ final genericType =
104
+ _getActionGenericType ((f.type as InterfaceType ).typeArguments.first);
103
105
return 'static final ActionName<${genericType }> ${f .name } = new ActionName<${genericType }>(\' ${e .name }-${f .name }\' );' ;
104
106
}
105
107
@@ -147,25 +149,36 @@ bool _hasSuperType(ClassElement classElement, String type) =>
147
149
.any ((interfaceType) => interfaceType.name == type) &&
148
150
! classElement.displayName.startsWith ('_\$ ' );
149
151
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 (',' )}>' ;
157
158
}
158
159
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
+ }
161
171
172
+ List <String > _correctUnresolvedGenerics (
173
+ List <DartType > args, List <TypeParameterElement > params) {
162
174
// hack for thunks/repatches or any other type argument list where
163
175
// any given argument is a Built and the proceding is a Builder
164
176
// and the builder is dynamic in the typeArguments list becauses it is
165
177
// yet to be generated. This is complex and a bit awkward but
166
178
// it is written this way to be very careful not to make any unintended
167
179
// 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);
169
182
for (int i = 0 ; i < boundParams.length; i++ ) {
170
183
// get the bound param at this spot
171
184
final b = boundParams.elementAt (i);
@@ -192,5 +205,5 @@ String _getActionGenericType(FieldElement e) {
192
205
}
193
206
}
194
207
195
- return '${ typeArgument . name }<${ typeArguments . join ( ',' )}>' ;
208
+ return typeArguments;
196
209
}
0 commit comments