groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/2] groovy git commit: GROOVY-7853: o.c.g.r.t.DefaultTypeTransformation does not apply the right toString on primitve arrays when transforming to String (don't use ShortTypeHandling)
Date Tue, 23 Aug 2016 03:51:45 GMT
GROOVY-7853: o.c.g.r.t.DefaultTypeTransformation does not apply the right toString on primitve
arrays when transforming to String (don't use ShortTypeHandling)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/eec3b1f3
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/eec3b1f3
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/eec3b1f3

Branch: refs/heads/master
Commit: eec3b1f3da081d62fdcaaa2b07a3547f4795bf7f
Parents: 20519b9
Author: paulk <paulk@asert.com.au>
Authored: Sun Jun 19 14:11:29 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Tue Aug 23 13:47:01 2016 +1000

----------------------------------------------------------------------
 .../typehandling/DefaultTypeTransformation.java |  2 +-
 .../runtime/typehandling/ShortTypeHandling.java | 20 ++++++++++--------
 .../groovy/swing/SwingBuilderTableTest.groovy   | 22 ++++++++++----------
 3 files changed, 23 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/eec3b1f3/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index c57d4d4..2f4d6da 100644
--- a/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -229,7 +229,7 @@ public class DefaultTypeTransformation {
         } else if (Collection.class.isAssignableFrom(type)) {
             return continueCastOnCollection(object, type);
         } else if (type == String.class) {
-            return ShortTypeHandling.castToString(object);
+            return InvokerHelper.toString(object);
         } else if (type == Character.class) {
             return ShortTypeHandling.castToChar(object);
         } else if (type == Boolean.class) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/eec3b1f3/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java b/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java
index b76f0b9..b06569d 100644
--- a/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java
+++ b/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java
@@ -41,15 +41,17 @@ public class ShortTypeHandling {
 
     public static String castToString(Object object) {
         if (object==null) return null;
-        if (object instanceof boolean[]) return Arrays.toString((boolean[])object);
-        if (object instanceof byte[]) return Arrays.toString((byte[])object);
-        if (object instanceof char[]) return new String((char[])object);
-        if (object instanceof double[]) return Arrays.toString((double[])object);
-        if (object instanceof float[]) return Arrays.toString((float[])object);
-        if (object instanceof int[]) return Arrays.toString((int[])object);
-        if (object instanceof long[]) return Arrays.toString((long[])object);
-        if (object instanceof short[]) return Arrays.toString((short[])object);
-        if (object instanceof Object[]) return Arrays.toString((Object[])object);
+        if (object.getClass().isArray()) {
+            if (object instanceof boolean[]) return Arrays.toString((boolean[])object);
+            if (object instanceof byte[]) return Arrays.toString((byte[])object);
+            if (object instanceof char[]) return new String((char[])object);
+            if (object instanceof double[]) return Arrays.toString((double[])object);
+            if (object instanceof float[]) return Arrays.toString((float[])object);
+            if (object instanceof int[]) return Arrays.toString((int[])object);
+            if (object instanceof long[]) return Arrays.toString((long[])object);
+            if (object instanceof short[]) return Arrays.toString((short[])object);
+            return Arrays.toString((Object[])object);
+        }
         return object.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/eec3b1f3/subprojects/groovy-swing/src/test/groovy/groovy/swing/SwingBuilderTableTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-swing/src/test/groovy/groovy/swing/SwingBuilderTableTest.groovy
b/subprojects/groovy-swing/src/test/groovy/groovy/swing/SwingBuilderTableTest.groovy
index 065955d..58c4399 100644
--- a/subprojects/groovy-swing/src/test/groovy/groovy/swing/SwingBuilderTableTest.groovy
+++ b/subprojects/groovy-swing/src/test/groovy/groovy/swing/SwingBuilderTableTest.groovy
@@ -314,7 +314,7 @@ class SwingBuilderTableTest extends GroovySwingTestCase {
                 t2ses = label(text: bind { table02.selectedElements })
             }
 
-            assert swing.t1e.text == '[{ATHLETEID=1, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20},
{ATHLETEID=2, FIRSTNAME=Sam, LASTNAME=Wilson, DATEOFBIRTH=1876-12-15}, {ATHLETEID=3, FIRSTNAME=Jessie,
LASTNAME=James, DATEOFBIRTH=1877-06-12}]'
+            assert swing.t1e.text == '[[ATHLETEID:1, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20],
[ATHLETEID:2, FIRSTNAME:Sam, LASTNAME:Wilson, DATEOFBIRTH:1876-12-15], [ATHLETEID:3, FIRSTNAME:Jessie,
LASTNAME:James, DATEOFBIRTH:1877-06-12]]'
             assert swing.t1se.text == null
             assert swing.t1ses.text == '[]'
 
@@ -323,25 +323,25 @@ class SwingBuilderTableTest extends GroovySwingTestCase {
             assert swing.t2ses.text == '[]'
 
             swing.table01.addRowSelectionInterval(0, 0)
-            assert swing.t1se.text == '{ATHLETEID=1, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20}'
-            assert swing.t1ses.text == '[{ATHLETEID=1, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20}]'
+            assert swing.t1se.text == '[ATHLETEID:1, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20]'
+            assert swing.t1ses.text == '[[ATHLETEID:1, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20]]'
 
             swing.table02.addRowSelectionInterval(0, 0)
-            assert swing.t2se.text == '{Athlete ID=1, First Name=Bob, Last Name=Jones, Date
Of Birth=1875-05-20}'
-            assert swing.t2ses.text == '[{Athlete ID=1, First Name=Bob, Last Name=Jones,
Date Of Birth=1875-05-20}]'
+            assert swing.t2se.text == '[Athlete ID:1, First Name:Bob, Last Name:Jones, Date
Of Birth:1875-05-20]'
+            assert swing.t2ses.text == '[[Athlete ID:1, First Name:Bob, Last Name:Jones,
Date Of Birth:1875-05-20]]'
 
             swing.table01.addRowSelectionInterval(2, 2)
