groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/2] incubator-groovy git commit: GROOVY-7672: TupleConstructor should have only SOURCE retention policy (additional doco)
Date Sat, 14 Nov 2015 02:08:55 GMT
GROOVY-7672: TupleConstructor should have only SOURCE retention policy (additional doco)


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/e3e9d41a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/e3e9d41a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/e3e9d41a

Branch: refs/heads/master
Commit: e3e9d41a277a76c12bff8ad51dbb6fb228ff5302
Parents: 60194df
Author: paulk <paulk@asert.com.au>
Authored: Fri Nov 13 21:05:12 2015 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Sat Nov 14 12:08:16 2015 +1000

----------------------------------------------------------------------
 src/spec/doc/core-metaprogramming.adoc          | 16 +++++++
 .../test/CodeGenerationASTTransformsTest.groovy | 45 ++++++++++++++++++++
 2 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e3e9d41a/src/spec/doc/core-metaprogramming.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-metaprogramming.adoc b/src/spec/doc/core-metaprogramming.adoc
index 87733dc..0b7a853 100644
--- a/src/spec/doc/core-metaprogramming.adoc
+++ b/src/spec/doc/core-metaprogramming.adoc
@@ -966,6 +966,22 @@ include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=
 ----
 |=======================================================================
 
+Setting the `defaults` annotation attribute to `false` and the `force` annotation attribute
to `true` allows
+multiple tuple constructors to be created by using different customization options for the
different cases
+(provided each case has a different type signature) as shown in the following example:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=tupleconstructor_example_defaults_multiple,indent=0]
+----
+
+Similarly, here is another example using different options for `includes`:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=tupleconstructor_example_defaults_multipleIncludes,indent=0]
+----
+
 [[xform-MapConstructor]]
 ===== @groovy.transform.MapConstructor
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e3e9d41a/src/spec/test/CodeGenerationASTTransformsTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/CodeGenerationASTTransformsTest.groovy b/src/spec/test/CodeGenerationASTTransformsTest.groovy
index 381111b..8bdbd75 100644
--- a/src/spec/test/CodeGenerationASTTransformsTest.groovy
+++ b/src/spec/test/CodeGenerationASTTransformsTest.groovy
@@ -579,6 +579,51 @@ assert new Musician('Jimi', 'Guitar', 1942).toString() == 'Musician(Jimi,
Guitar
 assert Musician.constructors.size() == 1
 // end::tupleconstructor_example_defaults_false[]
 '''
+
+        assertScript '''
+import groovy.transform.*
+// tag::tupleconstructor_example_defaults_multiple[]
+class Named {
+  String name
+}
+
+@ToString(includeSuperProperties=true, ignoreNulls=true, includeNames=true, includeFields=true)
+@TupleConstructor(force=true, defaults=false)
+@TupleConstructor(force=true, defaults=false, includeFields=true)
+@TupleConstructor(force=true, defaults=false, includeSuperProperties=true)
+class Book extends Named {
+  Integer published
+  private Boolean fiction
+  Book() {}
+}
+
+assert new Book("Regina", 2015).toString() == 'Book(published:2015, name:Regina)'
+assert new Book(2015, false).toString() == 'Book(published:2015, fiction:false)'
+assert new Book(2015).toString() == 'Book(published:2015)'
+assert new Book().toString() == 'Book()'
+assert Book.constructors.size() == 4
+// end::tupleconstructor_example_defaults_multiple[]
+'''
+
+        assertScript '''
+import groovy.transform.*
+// tag::tupleconstructor_example_defaults_multipleIncludes[]
+@ToString(includeSuperProperties=true, ignoreNulls=true, includeNames=true, includeFields=true)
+@TupleConstructor(force=true, defaults=false, includes='name,year')
+@TupleConstructor(force=true, defaults=false, includes='year,fiction')
+@TupleConstructor(force=true, defaults=false, includes='name,fiction')
+class Book {
+    String name
+    Integer year
+    Boolean fiction
+}
+
+assert new Book("Regina", 2015).toString() == 'Book(name:Regina, year:2015)'
+assert new Book(2015, false).toString() == 'Book(year:2015, fiction:false)'
+assert new Book("Regina", false).toString() == 'Book(name:Regina, fiction:false)'
+assert Book.constructors.size() == 3
+// end::tupleconstructor_example_defaults_multipleIncludes[]
+'''
     }
 
     void testMapConstructor() {


Mime
View raw message