Skip to content

Commit

Permalink
Merge pull request #220 from Workiva/AF-3731_carry_generics_on_mixins
Browse files Browse the repository at this point in the history
AF-3731: Carry type parameters on generated empty prop/state mixins classes
  • Loading branch information
rmconsole2-wf authored Jan 7, 2019
2 parents 014965f + 8ba2e6d commit eb1c1bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/src/transformer/impl_generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class ImplGenerator {
/// This is because with the builder compatible boilerplate, Props
/// and State mixin classes are renamed to include a $ prefix with the assumption that
/// the actual class with concrete accessor implementations will be generated.
transformedFile.insert(sourceFile.location(propMixin.node.end), ' abstract class \$${propMixin.node.name.name} {}');
transformedFile.insert(sourceFile.location(propMixin.node.end), ' abstract class \$${propMixin.node.name.name}${propMixin.node.typeParameters ?? ''} {}');
});

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

// ----------------------------------------------------------------------
Expand Down
68 changes: 48 additions & 20 deletions test/vm_tests/transformer/impl_generation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,32 +382,60 @@ main() {
});
});

test('props mixins', () {
preservedLineNumbersTest('''
@PropsMixin() class FooPropsMixin {
Map get props;
group('for props mixins', () {
test('without type parameters', () {
preservedLineNumbersTest('''
@PropsMixin() class FooPropsMixin {
Map get props;
var bar;
var baz;
}
''');
var bar;
var baz;
}
''');

var transformedSource = transformedFile.getTransformedText();
expect(transformedSource, contains('abstract class \$FooPropsMixin {}'));
expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin {}'));
});

test('with type parameters', () {
preservedLineNumbersTest('''
@PropsMixin() class FooPropsMixin<T extends Iterable<T>, U> {
Map get props;
List<T> bar;
U baz;
}
''');

expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin<T extends Iterable<T>, U> {}'));
});
});

test('state mixins', () {
preservedLineNumbersTest('''
@StateMixin() class FooStateMixin {
Map get state;
group('for state mixins', () {
test('without type parameters', () {
preservedLineNumbersTest('''
@StateMixin() class FooStateMixin {
Map get state;
var bar;
var baz;
}
''');
var bar;
var baz;
}
''');

var transformedSource = transformedFile.getTransformedText();
expect(transformedSource, contains('abstract class \$FooStateMixin {}'));
expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin {}'));
});

test('with type parameters', () {
preservedLineNumbersTest('''
@StateMixin() class FooStateMixin<T extends Iterable<T>, U> {
Map get state;
List<T> bar;
U baz;
}
''');

expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin<T extends Iterable<T>, U> {}'));
});
});

test('abstract props classes', () {
Expand Down

0 comments on commit eb1c1bf

Please sign in to comment.