You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/01/16 00:57:00 UTC
[groovy] branch GROOVY_3_0_X updated (6280d6d -> 26adaa6)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 6280d6d Trivial refactoring: simplify code and extract common variable
new 22592e7 update broken link
new 26adaa6 Fix GROOVY-8966
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/main/java/groovy/lang/IntRange.java | 4 ++++
src/main/java/groovy/lang/NumberRange.java | 15 +++++++++++++++
.../groovy/runtime/DefaultGroovyMethodsSupport.java | 6 +++++-
src/spec/doc/design-pattern-decorator.adoc | 3 ++-
src/test/groovy/bugs/groovy8966/Groovy8966.groovy | 18 ++++++++++++++++++
5 files changed, 44 insertions(+), 2 deletions(-)
create mode 100644 src/test/groovy/bugs/groovy8966/Groovy8966.groovy
[groovy] 01/02: update broken link
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 22592e7964d07f5712d69728878063a8d9a401bd
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Jan 15 22:25:13 2020 +1000
update broken link
(cherry picked from commit 19e5a121382614e8462bc20a623c1ca08c270352)
---
src/spec/doc/design-pattern-decorator.adoc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/spec/doc/design-pattern-decorator.adoc b/src/spec/doc/design-pattern-decorator.adoc
index 4db3aee..d676d0f 100644
--- a/src/spec/doc/design-pattern-decorator.adoc
+++ b/src/spec/doc/design-pattern-decorator.adoc
@@ -227,7 +227,8 @@ You may have to adjust your `logging.properties` file for messages at log level
== Asynchronous Decorators using GPars
-Using the example code in http://www.cs.iastate.edu/~design/projects/panini/docs/starting.shtml[Panini] for inspiration. Here is a Groovy version that avoids using an `@AddedBehavior` annotation at the expense of not having as general an algorithm for selecting the methods to decorate. This isn't a limitation of the particular approach chosen but just a simplification for illustrative purposes (but don't assume below is an exact equivalent).
+The following example is inspired by some of the early example code for the http://design.cs.iastate.edu/~panini/[Panini] programming language.
+These days, you'll see this style used with async functions in JavaScript.
[source,groovy]
----
[groovy] 02/02: Fix GROOVY-8966
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 26adaa6edbed78b97f8c982e93e87959f07b228d
Author: Bo Zhang <zh...@gmail.com>
AuthorDate: Wed Jan 15 23:10:13 2020 +0800
Fix GROOVY-8966
Previously, when a exclusive NumberRange constructed from non-int type (e.g. long)
is used in List.getAt(), it will be incorrectly converted to inclusive. This commit
fixes this issue by introducing a subListBorders() method to NumberRange, which is
similar to IntRange.
(cherry picked from commit a46c601eadf6b06a850a8a6e27dda8d35c7263d4)
---
src/main/java/groovy/lang/IntRange.java | 4 ++++
src/main/java/groovy/lang/NumberRange.java | 15 +++++++++++++++
.../groovy/runtime/DefaultGroovyMethodsSupport.java | 6 +++++-
src/test/groovy/bugs/groovy8966/Groovy8966.groovy | 18 ++++++++++++++++++
4 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/src/main/java/groovy/lang/IntRange.java b/src/main/java/groovy/lang/IntRange.java
index 2cf80c4..8a1a172 100644
--- a/src/main/java/groovy/lang/IntRange.java
+++ b/src/main/java/groovy/lang/IntRange.java
@@ -223,6 +223,10 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer>, S
if (inclusive == null) {
throw new IllegalStateException("Should not call subListBorders on a non-inclusive aware IntRange");
}
+ return subListBorders(from, to, inclusive, size);
+ }
+
+ static RangeInfo subListBorders(int from, int to, boolean inclusive, int size) {
int tempFrom = from;
if (tempFrom < 0) {
tempFrom += size;
diff --git a/src/main/java/groovy/lang/NumberRange.java b/src/main/java/groovy/lang/NumberRange.java
index 3e1c6e3..f533a56 100644
--- a/src/main/java/groovy/lang/NumberRange.java
+++ b/src/main/java/groovy/lang/NumberRange.java
@@ -20,6 +20,7 @@ package groovy.lang;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.IteratorClosureAdapter;
+import org.codehaus.groovy.runtime.RangeInfo;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -178,6 +179,20 @@ public class NumberRange extends AbstractList<Comparable> implements Range<Compa
}
/**
+ * A method for determining from and to information when using this IntRange to index an aggregate object of the specified size.
+ * Normally only used internally within Groovy but useful if adding range indexing support for your own aggregates.
+ *
+ * @param size the size of the aggregate being indexed
+ * @return the calculated range information (with 1 added to the to value, ready for providing to subList
+ */
+ public RangeInfo subListBorders(int size) {
+ if (stepSize.intValue() != 1) {
+ throw new IllegalStateException("Step must be 1 when used by subList!");
+ }
+ return IntRange.subListBorders(((Number) from).intValue(), ((Number) to).intValue(), inclusive, size);
+ }
+
+ /**
* For a NumberRange with step size 1, creates a new NumberRange with the same
* <code>from</code> and <code>to</code> as this NumberRange
* but with a step size of <code>stepSize</code>.
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
index 8681b58..43136d5 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.runtime;
import groovy.lang.EmptyRange;
import groovy.lang.IntRange;
+import groovy.lang.NumberRange;
import groovy.lang.Range;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
@@ -76,7 +77,10 @@ public class DefaultGroovyMethodsSupport {
// helper method for getAt and putAt
protected static RangeInfo subListBorders(int size, Range range) {
if (range instanceof IntRange) {
- return ((IntRange)range).subListBorders(size);
+ return ((IntRange) range).subListBorders(size);
+ }
+ if (range instanceof NumberRange) {
+ return ((NumberRange) range).subListBorders(size);
}
int from = normaliseIndex(DefaultTypeTransformation.intUnbox(range.getFrom()), size);
int to = normaliseIndex(DefaultTypeTransformation.intUnbox(range.getTo()), size);
diff --git a/src/test/groovy/bugs/groovy8966/Groovy8966.groovy b/src/test/groovy/bugs/groovy8966/Groovy8966.groovy
new file mode 100644
index 0000000..d2b8a82
--- /dev/null
+++ b/src/test/groovy/bugs/groovy8966/Groovy8966.groovy
@@ -0,0 +1,18 @@
+package groovy.bugs.groovy8966
+
+import groovy.test.GroovyTestCase
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+@CompileStatic
+final class Groovy8966 extends GroovyTestCase {
+ @Test
+ void test() {
+ assertScript '''
+ def array = [0, 1, 2]
+ int a = 2
+ long b = 3
+ assert array[a..<b] == [2]
+ '''
+ }
+}
\ No newline at end of file