Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF-3731: Carry type parameters on generated empty prop/state mixins classes #220

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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