Skip to content

Commit eb1c1bf

Browse files
Merge pull request #220 from Workiva/AF-3731_carry_generics_on_mixins
AF-3731: Carry type parameters on generated empty prop/state mixins classes
2 parents 014965f + 8ba2e6d commit eb1c1bf

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

lib/src/transformer/impl_generation.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class ImplGenerator {
355355
/// This is because with the builder compatible boilerplate, Props
356356
/// and State mixin classes are renamed to include a $ prefix with the assumption that
357357
/// the actual class with concrete accessor implementations will be generated.
358-
transformedFile.insert(sourceFile.location(propMixin.node.end), ' abstract class \$${propMixin.node.name.name} {}');
358+
transformedFile.insert(sourceFile.location(propMixin.node.end), ' abstract class \$${propMixin.node.name.name}${propMixin.node.typeParameters ?? ''} {}');
359359
});
360360

361361
declarations.stateMixins.forEach((stateMixin) {
@@ -375,7 +375,7 @@ class ImplGenerator {
375375
/// This is because with the builder compatible boilerplate, Props
376376
/// and State mixin classes are renamed to include a $ prefix with the assumption that
377377
/// the actual class with concrete accessor implementations will be generated.
378-
transformedFile.insert(sourceFile.location(stateMixin.node.end), 'abstract class \$${stateMixin.node.name.name} {}');
378+
transformedFile.insert(sourceFile.location(stateMixin.node.end), 'abstract class \$${stateMixin.node.name.name}${stateMixin.node.typeParameters ?? ''} {}');
379379
});
380380

381381
// ----------------------------------------------------------------------

test/vm_tests/transformer/impl_generation_test.dart

+48-20
Original file line numberDiff line numberDiff line change
@@ -382,32 +382,60 @@ main() {
382382
});
383383
});
384384

385-
test('props mixins', () {
386-
preservedLineNumbersTest('''
387-
@PropsMixin() class FooPropsMixin {
388-
Map get props;
385+
group('for props mixins', () {
386+
test('without type parameters', () {
387+
preservedLineNumbersTest('''
388+
@PropsMixin() class FooPropsMixin {
389+
Map get props;
389390
390-
var bar;
391-
var baz;
392-
}
393-
''');
391+
var bar;
392+
var baz;
393+
}
394+
''');
394395

395-
var transformedSource = transformedFile.getTransformedText();
396-
expect(transformedSource, contains('abstract class \$FooPropsMixin {}'));
396+
expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin {}'));
397+
});
398+
399+
test('with type parameters', () {
400+
preservedLineNumbersTest('''
401+
@PropsMixin() class FooPropsMixin<T extends Iterable<T>, U> {
402+
Map get props;
403+
404+
List<T> bar;
405+
U baz;
406+
}
407+
''');
408+
409+
expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin<T extends Iterable<T>, U> {}'));
410+
});
397411
});
398412

399-
test('state mixins', () {
400-
preservedLineNumbersTest('''
401-
@StateMixin() class FooStateMixin {
402-
Map get state;
413+
group('for state mixins', () {
414+
test('without type parameters', () {
415+
preservedLineNumbersTest('''
416+
@StateMixin() class FooStateMixin {
417+
Map get state;
403418
404-
var bar;
405-
var baz;
406-
}
407-
''');
419+
var bar;
420+
var baz;
421+
}
422+
''');
408423

409-
var transformedSource = transformedFile.getTransformedText();
410-
expect(transformedSource, contains('abstract class \$FooStateMixin {}'));
424+
expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin {}'));
425+
});
426+
427+
test('with type parameters', () {
428+
preservedLineNumbersTest('''
429+
@StateMixin() class FooStateMixin<T extends Iterable<T>, U> {
430+
Map get state;
431+
432+
List<T> bar;
433+
U baz;
434+
}
435+
''');
436+
437+
expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin<T extends Iterable<T>, U> {}'));
438+
});
411439
});
412440

413441
test('abstract props classes', () {

0 commit comments

Comments
 (0)