-            assert swing.t1se.text == '{ATHLETEID=1, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20}'
-            assert swing.t1ses.text == '[{ATHLETEID=1, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20},
{ATHLETEID=3, FIRSTNAME=Jessie, LASTNAME=James, DATEOFBIRTH=1877-06-12}]'
+            assert swing.t1se.text == '[ATHLETEID:1, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20]'
+            assert swing.t1ses.text == '[[ATHLETEID:1, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20],
[ATHLETEID:3, FIRSTNAME:Jessie, LASTNAME:James, DATEOFBIRTH:1877-06-12]]'
 
             swing.table02.addRowSelectionInterval(2, 2)
-            assert swing.t2se.text == '{Athlete ID=1, First Name=Bob, Last Name=Jones, Date
Of Birth=1875-05-20}'
-            assert swing.t2ses.text == '[{Athlete ID=1, First Name=Bob, Last Name=Jones,
Date Of Birth=1875-05-20}, {Athlete ID=3, First Name=Jessie, Last Name=James, Date Of Birth=1877-06-12}]'
+            assert swing.t2se.text == '[Athlete ID:1, First Name:Bob, Last Name:Jones, Date
Of Birth:1875-05-20]'
+            assert swing.t2ses.text == '[[Athlete ID:1, First Name:Bob, Last Name:Jones,
Date Of Birth:1875-05-20], [Athlete ID:3, First Name:Jessie, Last Name:James, Date Of Birth:1877-06-12]]'
 
             swing.table01.model.setValueAt('x', 0, 0,)
             swing.table02.model.setValueAt('x', 0, 0)
-            //FIXME groovy default table model does not fire data cahgne events whe editing
throught he model.
-            //assert swing.t1e.text == '[{ATHLETEID=x, FIRSTNAME=Bob, LASTNAME=Jones, DATEOFBIRTH=1875-05-20},
{ATHLETEID=2, FIRSTNAME=Sam, LASTNAME=Wilson, DATEOFBIRTH=1876-12-15}, {ATHLETEID=3, FIRSTNAME=Jessie,
LASTNAME=James, DATEOFBIRTH=1877-06-12}]'
+            //FIXME groovy default table model does not fire data cahgne events when editing
through the model.
+            //assert swing.t1e.text == '[[ATHLETEID:x, FIRSTNAME:Bob, LASTNAME:Jones, DATEOFBIRTH:1875-05-20],
[ATHLETEID:2, FIRSTNAME:Sam, LASTNAME:Wilson, DATEOFBIRTH:1876-12-15], [ATHLETEID:3, FIRSTNAME:Jessie,
LASTNAME:James, DATEOFBIRTH:1877-06-12]]'
             assert swing.t2e.text == '[[x, Bob, Jones, 1875-05-20], [2, Sam, Wilson, 1876-12-15],
[3, Jessie, James, 1877-06-12]]'
         }
     }


Mime
View raw message