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 2016/03/04 17:02:31 UTC
[1/2] groovy git commit: More examples for AST transformation classes
in Javadoc based on MrHak's Groovy Goodness blog posts
Repository: groovy
Updated Branches:
refs/heads/master 67cf7d53e -> c04484a66
More examples for AST transformation classes in Javadoc based on MrHak's Groovy Goodness blog posts
* Give readers of the Javadoc documentation more example code
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2b6a6397
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2b6a6397
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2b6a6397
Branch: refs/heads/master
Commit: 2b6a639736c017e66c86fdfffc1538d11a1e26c9
Parents: 67cf7d5
Author: Hubert Klein Ikkink <h....@gmail.com>
Authored: Thu Mar 3 16:39:08 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Fri Mar 4 17:01:00 2016 +0100
----------------------------------------------------------------------
src/main/groovy/transform/Canonical.groovy | 44 ++++++++++++
src/main/groovy/transform/IndexedProperty.java | 33 +++++++++
.../groovy/transform/InheritConstructors.java | 31 ++++++++
src/main/groovy/transform/Memoized.java | 39 ++++++++++
src/main/groovy/transform/Sortable.java | 75 ++++++++++++++++++++
src/main/groovy/transform/Synchronized.java | 50 +++++++++++++
src/main/groovy/transform/TailRecursive.groovy | 18 +++++
7 files changed, 290 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/Canonical.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Canonical.groovy b/src/main/groovy/transform/Canonical.groovy
index 637ddd5..10ddb6d 100644
--- a/src/main/groovy/transform/Canonical.groovy
+++ b/src/main/groovy/transform/Canonical.groovy
@@ -75,6 +75,50 @@ package groovy.transform
* <p>
* If you want similar functionality to what this annotation provides but also require immutability, see the
* {@code @}{@link Immutable} annotation.
+ *
+ * <p>More examples:</p>
+ * <pre>
+ * import groovy.transform.*
+ *
+ * @Canonical
+ * class Building {
+ * String name
+ * int floors
+ * boolean officeSpace
+ * }
+ *
+ * // Constructors are added.
+ * def officeSpace = new Building('Initech office', 1, true)
+ *
+ * // toString() added.
+ * assert officeSpace.toString() == 'Building(Initech office, 1, true)'
+ *
+ * // Default values are used if constructor
+ * // arguments are not assigned.
+ * def theOffice = new Building('Wernham Hogg Paper Company')
+ * assert theOffice.floors == 0
+ * theOffice.officeSpace = true
+ *
+ * def anotherOfficeSpace = new Building(name: 'Initech office', floors: 1, officeSpace: true)
+ *
+ * // equals() method is added.
+ * assert anotherOfficeSpace == officeSpace
+ *
+ * // equals() and hashCode() are added, so duplicate is not in Set.
+ * def offices = [officeSpace, anotherOfficeSpace, theOffice] as Set
+ * assert offices.size() == 2
+ * assert offices.name.join(',') == 'Initech office,Wernham Hogg Paper Company'
+ *
+ * @Canonical
+ * @ToString(excludes='age') // Customize one of the transformations.
+ * class Person {
+ * String name
+ * int age
+ * }
+ *
+ * def mrhaki = new Person('mrhaki', 37)
+ * assert mrhaki.toString() == 'Person(mrhaki)'
+ * </pre>
*
* @see groovy.transform.EqualsAndHashCode
* @see groovy.transform.ToString
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/IndexedProperty.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/IndexedProperty.java b/src/main/groovy/transform/IndexedProperty.java
index 89b2ce5..4d4daab 100644
--- a/src/main/groovy/transform/IndexedProperty.java
+++ b/src/main/groovy/transform/IndexedProperty.java
@@ -62,6 +62,39 @@ import java.lang.annotation.Target;
* visibility can be specified) or you will receive a compile-time error message.
* The normal Groovy property getters and setters will also be created.
* <p>
+ * <p>More examples:</p>
+ * <pre>
+ * import groovy.transform.IndexedProperty
+ *
+ * class Group {
+ * String name
+ * List members = []
+ * }
+ *
+ * class IndexedGroup {
+ * String name
+ * @IndexedProperty List members = []
+ * }
+ *
+ * def group = new Group(name: 'Groovy')
+ * group.members[0] = 'mrhaki'
+ * group.members[1] = 'Hubert'
+ * assert 2 == group.members.size()
+ * assert ['mrhaki', 'Hubert'] == group.members
+ *
+ * try {
+ * group.setMembers(0, 'hubert') // Not index property
+ * } catch (MissingMethodException e) {
+ * assert e
+ * }
+ *
+ * def indexedGroup = new IndexedGroup(name: 'Grails')
+ * indexedGroup.members[0] = 'mrhaki'
+ * indexedGroup.setMembers 1, 'Hubert'
+ * assert 2 == indexedGroup.members.size()
+ * assert 'mrhaki' == indexedGroup.getMembers(0)
+ * assert 'Hubert' == indexedGroup.members[1]
+ * </pre>
*
* @author Paul King
* @since 1.7.3
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/InheritConstructors.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/InheritConstructors.java b/src/main/groovy/transform/InheritConstructors.java
index fcac101..0206e06 100644
--- a/src/main/groovy/transform/InheritConstructors.java
+++ b/src/main/groovy/transform/InheritConstructors.java
@@ -111,6 +111,37 @@ import java.lang.annotation.Target;
* inherit) the constructors with signatures that Groovy adds later.
* If you get it wrong you will get a compile-time error about the duplication.</li>
* </ul>
+ * <p>More examples:</p>
+ * <pre>
+ * //--------------------------------------------------------------------------
+ * import groovy.transform.InheritConstructors
+ *
+ * @InheritConstructors
+ * class MyException extends Exception {
+ * }
+ *
+ * def e = new MyException()
+ * def e1 = new MyException('message') // Other constructors are available.
+ * assert 'message' == e1.message
+ * </pre>
+ * <pre>
+ * //--------------------------------------------------------------------------
+ * import groovy.transform.InheritConstructors
+
+ * class Person {
+ * String name
+ *
+ * Person(String name) {
+ * this.name = name
+ * }
+ * }
+ *
+ * @InheritConstructors
+ * class Child extends Person {}
+ *
+ * def child = new Child('Liam')
+ * assert 'Liam' == child.name
+ * </pre>
*
* @author Paul King
* @since 1.7.3
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/Memoized.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Memoized.java b/src/main/groovy/transform/Memoized.java
index eda9008..a1aa76c 100644
--- a/src/main/groovy/transform/Memoized.java
+++ b/src/main/groovy/transform/Memoized.java
@@ -86,6 +86,45 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* 5
* </pre>
*
+ * <p>More examples:</p>
+ * <pre>
+ * import groovy.transform.*
+ *
+ * // Script variable which is changed when increment()
+ * // method is invoked.
+ * // If cached method call is invoked then the value
+ * // of this variable will not change.
+ * @Field boolean incrementChange = false
+ *
+ * @Memoized
+ * int increment(int value) {
+ * incrementChange = true
+ * value + 1
+ * }
+ *
+ * // Invoke increment with argument 10.
+ * increment(10)
+ *
+ * // increment is invoked so incrementChange is true.
+ * assert incrementChange
+ *
+ * // Set incrementChange back to false.
+ * incrementChange = false
+ *
+ * // Invoke increment with argument 10.
+ * increment(10)
+ *
+ * // Now the cached method is used and
+ * // incrementChange is not changed.
+ * assert !incrementChange
+ *
+ * // Invoke increment with other argument value.
+ * increment(11)
+ *
+ * // increment is invoked so incrementChange is true.
+ * assert incrementChange
+ * </pre>
+ *
* @author Andrey Bloschetsov
*/
@java.lang.annotation.Documented
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/Sortable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Sortable.java b/src/main/groovy/transform/Sortable.java
index 744d016..9d6cb0d 100644
--- a/src/main/groovy/transform/Sortable.java
+++ b/src/main/groovy/transform/Sortable.java
@@ -47,6 +47,81 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* {@code comparatorByLast} and {@code comparatorByBorn}</li>
* </ul>
* The properties within the class must themselves be {@code Comparable} or {@code @Sortable}.
+ * <p>More examples:</p>
+ * <pre>
+ * //--------------------------------------------------------------------------
+ * import groovy.transform.Sortable
+ * import groovy.transform.ToString
+ *
+ * @Sortable
+ * @ToString
+ * class Course {
+ * // Order of properties determines priority when sorting
+ * String title
+ * Date beginDate
+ * Integer maxAttendees // int doesn't implement Comparable, so use Integer
+ * }
+ *
+ *
+ * final Course groovy = new Course(
+ * title: 'Groovy', beginDate: new Date() + 7, maxAttendees: 40)
+ * final Course groovy2 = new Course(
+ * title: 'Groovy', beginDate: new Date() + 2, maxAttendees: 50)
+ * final Course grails = new Course(
+ * title: 'Grails', beginDate: new Date() + 1, maxAttendees: 20)
+ *
+ *
+ * final List<Course> courses = [groovy, groovy2, grails]
+ * assert courses.last().title == 'Grails'
+ *
+ * // Use sort() method to sort
+ * final List<Course> sorted = courses.sort(false)
+ *
+ * assert sorted.first().title == 'Grails'
+ * assert sorted.last().title == 'Groovy'
+ * assert sorted.maxAttendees == [20, 50, 40]
+ * </pre>
+ * <pre>
+ * //--------------------------------------------------------------------------
+ * // Order of fields for includes determines priority when sorting
+ * @Sortable(includes = ['title', 'maxAttendees'])
+ * // Or @Sortable(excludes = ['beginDate'])
+ * @ToString
+ * class CourseSort {
+ * String title
+ * Date beginDate
+ * Integer maxAttendees
+ * }
+ *
+ * final Course groovy = new Course(
+ * title: 'Groovy', beginDate: new Date() + 7, maxAttendees: 40)
+ * final Course groovy2 = new Course(
+ * title: 'Groovy', beginDate: new Date() + 2, maxAttendees: 50)
+ * final Course grails = new Course(
+ * title: 'Grails', beginDate: new Date() + 1, maxAttendees: 20)
+ *
+ *
+ * final List<Course> courses = [groovy, groovy2, grails]
+ *
+ * // Use sort() method to sort
+ * final List<Course> sorted = courses.sort(false)
+ *
+ * assert sorted.first().title == 'Grails'
+ * assert sorted.last().title == 'Groovy'
+ * assert sorted.maxAttendees == [20, 40, 50]
+ * </pre>
+ * <pre>
+ * //--------------------------------------------------------------------------
+ * // Static methods to create comparators.
+ * final Comparator byMaxAttendees = Course.comparatorByMaxAttendees()
+ * final List<Course> sortedByMaxAttendees = courses.sort(false, byMaxAttendees)
+ *
+ * assert sortedByMaxAttendees.maxAttendees == [20, 40, 50]
+ * // beginDate is not used for sorting
+ * assert sortedByMaxAttendees[2].beginDate < sortedByMaxAttendees[1].beginDate
+ *
+ * assert Course.declaredMethods.name.findAll { it.startsWith('comparatorBy') } == ['comparatorByTitle', 'comparatorByMaxAttendees']
+ * </pre>
*
* @author Andres Almiray
* @author Paul King
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/Synchronized.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Synchronized.java b/src/main/groovy/transform/Synchronized.java
index 25c5198..1157e3b 100644
--- a/src/main/groovy/transform/Synchronized.java
+++ b/src/main/groovy/transform/Synchronized.java
@@ -104,6 +104,56 @@ import java.lang.annotation.Target;
* this pattern tend to use. This is because a new <code>Object</code> is NOT serializable, but
* a 0-size array is. Therefore, using {@code @Synchronized} will not prevent your
* object from being serialized.
+ * <p>More examples:</p>
+ * <pre>
+ * import groovy.transform.Synchronized
+ *
+ * class Util {
+ * private counter = 0
+ *
+ * private def list = ['Groovy']
+ *
+ * private Object listLock = new Object[0]
+ *
+ * @Synchronized
+ * void workOnCounter() {
+ * assert 0 == counter
+ * counter++
+ * assert 1 == counter
+ * counter --
+ * assert 0 == counter
+ * }
+ *
+ * @Synchronized('listLock')
+ * void workOnList() {
+ * assert 'Groovy' == list[0]
+ * list << 'Grails'
+ * assert 2 == list.size()
+ * list = list - 'Grails'
+ * assert 'Groovy' == list[0]
+ * }
+ * }
+ *
+ * def util = new Util()
+ * def tc1 = Thread.start {
+ * 100.times {
+ * util.workOnCounter()
+ * sleep 20
+ * util.workOnList()
+ * sleep 10
+ * }
+ * }
+ * def tc2 = Thread.start {
+ * 100.times {
+ * util.workOnCounter()
+ * sleep 10
+ * util.workOnList()
+ * sleep 15
+ * }
+ * }
+ * tc1.join()
+ * tc2.join()
+ * </pre>
*
* @author Paul King
* @since 1.7.3
http://git-wip-us.apache.org/repos/asf/groovy/blob/2b6a6397/src/main/groovy/transform/TailRecursive.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/TailRecursive.groovy b/src/main/groovy/transform/TailRecursive.groovy
index bf457a7..2a85159 100644
--- a/src/main/groovy/transform/TailRecursive.groovy
+++ b/src/main/groovy/transform/TailRecursive.groovy
@@ -57,6 +57,24 @@ import java.lang.annotation.Target
* <li>Non trivial continuation passing style examples do not work.
* <li>Probably many unrecognized edge cases.
* </ul>
+ *
+ * <p>More examples:</p>
+ * <pre>
+ * import groovy.transform.TailRecursive
+ *
+ * @TailRecursive
+ * long sizeOfList(list, counter = 0) {
+ * if (list.size() == 0) {
+ * counter
+ * } else {
+ * sizeOfList(list.tail(), counter + 1)
+ * }
+ * }
+ *
+ * // Without @TailRecursive a StackOverFlowError
+ * // is thrown.
+ * assert sizeOfList(1..10000) == 10000
+ * </pre>
*
* @author Johannes Link
* @since 2.3
[2/2] groovy git commit: Tested code snippets for AST transformation
Javadoc (closes #278)
Posted by pa...@apache.org.
Tested code snippets for AST transformation Javadoc (closes #278)
* Added CSS class groovyTestCase for code snippets, so they are automatically tested
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c04484a6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c04484a6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c04484a6
Branch: refs/heads/master
Commit: c04484a66e7601f02e41504c04fdf8292aa88c89
Parents: 2b6a639
Author: Hubert Klein Ikkink <h....@gmail.com>
Authored: Thu Mar 3 23:48:12 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Fri Mar 4 17:01:07 2016 +0100
----------------------------------------------------------------------
src/main/groovy/transform/BaseScript.java | 2 +-
src/main/groovy/transform/Canonical.groovy | 2 +-
.../groovy/transform/EqualsAndHashCode.java | 2 +-
src/main/groovy/transform/Immutable.java | 2 +-
src/main/groovy/transform/IndexedProperty.java | 2 +-
.../groovy/transform/InheritConstructors.java | 4 ++--
src/main/groovy/transform/Memoized.java | 2 +-
src/main/groovy/transform/Sortable.java | 22 +++++++++++---------
src/main/groovy/transform/Synchronized.java | 2 +-
src/main/groovy/transform/TailRecursive.groovy | 2 +-
src/main/groovy/transform/ToString.java | 18 ++++++++--------
src/main/groovy/transform/TupleConstructor.java | 8 +++----
12 files changed, 35 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/BaseScript.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/BaseScript.java b/src/main/groovy/transform/BaseScript.java
index af3e594..6bea56e 100644
--- a/src/main/groovy/transform/BaseScript.java
+++ b/src/main/groovy/transform/BaseScript.java
@@ -85,7 +85,7 @@ import java.lang.annotation.Target;
* the AST is currently implemented they are not accessible in the script body code.
* </p>
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* // Simple Car class to save state and distance.
* class Car {
* String state
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/Canonical.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Canonical.groovy b/src/main/groovy/transform/Canonical.groovy
index 10ddb6d..82d2fc2 100644
--- a/src/main/groovy/transform/Canonical.groovy
+++ b/src/main/groovy/transform/Canonical.groovy
@@ -77,7 +77,7 @@ package groovy.transform
* {@code @}{@link Immutable} annotation.
*
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.*
*
* @Canonical
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/EqualsAndHashCode.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/EqualsAndHashCode.java b/src/main/groovy/transform/EqualsAndHashCode.java
index 2c75279..634dbe9 100644
--- a/src/main/groovy/transform/EqualsAndHashCode.java
+++ b/src/main/groovy/transform/EqualsAndHashCode.java
@@ -193,7 +193,7 @@ import java.lang.annotation.Target;
* you have such structures.
* A future version of this transform may better handle some additional recursive scenarios.
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.EqualsAndHashCode
*
* @EqualsAndHashCode(includeFields=true)
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/Immutable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Immutable.java b/src/main/groovy/transform/Immutable.java
index 314abbc..20a1034 100644
--- a/src/main/groovy/transform/Immutable.java
+++ b/src/main/groovy/transform/Immutable.java
@@ -124,7 +124,7 @@ import java.lang.annotation.Target;
* </ul>
* <p>More examples:</p>
--------------------------------------------------------------------------------
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.*
*
* @Canonical
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/IndexedProperty.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/IndexedProperty.java b/src/main/groovy/transform/IndexedProperty.java
index 4d4daab..cf77d98 100644
--- a/src/main/groovy/transform/IndexedProperty.java
+++ b/src/main/groovy/transform/IndexedProperty.java
@@ -63,7 +63,7 @@ import java.lang.annotation.Target;
* The normal Groovy property getters and setters will also be created.
* <p>
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.IndexedProperty
*
* class Group {
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/InheritConstructors.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/InheritConstructors.java b/src/main/groovy/transform/InheritConstructors.java
index 0206e06..66a1e10 100644
--- a/src/main/groovy/transform/InheritConstructors.java
+++ b/src/main/groovy/transform/InheritConstructors.java
@@ -112,7 +112,7 @@ import java.lang.annotation.Target;
* If you get it wrong you will get a compile-time error about the duplication.</li>
* </ul>
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* import groovy.transform.InheritConstructors
*
@@ -124,7 +124,7 @@ import java.lang.annotation.Target;
* def e1 = new MyException('message') // Other constructors are available.
* assert 'message' == e1.message
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* import groovy.transform.InheritConstructors
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/Memoized.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Memoized.java b/src/main/groovy/transform/Memoized.java
index a1aa76c..9e1409d 100644
--- a/src/main/groovy/transform/Memoized.java
+++ b/src/main/groovy/transform/Memoized.java
@@ -87,7 +87,7 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* </pre>
*
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.*
*
* // Script variable which is changed when increment()
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/Sortable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Sortable.java b/src/main/groovy/transform/Sortable.java
index 9d6cb0d..45fe99f 100644
--- a/src/main/groovy/transform/Sortable.java
+++ b/src/main/groovy/transform/Sortable.java
@@ -48,7 +48,7 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* </ul>
* The properties within the class must themselves be {@code Comparable} or {@code @Sortable}.
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* import groovy.transform.Sortable
* import groovy.transform.ToString
@@ -74,20 +74,23 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* final List<Course> courses = [groovy, groovy2, grails]
* assert courses.last().title == 'Grails'
*
- * // Use sort() method to sort
- * final List<Course> sorted = courses.sort(false)
+ * // Use toSorted() method to sort
+ * final List<Course> sorted = courses.toSorted()
*
* assert sorted.first().title == 'Grails'
* assert sorted.last().title == 'Groovy'
* assert sorted.maxAttendees == [20, 50, 40]
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // Order of fields for includes determines priority when sorting
+ * import groovy.transform.Sortable
+ * import groovy.transform.ToString
+ *
* @Sortable(includes = ['title', 'maxAttendees'])
* // Or @Sortable(excludes = ['beginDate'])
* @ToString
- * class CourseSort {
+ * class Course {
* String title
* Date beginDate
* Integer maxAttendees
@@ -103,14 +106,13 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
*
* final List<Course> courses = [groovy, groovy2, grails]
*
- * // Use sort() method to sort
- * final List<Course> sorted = courses.sort(false)
+ * // Use toSorted() method to sort
+ * final List<Course> sorted = courses.toSorted()
*
* assert sorted.first().title == 'Grails'
* assert sorted.last().title == 'Groovy'
* assert sorted.maxAttendees == [20, 40, 50]
- * </pre>
- * <pre>
+ *
* //--------------------------------------------------------------------------
* // Static methods to create comparators.
* final Comparator byMaxAttendees = Course.comparatorByMaxAttendees()
@@ -120,7 +122,7 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass;
* // beginDate is not used for sorting
* assert sortedByMaxAttendees[2].beginDate < sortedByMaxAttendees[1].beginDate
*
- * assert Course.declaredMethods.name.findAll { it.startsWith('comparatorBy') } == ['comparatorByTitle', 'comparatorByMaxAttendees']
+ * assert Course.declaredMethods.name.findAll { it.startsWith('comparatorBy') }.toSorted() == ['comparatorByMaxAttendees', 'comparatorByTitle']
* </pre>
*
* @author Andres Almiray
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/Synchronized.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Synchronized.java b/src/main/groovy/transform/Synchronized.java
index 1157e3b..dc8867c 100644
--- a/src/main/groovy/transform/Synchronized.java
+++ b/src/main/groovy/transform/Synchronized.java
@@ -105,7 +105,7 @@ import java.lang.annotation.Target;
* a 0-size array is. Therefore, using {@code @Synchronized} will not prevent your
* object from being serialized.
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.Synchronized
*
* class Util {
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/TailRecursive.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/TailRecursive.groovy b/src/main/groovy/transform/TailRecursive.groovy
index 2a85159..0c9b6cf 100644
--- a/src/main/groovy/transform/TailRecursive.groovy
+++ b/src/main/groovy/transform/TailRecursive.groovy
@@ -59,7 +59,7 @@ import java.lang.annotation.Target
* </ul>
*
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.TailRecursive
*
* @TailRecursive
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/ToString.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/ToString.java b/src/main/groovy/transform/ToString.java
index 1d56f5f..16672a4 100644
--- a/src/main/groovy/transform/ToString.java
+++ b/src/main/groovy/transform/ToString.java
@@ -113,7 +113,7 @@ import java.lang.annotation.Target;
* my.company.NamedThing(name: Lassie)
* </pre>
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // Most simple implementation of toString.
* import groovy.transform.ToString
@@ -129,12 +129,12 @@ import java.lang.annotation.Target;
*
* assert person.toString() == 'Person(mrhaki, [Groovy, Java])'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // includeNames to output the names of the properties.
* import groovy.transform.ToString
*
- * @@ToString(includeNames=true)
+ * @ToString(includeNames=true)
* class Person {
* String name
* List likes
@@ -145,7 +145,7 @@ import java.lang.annotation.Target;
*
* assert person.toString() == 'Person(name:mrhaki, likes:[Groovy, Java])'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // includeFields to not only output properties, but also field values.
* import groovy.transform.ToString
@@ -182,7 +182,7 @@ import java.lang.annotation.Target;
*
* assert student.toString() == 'Student(courses:[IT, Business], super:Person(name:mrhaki, likes:[Groovy, Java]))'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // excludes active field and likes property from output
* import groovy.transform.ToString
@@ -198,7 +198,7 @@ import java.lang.annotation.Target;
*
* assert person.toString() == 'Person(name:mrhaki)'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // Don't include the package name in the output
* package com.mrhaki.blog.groovy
@@ -215,7 +215,7 @@ import java.lang.annotation.Target;
*
* assert course.toString() == 'Course(Groovy 101, 200)'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // Don't use properties with null value.
* package com.mrhaki.blog.groovy
@@ -232,14 +232,14 @@ import java.lang.annotation.Target;
*
* assert course.toString() == 'com.mrhaki.blog.groovy.Course(Groovy 101)'
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // Cache toString() result.
* package com.mrhaki.blog.groovy
*
* import groovy.transform.*
*
- * @@ToString(cache=true)
+ * @ToString(cache=true)
* class Course {
* String title
* Integer maxAttendees
http://git-wip-us.apache.org/repos/asf/groovy/blob/c04484a6/src/main/groovy/transform/TupleConstructor.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/TupleConstructor.java b/src/main/groovy/transform/TupleConstructor.java
index e472667..916028d 100644
--- a/src/main/groovy/transform/TupleConstructor.java
+++ b/src/main/groovy/transform/TupleConstructor.java
@@ -56,7 +56,7 @@ import java.lang.annotation.Target;
* by the fields of the class (if {@code includeFields} is set). Within each grouping the order
* is as attributes appear within the respective class.
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* import groovy.transform.TupleConstructor
*
@@ -77,7 +77,7 @@ import java.lang.annotation.Target;
* assert person.name == 'mrhaki'
* assert !person.likes
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // includeFields in the constructor creation.
* import groovy.transform.TupleConstructor
@@ -97,7 +97,7 @@ import java.lang.annotation.Target;
* assert person.likes == ['Groovy', 'Java']
* assert person.activated
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // use force attribute to force creation of constructor
* // even if we define our own constructors.
@@ -126,7 +126,7 @@ import java.lang.annotation.Target;
*
* assert person.activated
* </pre>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* // include properties and fields from super class.
* import groovy.transform.TupleConstructor