groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [3/3] groovy git commit: improve doco for @EqualsAndHashcode
Date Sun, 04 Feb 2018 00:08:57 GMT
improve doco for @EqualsAndHashcode


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

Branch: refs/heads/GROOVY_2_6_X
Commit: dd278d61c26caa87aa2187bb4ba0ee4d136a3f1c
Parents: 7a294a0
Author: paulk <paulk@asert.com.au>
Authored: Sat Feb 3 20:53:50 2018 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Sun Feb 4 10:08:43 2018 +1000

----------------------------------------------------------------------
 src/spec/doc/core-metaprogramming.adoc          | 13 ++++++++----
 .../test/CodeGenerationASTTransformsTest.groovy | 21 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/dd278d61/src/spec/doc/core-metaprogramming.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-metaprogramming.adoc b/src/spec/doc/core-metaprogramming.adoc
index cd1cd00..94cca81 100644
--- a/src/spec/doc/core-metaprogramming.adoc
+++ b/src/spec/doc/core-metaprogramming.adoc
@@ -871,6 +871,11 @@ include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=
 ----
 include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_includes,indent=0]
 ----
+|cache|False|Cache the hashCode computation. Should only be set to true if the class is immutable.|
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_cache,indent=0]
+----
 |callSuper|False|Whether to include super in equals and hashCode calculations|
 [source,groovy]
 ----
@@ -881,13 +886,13 @@ include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=
 ----
 include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_includeFields,indent=0]
 ----
-|cache|False|Cache the hashCode computation. Should only be set to true if the class is immutable.|
+|useCanEqual|True|Should equals call canEqual helper method.|See http://www.artima.com/lejava/articles/equality.html
+|allProperties|False|Should JavaBean properties be included in equals and hashCode calculations|
 [source,groovy]
 ----
-include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_cache,indent=0]
+include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_allProperties,indent=0]
 ----
-|useCanEqual|True|Should equals call canEqual helper method.|See http://www.artima.com/lejava/articles/equality.html
-|allNames|False|Should fileds and/or properties with internal names be included in equals
and hashCode calculations|
+|allNames|False|Should fields and/or properties with internal names be included in equals
and hashCode calculations|
 [source,groovy]
 ----
 include::{projectdir}/src/spec/test/CodeGenerationASTTransformsTest.groovy[tags=equalshashcode_example_allNames,indent=0]

http://git-wip-us.apache.org/repos/asf/groovy/blob/dd278d61/src/spec/test/CodeGenerationASTTransformsTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/CodeGenerationASTTransformsTest.groovy b/src/spec/test/CodeGenerationASTTransformsTest.groovy
index 90c941e..f2bb2b7 100644
--- a/src/spec/test/CodeGenerationASTTransformsTest.groovy
+++ b/src/spec/test/CodeGenerationASTTransformsTest.groovy
@@ -334,6 +334,27 @@ assert p1.hashCode() != p2.hashCode()
 '''
 
         assertScript '''
+import groovy.transform.EqualsAndHashCode
+
+// tag::equalshashcode_example_allProperties[]
+@EqualsAndHashCode(allProperties=true, excludes='first, last')
+class Person {
+    String first, last
+    String getInitials() { first[0] + last[0] }
+}
+
+def p1 = new Person(first: 'Jack', last: 'Smith')
+def p2 = new Person(first: 'Jack', last: 'Spratt')
+def p3 = new Person(first: 'Bob', last: 'Smith')
+
+assert p1 == p2
+assert p1.hashCode() == p2.hashCode()
+assert p1 != p3
+assert p1.hashCode() != p3.hashCode()
+// end::equalshashcode_example_allProperties[]
+'''
+
+        assertScript '''
 // tag::equalshashcode_example_allNames[]
 import groovy.transform.EqualsAndHashCode
 


Mime
View raw message