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/05 12:06:14 UTC
[1/5] groovy git commit: StringGroovyMethods: test more javadoc
examples
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_4_X c1dda9d86 -> e0d321ca6
StringGroovyMethods: test more javadoc examples
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/888a04d4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/888a04d4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/888a04d4
Branch: refs/heads/GROOVY_2_4_X
Commit: 888a04d4ba7495c097d6769876d9d2ec8be8f6dd
Parents: c1dda9d
Author: pascalschumacher <pa...@gmx.net>
Authored: Thu Mar 3 23:58:40 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 5 11:45:15 2016 +0100
----------------------------------------------------------------------
.../groovy/runtime/StringGroovyMethods.java | 172 +++++++++----------
1 file changed, 86 insertions(+), 86 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/888a04d4/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 262700c..67b0e40 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -843,18 +843,18 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* If the regex doesn't match, null will be returned.
* <p>
* For example, if the regex doesn't match the result is null:
- * <pre>
- * assert null == "New York, NY".find(/\d{5}/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY".find(/\d{5}/) == null
* </pre>
*
* If it does match, we get the matching string back:
- * <pre>
- * assert "10292" == "New York, NY 10292-0098".find(/\d{5}/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(/\d{5}/) == "10292"
* </pre>
*
* If we have capture groups in our expression, we still get back the full match
- * <pre>
- * assert "10292-0098" == "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(/(\d{5})-?(\d{4})/) == "10292-0098"
* </pre>
*
* @param self a CharSequence
@@ -887,19 +887,19 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* If the pattern doesn't match, null will be returned.
* <p>
* For example, if the pattern doesn't match the result is null:
- * <pre>
- * assert null == "New York, NY".find(~/\d{5}/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY".find(~/\d{5}/) == null
* </pre>
*
* If it does match, we get the matching string back:
- * <pre>
- * assert "10292" == "New York, NY 10292-0098".find(~/\d{5}/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(~/\d{5}/) == "10292"
* </pre>
*
* If we have capture groups in our expression, the groups are ignored and
* we get back the full match:
- * <pre>
- * assert "10292-0098" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/)
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) == "10292-0098"
* </pre>
* If you need to work with capture groups, then use the closure version
* of this method or use Groovy's matcher operators or use <tt>eachMatch</tt>.
@@ -923,47 +923,47 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* If the regex doesn't match, the closure will not be called and find will return null.
* <p>
* For example, if the pattern doesn't match, the result is null:
- * <pre>
- * assert null == "New York, NY".find(~/\d{5}/) { match -> return "-$match-"}
+ * <pre class="groovyTestCase">
+ * assert "New York, NY".find(~/\d{5}/) { match -> return "-$match-"} == null
* </pre>
*
* If it does match and we don't have any capture groups in our regex, there is a single parameter
* on the closure that the match gets passed to:
- * <pre>
- * assert "-10292-" == "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"}
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(~/\d{5}/) { match -> return "-$match-"} == "-10292-"
* </pre>
*
* If we have capture groups in our expression, our closure has one parameter for the match, followed by
* one for each of the capture groups:
- * <pre>
- * assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
* assert match == "10292-0098"
* assert zip == "10292"
* assert plusFour == "0098"
* return zip
- * }
+ * } == "10292"
* </pre>
* If we have capture groups in our expression, and our closure has one parameter,
* the closure will be passed an array with the first element corresponding to the whole match,
* followed by an element for each of the capture groups:
- * <pre>
- * assert "10292" == "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { match, zip, plusFour ->
+ * <pre class="groovyTestCase">
+ * assert "New York, NY 10292-0098".find(~/(\d{5})-?(\d{4})/) { array ->
* assert array[0] == "10292-0098"
* assert array[1] == "10292"
* assert array[2] == "0098"
* return array[1]
- * }
+ * } == "10292"
* </pre>
* If a capture group is optional, and doesn't match, then the corresponding value
* for that capture group passed to the closure will be null as illustrated here:
- * <pre>
- * assert "2339999" == "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber ->
+ * <pre class="groovyTestCase">
+ * assert "adsf 233-9999 adsf".find(~/(\d{3})?-?(\d{3})-(\d{4})/) { match, areaCode, exchange, stationNumber ->
* assert "233-9999" == match
* assert null == areaCode
* assert "233" == exchange
* assert "9999" == stationNumber
* return "$exchange$stationNumber"
- * }
+ * } == "2339999"
* </pre>
*
* @param self a CharSequence
@@ -1030,13 +1030,13 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* Returns a (possibly empty) list of all occurrences of a regular expression (provided as a CharSequence) found within a CharSequence.
* <p>
* For example, if the regex doesn't match, it returns an empty list:
- * <pre>
- * assert [] == "foo".findAll(/(\w*) Fish/)
+ * <pre class="groovyTestCase">
+ * assert "foo".findAll(/(\w*) Fish/) == []
* </pre>
* Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
- * <pre>
+ * <pre class="groovyTestCase">
* def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"]
- * assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/)
+ * assert "One Fish, Two Fish, Red Fish, Blue Fish".findAll(/(\w*) Fish/) == expected
* </pre>
* If you need to work with capture groups, then use the closure version
* of this method or use Groovy's matcher operators or use <tt>eachMatch</tt>.
@@ -1058,17 +1058,17 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* If there are no matches, the closure will not be called, and an empty List will be returned.
* <p>
* For example, if the regex doesn't match, it returns an empty list:
- * <pre>
- * assert [] == "foo".findAll(/(\w*) Fish/) { match, firstWord -> return firstWord }
+ * <pre class="groovyTestCase">
+ * assert "foo".findAll(/(\w*) Fish/) { match, firstWord -> return firstWord } == []
* </pre>
* Any regular expression matches are passed to the closure, if there are no capture groups, there will be one parameter for the match:
- * <pre>
- * assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(/.ould/) { match -> "${match}n't"}
+ * <pre class="groovyTestCase">
+ * assert "I could not, would not, with a fox.".findAll(/.ould/) { match -> "${match}n't"} == ["couldn't", "wouldn't"]
* </pre>
* If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
- * <pre>
+ * <pre class="groovyTestCase">
* def orig = "There's a Wocket in my Pocket"
- * assert ["W > Wocket", "P > Pocket"] == orig.findAll(/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
+ * assert orig.findAll(/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" } == ["W > Wocket", "P > Pocket"]
* </pre>
*
* @param self a CharSequence
@@ -1086,13 +1086,13 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* Returns a (possibly empty) list of all occurrences of a regular expression (in Pattern format) found within a CharSequence.
* <p>
* For example, if the pattern doesn't match, it returns an empty list:
- * <pre>
- * assert [] == "foo".findAll(~/(\w*) Fish/)
+ * <pre class="groovyTestCase">
+ * assert "foo".findAll(~/(\w*) Fish/) == []
* </pre>
* Any regular expression matches are returned in a list, and all regex capture groupings are ignored, only the full match is returned:
- * <pre>
+ * <pre class="groovyTestCase">
* def expected = ["One Fish", "Two Fish", "Red Fish", "Blue Fish"]
- * assert expected == "One Fish, Two Fish, Red Fish, Blue Fish".findAll(~/(\w*) Fish/)
+ * assert "One Fish, Two Fish, Red Fish, Blue Fish".findAll(~/(\w*) Fish/) == expected
* </pre>
*
* @param self a CharSequence
@@ -1123,18 +1123,18 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* If there are no matches, the closure will not be called, and an empty List will be returned.
* <p>
* For example, if the pattern doesn't match, it returns an empty list:
- * <pre>
- * assert [] == "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord }
+ * <pre class="groovyTestCase">
+ * assert "foo".findAll(~/(\w*) Fish/) { match, firstWord -> return firstWord } == []
* </pre>
* Any regular expression matches are passed to the closure, if there are no capture groups, there will be one
* parameter for the match:
- * <pre>
- * assert ["couldn't", "wouldn't"] == "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"}
+ * <pre class="groovyTestCase">
+ * assert "I could not, would not, with a fox.".findAll(~/.ould/) { match -> "${match}n't"} == ["couldn't", "wouldn't"]
* </pre>
* If there are capture groups, the first parameter will be the match followed by one parameter for each capture group:
- * <pre>
+ * <pre class="groovyTestCase">
* def orig = "There's a Wocket in my Pocket"
- * assert ["W > Wocket", "P > Pocket"] == orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" }
+ * assert orig.findAll(~/(.)ocket/) { match, firstLetter -> "$firstLetter > $match" } == ["W > Wocket", "P > Pocket"]
* </pre>
*
* @param self a CharSequence
@@ -1327,10 +1327,10 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
}
/**
- * Support the subscript operator, e.g. matcher[index], for a regex Matcher.
+ * Support the subscript operator, e.g. matcher[index], for a regex Matcher.
* <p>
* For an example using no group match,
- * <pre>
+ * <pre class="groovyTestCase">
* def p = /ab[d|f]/
* def m = "abcabdabeabf" =~ p
* assert 2 == m.count
@@ -1339,12 +1339,12 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* assert 0 == m.groupCount()
* def matches = ["abd", "abf"]
* for (i in 0..<m.count) {
- *   assert m[i] == matches[i]
+ * assert m[i] == matches[i]
* }
* </pre>
* <p>
* For an example using group matches,
- * <pre>
+ * <pre class="groovyTestCase">
* def p = /(?:ab([c|d|e|f]))/
* def m = "abcabdabeabf" =~ p
* assert 4 == m.count
@@ -1352,19 +1352,19 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* assert 1 == m.groupCount()
* def matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]]
* for (i in 0..<m.count) {
- *   assert m[i] == matches[i]
+ * assert m[i] == matches[i]
* }
* </pre>
* <p>
* For another example using group matches,
- * <pre>
+ * <pre class="groovyTestCase">
* def m = "abcabdabeabfabxyzabx" =~ /(?:ab([d|x-z]+))/
* assert 3 == m.count
* assert m.hasGroup()
* assert 1 == m.groupCount()
* def matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]]
* for (i in 0..<m.count) {
- *   assert m[i] == matches[i]
+ * assert m[i] == matches[i]
* }
* </pre>
*
@@ -2473,22 +2473,22 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* Replaces all occurrences of a captured group by the result of a closure on that text.
* <p>
* For examples,
- * <pre>
- * assert "hellO wOrld" == "hello world".replaceAll("(o)") { it[0].toUpperCase() }
+ * <pre class="groovyTestCase">
+ * assert "hello world".replaceAll("(o)") { it[0].toUpperCase() } == "hellO wOrld"
*
- * assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() })
+ * assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) == "FOOBAR-FOOBAR-"
*
- * Here,
- * it[0] is the global string of the matched group
- * it[1] is the first string in the matched group
- * it[2] is the second string in the matched group
+ * // Here,
+ * // it[0] is the global string of the matched group
+ * // it[1] is the first string in the matched group
+ * // it[2] is the second string in the matched group
*
- * assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() })
+ * assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) == "FOO-FOO-"
*
- * Here,
- * x is the global string of the matched group
- * y is the first string in the matched group
- * z is the second string in the matched group
+ * // Here,
+ * // x is the global string of the matched group
+ * // y is the first string in the matched group
+ * // z is the second string in the matched group
* </pre>
* Note that unlike String.replaceAll(String regex, String replacement), where the replacement string
* treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string
@@ -2536,29 +2536,29 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* Replaces all occurrences of a captured group by the result of a closure call on that text.
* <p>
* For examples,
- * <pre>
- * assert "hellO wOrld" == "hello world".replaceAll(~"(o)") { it[0].toUpperCase() }
+ * <pre class="groovyTestCase">
+ * assert "hello world".replaceAll(~"(o)") { it[0].toUpperCase() } == "hellO wOrld"
*
- * assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { it[0].toUpperCase() })
+ * assert "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { it[0].toUpperCase() }) == "FOOBAR-FOOBAR-"
*
- * Here,
- * it[0] is the global string of the matched group
- * it[1] is the first string in the matched group
- * it[2] is the second string in the matched group
+ * // Here,
+ * // it[0] is the global string of the matched group
+ * // it[1] is the first string in the matched group
+ * // it[2] is the second string in the matched group
*
- * assert "FOOBAR-FOOBAR-" == "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() })
+ * assert "foobar-FooBar-".replaceAll(~"(([fF][oO]{2})[bB]ar)", { Object[] it -> it[0].toUpperCase() }) == "FOOBAR-FOOBAR-"
*
- * Here,
- * it[0] is the global string of the matched group
- * it[1] is the first string in the matched group
- * it[2] is the second string in the matched group
+ * // Here,
+ * // it[0] is the global string of the matched group
+ * // it[1] is the first string in the matched group
+ * // it[2] is the second string in the matched group
*
- * assert "FOO-FOO-" == "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() })
+ * assert "foobar-FooBar-".replaceAll("(([fF][oO]{2})[bB]ar)", { x, y, z -> z.toUpperCase() }) == "FOO-FOO-"
*
- * Here,
- * x is the global string of the matched group
- * y is the first string in the matched group
- * z is the second string in the matched group
+ * // Here,
+ * // x is the global string of the matched group
+ * // y is the first string in the matched group
+ * // z is the second string in the matched group
* </pre>
* Note that unlike String.replaceAll(String regex, String replacement), where the replacement string
* treats '$' and '\' specially (for group substitution), the result of the closure is converted to a string
@@ -3510,11 +3510,11 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* and so on for all provided replacement characters.
* <p>
* Here is an example which converts the vowels in a word from lower to uppercase:
- * <pre>
+ * <pre class="groovyTestCase">
* assert 'hello'.tr('aeiou', 'AEIOU') == 'hEllO'
* </pre>
* A character range using regex-style syntax can also be used, e.g. here is an example which converts a word from lower to uppercase:
- * <pre>
+ * <pre class="groovyTestCase">
* assert 'hello'.tr('a-z', 'A-Z') == 'HELLO'
* </pre>
* Hyphens at the start or end of sourceSet or replacementSet are treated as normal hyphens and are not
@@ -3523,15 +3523,15 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* the '-' character plus the 'e' character.
* <p>
* Unlike the unix tr command, Groovy's tr command supports reverse ranges, e.g.:
- * <pre>
+ * <pre class="groovyTestCase">
* assert 'hello'.tr('z-a', 'Z-A') == 'HELLO'
* </pre>
* If replacementSet is smaller than sourceSet, then the last character from replacementSet is used as the replacement for all remaining source characters as shown here:
- * <pre>
+ * <pre class="groovyTestCase">
* assert 'Hello World!'.tr('a-z', 'A') == 'HAAAA WAAAA!'
* </pre>
* If sourceSet contains repeated characters, the last specified replacement is used as shown here:
- * <pre>
+ * <pre class="groovyTestCase">
* assert 'Hello World!'.tr('lloo', '1234') == 'He224 W4r2d!'
* </pre>
* The functionality provided by tr can be achieved using regular expressions but tr provides a much more compact
[4/5] groovy git commit: test more javadoc code examples
Posted by pa...@apache.org.
test more javadoc code examples
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a9bfa54f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a9bfa54f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a9bfa54f
Branch: refs/heads/GROOVY_2_4_X
Commit: a9bfa54fc0c796a826a5e2fb93b5748f835a9a0d
Parents: 3d332f4
Author: pascalschumacher <pa...@gmx.net>
Authored: Fri Mar 4 20:57:43 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 5 11:57:48 2016 +0100
----------------------------------------------------------------------
src/main/groovy/lang/TracingInterceptor.java | 2 +-
.../groovy/transform/EqualsAndHashCode.java | 12 +++++----
src/main/groovy/transform/Field.java | 3 ++-
src/main/groovy/transform/Immutable.java | 6 ++---
src/main/groovy/transform/TailRecursive.groovy | 3 ++-
.../transform/builder/DefaultStrategy.java | 6 ++---
.../transform/builder/ExternalStrategy.java | 2 +-
.../transform/builder/SimpleStrategy.java | 2 +-
src/main/groovy/util/ConfigObject.java | 2 +-
src/main/groovy/util/Eval.java | 26 ++++++++++----------
.../ast/expr/ElvisOperatorExpression.java | 2 +-
.../groovy/runtime/ComposedClosure.java | 2 +-
.../codehaus/groovy/runtime/CurriedClosure.java | 2 +-
.../groovy/runtime/DefaultGroovyMethods.java | 2 +-
.../groovy/runtime/StringGroovyMethods.java | 10 ++++----
15 files changed, 43 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/lang/TracingInterceptor.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/TracingInterceptor.java b/src/main/groovy/lang/TracingInterceptor.java
index 5a5a1ab..f67de11 100644
--- a/src/main/groovy/lang/TracingInterceptor.java
+++ b/src/main/groovy/lang/TracingInterceptor.java
@@ -32,7 +32,7 @@ import java.io.Writer;
* of two spaces is written.
* <p>
* Here is an example usage on the ArrayList object: <br>
- * <pre>
+ * <pre class="groovyTestCase">
* def proxy = ProxyMetaClass.getInstance(ArrayList.class)
* proxy.interceptor = new TracingInterceptor()
* proxy.use {
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/EqualsAndHashCode.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/EqualsAndHashCode.java b/src/main/groovy/transform/EqualsAndHashCode.java
index c1bb954..f572549 100644
--- a/src/main/groovy/transform/EqualsAndHashCode.java
+++ b/src/main/groovy/transform/EqualsAndHashCode.java
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
* Class annotation used to assist in creating appropriate {@code equals()} and {@code hashCode()} methods.
* <p>
* It allows you to write classes in this shortened form:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.EqualsAndHashCode
* {@code @EqualsAndHashCode}
* class Person {
@@ -83,7 +83,8 @@ import java.lang.annotation.Target;
* to be used in limited cases where its purpose is for overriding implementation details rather than
* creating a derived type with different behavior. This is useful when using JPA Proxies for example or
* as shown in the following examples:
- * <pre>
+ * <pre class="groovyTestCase">
+ * import groovy.transform.*
* {@code @Canonical} class IntPair { int x, y }
* def p1 = new IntPair(1, 2)
*
@@ -107,7 +108,8 @@ import java.lang.annotation.Target;
* <code>equals</code> and <code>canEqual</code> method. The easiest way to
* achieve this would be to use the {@code @Canonical} or
* {@code @EqualsAndHashCode} annotations as shown below:
- * <pre>
+ * <pre class="groovyTestCase">
+ * import groovy.transform.*
* {@code @EqualsAndHashCode}
* {@code @TupleConstructor(includeSuperProperties=true)}
* class IntTriple extends IntPair { int z }
@@ -159,7 +161,7 @@ import java.lang.annotation.Target;
* </pre>
* There is also support for including or excluding fields/properties by name when constructing
* the equals and hashCode methods as shown here:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.*
* {@code @EqualsAndHashCode}(excludes="z")
* {@code @TupleConstructor}
@@ -172,7 +174,7 @@ import java.lang.annotation.Target;
*
* {@code @EqualsAndHashCode}(excludes=["y", "z"])
* {@code @TupleConstructor}
- * public class Point2D {
+ * public class Point1D {
* int x, y, z
* }
*
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/Field.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Field.java b/src/main/groovy/transform/Field.java
index 0a89817..546d045 100644
--- a/src/main/groovy/transform/Field.java
+++ b/src/main/groovy/transform/Field.java
@@ -31,7 +31,8 @@ import java.lang.annotation.Target;
* <p>
* The annotated variable will become a private field of the script class.
* The type of the field will be the same as the type of the variable. Example usage:
- * <pre>
+ * <pre class="groovyTestCase">
+ * import groovy.transform.Field
* {@code @Field} List awe = [1, 2, 3]
* def awesum() { awe.sum() }
* assert awesum() == 6
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/Immutable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Immutable.java b/src/main/groovy/transform/Immutable.java
index 20a1034..d0567e6 100644
--- a/src/main/groovy/transform/Immutable.java
+++ b/src/main/groovy/transform/Immutable.java
@@ -29,8 +29,8 @@ import java.lang.annotation.Target;
* Class annotation used to assist in the creation of immutable classes.
* <p>
* It allows you to write classes in this shortened form:
- * <pre>
- * {@code @Immutable} class Customer {
+ * <pre class="groovyTestCase">
+ * {@code @groovy.transform.Immutable} class Customer {
* String first, last
* int age
* Date since
@@ -224,7 +224,7 @@ public @interface Immutable {
* new property values and returns a new instance of the Immutable class with
* these values set.
* Example:
- * <pre>
+ * <pre class="groovyTestCase">
* {@code @groovy.transform.Immutable}(copyWith = true)
* class Person {
* String first, last
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/TailRecursive.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/TailRecursive.groovy b/src/main/groovy/transform/TailRecursive.groovy
index 0c9b6cf..e2bea42 100644
--- a/src/main/groovy/transform/TailRecursive.groovy
+++ b/src/main/groovy/transform/TailRecursive.groovy
@@ -30,7 +30,8 @@ import java.lang.annotation.Target
* since the JVM cannot do this itself. This works for both static and non-static methods.
* <p/>
* It allows you to write a method like this:
- * <pre>
+ * <pre class="groovyTestCase">
+ * import groovy.transform.TailRecursive
* class Target {
* {@code @TailRecursive}
* long sumUp(long number, long sum = 0) {
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/builder/DefaultStrategy.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/builder/DefaultStrategy.java b/src/main/groovy/transform/builder/DefaultStrategy.java
index 2cb6922..2f81e0f 100644
--- a/src/main/groovy/transform/builder/DefaultStrategy.java
+++ b/src/main/groovy/transform/builder/DefaultStrategy.java
@@ -67,7 +67,7 @@ import static org.objectweb.asm.Opcodes.ACC_STATIC;
* static method or constructor levels.
*
* You use it as follows:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.builder.*
*
* {@code @Builder}
@@ -99,7 +99,7 @@ import static org.objectweb.asm.Opcodes.ACC_STATIC;
*
* You can also use the {@code @Builder} annotation in combination with this strategy on one or more constructor or
* static method instead of or in addition to using it at the class level. An example with a constructor follows:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.ToString
* import groovy.transform.builder.Builder
*
@@ -127,7 +127,7 @@ import static org.objectweb.asm.Opcodes.ACC_STATIC;
* have unique names. E.g. we can modify the previous example to have three builders. At least two of the builders
* in our case will need to set the 'builderClassName' and 'builderMethodName' annotation attributes to ensure
* we have unique names. This is shown in the following example:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.builder.*
* import groovy.transform.*
*
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/builder/ExternalStrategy.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/builder/ExternalStrategy.java b/src/main/groovy/transform/builder/ExternalStrategy.java
index dcef7b2..2ee983d 100644
--- a/src/main/groovy/transform/builder/ExternalStrategy.java
+++ b/src/main/groovy/transform/builder/ExternalStrategy.java
@@ -60,7 +60,7 @@ import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
*
* You use it by creating and annotating an explicit builder class which will be filled in by during
* annotation processing with the appropriate build method and setters. An example is shown here:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.builder.*
*
* class Person {
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/transform/builder/SimpleStrategy.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/builder/SimpleStrategy.java b/src/main/groovy/transform/builder/SimpleStrategy.java
index ddd87a1..45dc1a1 100644
--- a/src/main/groovy/transform/builder/SimpleStrategy.java
+++ b/src/main/groovy/transform/builder/SimpleStrategy.java
@@ -47,7 +47,7 @@ import static org.codehaus.groovy.transform.BuilderASTTransformation.NO_EXCEPTIO
* setter methods for properties return the original object, thus allowing chained usage of the setters.
*
* You use it as follows:
- * <pre>
+ * <pre class="groovyTestCase">
* import groovy.transform.builder.*
*
* {@code @Builder}(builderStrategy=SimpleStrategy)
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/util/ConfigObject.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/ConfigObject.java b/src/main/groovy/util/ConfigObject.java
index 24220cd..a9e2803 100644
--- a/src/main/groovy/util/ConfigObject.java
+++ b/src/main/groovy/util/ConfigObject.java
@@ -372,7 +372,7 @@ public class ConfigObject extends GroovyObjectSupport implements Writable, Map,
/**
* Checks if a config option is set. Example usage:
- * <pre>
+ * <pre class="groovyTestCase">
* def config = new ConfigSlurper().parse("foo { password='' }")
* assert config.foo.isSet('password')
* assert config.foo.isSet('username') == false
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/groovy/util/Eval.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/Eval.java b/src/main/groovy/util/Eval.java
index 930337d..0330108 100644
--- a/src/main/groovy/util/Eval.java
+++ b/src/main/groovy/util/Eval.java
@@ -29,9 +29,9 @@ import groovy.lang.GroovyShell;
* This class is a simple helper on top of GroovyShell. You can use it to evaluate small
* Groovy scripts that don't need large Binding objects. For example, this script
* executes with no errors:
- * <pre>
- * assert 10 == Eval.me(' 2 * 4 + 2')
- * assert 10 == Eval.x(2, ' x * 4 + 2')
+ * <pre class="groovyTestCase">
+ * assert Eval.me(' 2 * 4 + 2') == 10
+ * assert Eval.x(2, ' x * 4 + 2') == 10
* </pre>
*
* @see GroovyShell
@@ -41,8 +41,8 @@ import groovy.lang.GroovyShell;
public class Eval {
/**
* Evaluates the specified String expression and returns the result. For example:
- * <pre>
- * assert 10 == Eval.me(' 2 * 4 + 2')
+ * <pre class="groovyTestCase">
+ * assert Eval.me(' 2 * 4 + 2') == 10
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
@@ -55,8 +55,8 @@ public class Eval {
/**
* Evaluates the specified String expression and makes the parameter available inside
* the script, returning the result. For example, this code binds the 'x' variable:
- * <pre>
- * assert 10 == Eval.me('x', 2, ' x * 4 + 2')
+ * <pre class="groovyTestCase">
+ * assert Eval.me('x', 2, ' x * 4 + 2') == 10
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
@@ -73,8 +73,8 @@ public class Eval {
* Evaluates the specified String expression and makes the parameter available inside
* the script bound to a variable named 'x', returning the result. For example, this
* code executes without failure:
- * <pre>
- * assert 10 == Eval.x(2, ' x * 4 + 2')
+ * <pre class="groovyTestCase">
+ * assert Eval.x(2, ' x * 4 + 2') == 10
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
@@ -88,8 +88,8 @@ public class Eval {
* Evaluates the specified String expression and makes the first two parameters available inside
* the script bound to variables named 'x' and 'y' respectively, returning the result. For example,
* this code executes without failure:
- * <pre>
- * assert 10 == Eval.xy(2, 4, ' x * y + 2')
+ * <pre class="groovyTestCase">
+ * assert Eval.xy(2, 4, ' x * y + 2') == 10
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
@@ -107,8 +107,8 @@ public class Eval {
* Evaluates the specified String expression and makes the first three parameters available inside
* the script bound to variables named 'x', 'y', and 'z' respectively, returning the result. For
* example, this code executes without failure:
- * <pre>
- * assert 10 == Eval.xyz(2, 4, 2, ' x * y + z')
+ * <pre class="groovyTestCase">
+ * assert Eval.xyz(2, 4, 2, ' x * y + z') == 10
* </pre>
* @param expression the Groovy expression to evaluate
* @return the result of the expression
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/org/codehaus/groovy/ast/expr/ElvisOperatorExpression.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/expr/ElvisOperatorExpression.java b/src/main/org/codehaus/groovy/ast/expr/ElvisOperatorExpression.java
index e794fb5..64df749 100644
--- a/src/main/org/codehaus/groovy/ast/expr/ElvisOperatorExpression.java
+++ b/src/main/org/codehaus/groovy/ast/expr/ElvisOperatorExpression.java
@@ -30,7 +30,7 @@ import org.codehaus.groovy.ast.GroovyCodeVisitor;
* </pre>
* Even if x is no atomic expression, x will be evaluated only
* once. Example:
- * <pre>
+ * <pre class="groovyTestCase">
* class Foo {
* def index=0
* def getX(){ index++; return index }
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/org/codehaus/groovy/runtime/ComposedClosure.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ComposedClosure.java b/src/main/org/codehaus/groovy/runtime/ComposedClosure.java
index dd56389..948ce09 100644
--- a/src/main/org/codehaus/groovy/runtime/ComposedClosure.java
+++ b/src/main/org/codehaus/groovy/runtime/ComposedClosure.java
@@ -28,7 +28,7 @@ import java.util.List;
* <code>leftShift()</code> methods on <code>Closure</code>.
* <p>
* Typical usages:
- * <pre>
+ * <pre class="groovyTestCase">
* def twice = { a -> a * 2 }
* def inc = { b -> b + 1 }
* def f = { x -> twice(inc(x)) } // longhand
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/CurriedClosure.java b/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
index 0deb990..964d4ba 100644
--- a/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
+++ b/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
@@ -25,7 +25,7 @@ import groovy.lang.Closure;
* Normally used only internally through the <code>curry()</code>, <code>rcurry()</code> or
* <code>ncurry()</code> methods on <code>Closure</code>.
* Typical usages:
- * <pre>
+ * <pre class="groovyTestCase">
* // normal usage
* def unitAdder = { first, second, unit -> "${first + second} $unit" }
* assert unitAdder(10, 15, "minutes") == "25 minutes"
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index f0fdd19..38bf5f1 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -206,7 +206,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* Any method invoked inside the closure will first be invoked on the
* self reference. For instance, the following method calls to the append()
* method are invoked on the StringBuilder instance:
- * <pre>
+ * <pre class="groovyTestCase">
* def b = new StringBuilder().with {
* append('foo')
* append('bar')
http://git-wip-us.apache.org/repos/asf/groovy/blob/a9bfa54f/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 67b0e40..f9523c8 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -2634,12 +2634,12 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
* Replaces the first occurrence of a captured group by the result of a closure call on that text.
* <p>
* For example (with some replaceAll variants thrown in for comparison purposes),
- * <pre>
- * assert "hellO world" == "hello world".replaceFirst("(o)") { it[0].toUpperCase() } // first match
- * assert "hellO wOrld" == "hello world".replaceAll("(o)") { it[0].toUpperCase() } // all matches
+ * <pre class="groovyTestCase">
+ * assert "hello world".replaceFirst("(o)") { it[0].toUpperCase() } == "hellO world" // first match
+ * assert "hello world".replaceAll("(o)") { it[0].toUpperCase() } == "hellO wOrld" // all matches
*
- * assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() }
- * assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() }
+ * assert "one fish, two fish".replaceFirst(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } == '1-FISH, two fish'
+ * assert "one fish, two fish".replaceAll(/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } == '1-FISH, 2-FISH'
* </pre>
*
* @param self a CharSequence
[3/5] 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/3d332f4d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3d332f4d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3d332f4d
Branch: refs/heads/GROOVY_2_4_X
Commit: 3d332f4da8ef1f5d5b28be2c17c8bb196bb18d72
Parents: 3d5ec1f
Author: Hubert Klein Ikkink <h....@gmail.com>
Authored: Thu Mar 3 23:48:12 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 5 11:55:47 2016 +0100
----------------------------------------------------------------------
src/main/groovy/transform/BaseScript.java | 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 +++----
11 files changed, 34 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/3d332f4d/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/3d332f4d/src/main/groovy/transform/EqualsAndHashCode.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/EqualsAndHashCode.java b/src/main/groovy/transform/EqualsAndHashCode.java
index 533df3b..c1bb954 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/3d332f4d/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/3d332f4d/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/3d332f4d/src/main/groovy/transform/InheritConstructors.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/InheritConstructors.java b/src/main/groovy/transform/InheritConstructors.java
index e544fcf..0de3603 100644
--- a/src/main/groovy/transform/InheritConstructors.java
+++ b/src/main/groovy/transform/InheritConstructors.java
@@ -105,7 +105,7 @@ 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.
* <p>More examples:</p>
- * <pre>
+ * <pre class="groovyTestCase">
* //--------------------------------------------------------------------------
* import groovy.transform.InheritConstructors
*
@@ -117,7 +117,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/3d332f4d/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/3d332f4d/src/main/groovy/transform/Sortable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Sortable.java b/src/main/groovy/transform/Sortable.java
index 6423e66..4bef99c 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/3d332f4d/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/3d332f4d/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/3d332f4d/src/main/groovy/transform/ToString.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/ToString.java b/src/main/groovy/transform/ToString.java
index 4b57b8e..1d64234 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/3d332f4d/src/main/groovy/transform/TupleConstructor.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/TupleConstructor.java b/src/main/groovy/transform/TupleConstructor.java
index bfb2918..479e47c 100644
--- a/src/main/groovy/transform/TupleConstructor.java
+++ b/src/main/groovy/transform/TupleConstructor.java
@@ -55,7 +55,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
*
@@ -76,7 +76,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
@@ -96,7 +96,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.
@@ -125,7 +125,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
[5/5] groovy git commit: deactivate running of javadoc example which
is just a partial example
Posted by pa...@apache.org.
deactivate running of javadoc example which is just a partial example
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e0d321ca
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e0d321ca
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e0d321ca
Branch: refs/heads/GROOVY_2_4_X
Commit: e0d321ca62b6ed814b265acfc8ae316dbf5fb22f
Parents: a9bfa54
Author: pascalschumacher <pa...@gmx.net>
Authored: Fri Mar 4 21:57:00 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 5 11:57:58 2016 +0100
----------------------------------------------------------------------
src/main/groovy/transform/EqualsAndHashCode.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/e0d321ca/src/main/groovy/transform/EqualsAndHashCode.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/EqualsAndHashCode.java b/src/main/groovy/transform/EqualsAndHashCode.java
index f572549..01d911f 100644
--- a/src/main/groovy/transform/EqualsAndHashCode.java
+++ b/src/main/groovy/transform/EqualsAndHashCode.java
@@ -108,8 +108,7 @@ import java.lang.annotation.Target;
* <code>equals</code> and <code>canEqual</code> method. The easiest way to
* achieve this would be to use the {@code @Canonical} or
* {@code @EqualsAndHashCode} annotations as shown below:
- * <pre class="groovyTestCase">
- * import groovy.transform.*
+ * <pre>
* {@code @EqualsAndHashCode}
* {@code @TupleConstructor(includeSuperProperties=true)}
* class IntTriple extends IntPair { int z }
[2/5] groovy git commit: More examples for AST transformation classes
in Javadoc based on MrHak's Groovy Goodness blog posts
Posted by pa...@apache.org.
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/3d5ec1f6
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3d5ec1f6
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3d5ec1f6
Branch: refs/heads/GROOVY_2_4_X
Commit: 3d5ec1f621a4b7710522ba8c1715cd4c4f9ff323
Parents: 888a04d
Author: Hubert Klein Ikkink <h....@gmail.com>
Authored: Thu Mar 3 16:39:08 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 5 11:55:06 2016 +0100
----------------------------------------------------------------------
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 +++++
6 files changed, 246 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/3d5ec1f6/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/3d5ec1f6/src/main/groovy/transform/InheritConstructors.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/InheritConstructors.java b/src/main/groovy/transform/InheritConstructors.java
index cd22173..e544fcf 100644
--- a/src/main/groovy/transform/InheritConstructors.java
+++ b/src/main/groovy/transform/InheritConstructors.java
@@ -104,6 +104,37 @@ import java.lang.annotation.Target;
* this AST transformation. This means that you can't override (i.e. not
* inherit) the constructors with signatures that Groovy adds later.
* If you get it wrong you will get a compile-time error about the duplication.
+ * <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/3d5ec1f6/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/3d5ec1f6/src/main/groovy/transform/Sortable.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/transform/Sortable.java b/src/main/groovy/transform/Sortable.java
index fa1c22f..6423e66 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/3d5ec1f6/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/3d5ec1f6/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