From 0988fe1d28e38d1b96f8951b6777a93e82612d63 Mon Sep 17 00:00:00 2001 From: Corwin Sheahan Date: Mon, 7 Jan 2019 13:46:38 -0700 Subject: [PATCH 1/2] Carry type parameters on generated empty prop/state mixins classes --- lib/src/transformer/impl_generation.dart | 4 +- .../transformer/impl_generation_test.dart | 68 +++++++++++++------ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/lib/src/transformer/impl_generation.dart b/lib/src/transformer/impl_generation.dart index a01af1654..520410dd8 100644 --- a/lib/src/transformer/impl_generation.dart +++ b/lib/src/transformer/impl_generation.dart @@ -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) { @@ -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 ?? ''} {}'); }); // ---------------------------------------------------------------------- diff --git a/test/vm_tests/transformer/impl_generation_test.dart b/test/vm_tests/transformer/impl_generation_test.dart index 597e55716..7fd93db04 100644 --- a/test/vm_tests/transformer/impl_generation_test.dart +++ b/test/vm_tests/transformer/impl_generation_test.dart @@ -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; - } - '''); + List 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 { + Map get props; + + List bar; + var baz; + } + '''); + + expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin {}')); + }); }); - 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 { + Map get state; + + List bar; + var baz; + } + '''); + + expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin {}')); + }); }); test('abstract props classes', () { From 8ba2e6d3d533a14fbe7e89b738ffa44c849f7605 Mon Sep 17 00:00:00 2001 From: Corwin Sheahan Date: Mon, 7 Jan 2019 14:02:57 -0700 Subject: [PATCH 2/2] make test more better --- .../vm_tests/transformer/impl_generation_test.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/vm_tests/transformer/impl_generation_test.dart b/test/vm_tests/transformer/impl_generation_test.dart index 7fd93db04..0d14479df 100644 --- a/test/vm_tests/transformer/impl_generation_test.dart +++ b/test/vm_tests/transformer/impl_generation_test.dart @@ -388,7 +388,7 @@ main() { @PropsMixin() class FooPropsMixin { Map get props; - List bar; + var bar; var baz; } '''); @@ -398,15 +398,15 @@ main() { test('with type parameters', () { preservedLineNumbersTest(''' - @PropsMixin() class FooPropsMixin { + @PropsMixin() class FooPropsMixin, U> { Map get props; List bar; - var baz; + U baz; } '''); - expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin {}')); + expect(transformedFile.getTransformedText(), contains('abstract class \$FooPropsMixin, U> {}')); }); }); @@ -426,15 +426,15 @@ main() { test('with type parameters', () { preservedLineNumbersTest(''' - @StateMixin() class FooStateMixin { + @StateMixin() class FooStateMixin, U> { Map get state; List bar; - var baz; + U baz; } '''); - expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin {}')); + expect(transformedFile.getTransformedText(), contains('abstract class \$FooStateMixin, U> {}')); }); });