You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/02/03 11:55:52 UTC

[3/3] groovy git commit: improve doco for @EqualsAndHashcode

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/0fc41487
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0fc41487
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0fc41487

Branch: refs/heads/GROOVY_2_5_X
Commit: 0fc414879ce2c83ae83d4b038c7292ea54b3fbd8
Parents: e242936
Author: paulk <pa...@asert.com.au>
Authored: Sat Feb 3 20:53:50 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sat Feb 3 21:55:35 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/0fc41487/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/0fc41487/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