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 2015/10/29 03:42:52 UTC
incubator-groovy git commit: GROOVY-7616: Fix 'Illegal class name'
when collectEntries sees an array (closes #162)
Repository: incubator-groovy
Updated Branches:
refs/heads/master 7be5f9eb1 -> 24af0ede2
GROOVY-7616: Fix 'Illegal class name' when collectEntries sees an array (closes #162)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/24af0ede
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/24af0ede
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/24af0ede
Branch: refs/heads/master
Commit: 24af0ede22c8b1813a30392901507f30187f84a1
Parents: 7be5f9e
Author: Rahul Somasunderam <ra...@gmail.com>
Authored: Sun Oct 25 20:48:42 2015 -0700
Committer: paulk <pa...@asert.com.au>
Committed: Thu Oct 29 12:41:47 2015 +1000
----------------------------------------------------------------------
.../org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 6 ++++++
src/test/groovy/GroovyMethodsTest.groovy | 7 +++++++
2 files changed, 13 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/24af0ede/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 843a5bb..f03c9d3 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -3788,6 +3788,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
Object key = list.size() == 0 ? null : list.get(0);
Object value = list.size() <= 1 ? null : list.get(1);
leftShift(result, new MapEntry(key, value));
+ } else if (newEntry.getClass().isArray()) {
+ Object[] array = (Object[]) newEntry;
+ // def (key, value) == array.toList()
+ Object key = array.length == 0 ? null : array[0];
+ Object value = array.length <= 1 ? null : array[1];
+ leftShift(result, new MapEntry(key, value));
} else {
// TODO: enforce stricter behavior?
// given Map.Entry is an interface, we get a proxy which gives us lots
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/24af0ede/src/test/groovy/GroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GroovyMethodsTest.groovy b/src/test/groovy/GroovyMethodsTest.groovy
index 074a964..7ff340c 100644
--- a/src/test/groovy/GroovyMethodsTest.groovy
+++ b/src/test/groovy/GroovyMethodsTest.groovy
@@ -1471,6 +1471,13 @@ class GroovyMethodsTest extends GroovyTestCase {
}
}
+ void testCollectEntriesWithArray() {
+ def cityList = '1 San Francisco,2 Cupertino'
+ def cityMap = cityList.split(',').
+ collectEntries{ it.split(' ', 2) }
+ assert cityMap == ['1': 'San Francisco', '2': 'Cupertino']
+ }
+
void testListTakeWhile() {
def data = [
new ArrayList( [ 1, 3, 2 ] ),