[1/2] groovy git commit: Minor refactoring: move type data to `TypeUtil` and simplify `isArray` implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] groovy git commit: Minor refactoring: move type data to `TypeUtil` and simplify `isArray` implementation

Daniel.Sun
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 090db05f3 -> 17fe44d78


Minor refactoring: move type data to `TypeUtil` and simplify `isArray` implementation

(cherry picked from commit 20b2f3c)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 12468a48e82e3557e983dad54a006677a22cb78d
Parents: 090db05
Author: danielsun1106 <[hidden email]>
Authored: Sat Mar 10 01:54:25 2018 +0800
Committer: danielsun1106 <[hidden email]>
Committed: Sat Mar 10 03:04:13 2018 +0800

----------------------------------------------------------------------
 .../groovy/classgen/asm/util/TypeUtil.java      | 16 +++++++++++++
 .../groovy/reflection/ReflectionCache.java      | 25 ++++----------------
 2 files changed, 21 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/12468a48/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
index 483511d..23fbebc 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
@@ -140,6 +140,11 @@ public abstract class TypeUtil {
         return new Tuple2<ClassNode, Integer>(type, dimension);
     }
 
+    public static Class autoboxType(Class type) {
+        final Class res = PRIMITIVE_TYPE_TO_WRAPPED_CLASS_MAP.get(type);
+        return res == null ? type : res;
+    }
+
     private static final String REF_DESCRIPTION = "L";
     private static final Map<ClassNode, String> PRIMITIVE_TYPE_TO_DESCRIPTION_MAP = Maps.of(
             int_TYPE, "I",
@@ -197,4 +202,15 @@ public abstract class TypeUtil {
             Type.LONG_TYPE, "java/lang/Long",
             Type.SHORT_TYPE, "java/lang/Short"
     );
+
+    private static final Map<Class, Class> PRIMITIVE_TYPE_TO_WRAPPED_CLASS_MAP = Maps.of(
+        byte.class, Byte.class,
+        boolean.class, Boolean.class,
+        char.class, Character.class,
+        double.class, Double.class,
+        float.class, Float.class,
+        int.class, Integer.class,
+        long.class, Long.class,
+        short.class, Short.class
+    );
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/12468a48/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
index c9ea871..efedc95 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
@@ -18,28 +18,12 @@
  */
 package org.codehaus.groovy.reflection;
 
+import org.codehaus.groovy.classgen.asm.util.TypeUtil;
 import org.codehaus.groovy.util.TripleKeyHashMap;
 
-import java.util.HashMap;
-import java.util.Map;
-
 public class ReflectionCache {
-    private static final Map primitiveTypesMap = new HashMap();
-
-    static {
-        primitiveTypesMap.put(byte.class, Byte.class);
-        primitiveTypesMap.put(boolean.class, Boolean.class);
-        primitiveTypesMap.put(char.class, Character.class);
-        primitiveTypesMap.put(double.class, Double.class);
-        primitiveTypesMap.put(float.class, Float.class);
-        primitiveTypesMap.put(int.class, Integer.class);
-        primitiveTypesMap.put(long.class, Long.class);
-        primitiveTypesMap.put(short.class, Short.class);
-    }
-
     public static Class autoboxType(Class type) {
-        final Class res = (Class) primitiveTypesMap.get(type);
-        return res == null ? type : res;
+        return TypeUtil.autoboxType(type);
     }
 
     static TripleKeyHashMap mopNames = new TripleKeyHashMap();
@@ -55,10 +39,11 @@ public class ReflectionCache {
     static final CachedClass STRING_CLASS = getCachedClass(String.class);
 
     public static boolean isArray(Class klazz) {
-      return klazz.getName().charAt(0) == '[';
+      return klazz.isArray();
     }
 
     static void setAssignableFrom(Class klazz, Class aClass) {
+        // FIXME no implementation?
 //        SoftDoubleKeyMap.Entry val = (SoftDoubleKeyMap.Entry) assignableMap.getOrPut(klazz, aClass, null);
 //        if (val.getValue() == null) {
 //            val.setValue(Boolean.TRUE);
@@ -107,7 +92,7 @@ public class ReflectionCache {
         if (klazz == null)
           return null;
         
-        return ClassInfo.getClassInfo(klazz).getCachedClass ();
+        return ClassInfo.getClassInfo(klazz).getCachedClass();
     }
 
 }

Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

[2/2] groovy git commit: Trivial refactoring: simplify testing array type

Daniel.Sun
Trivial refactoring: simplify testing array type

(cherry picked from commit a8b9be9)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 17fe44d7893ed6c75f126b1dc442fc7d85f7962d
Parents: 12468a4
Author: danielsun1106 <[hidden email]>
Authored: Sat Mar 10 02:09:25 2018 +0800
Committer: danielsun1106 <[hidden email]>
Committed: Sat Mar 10 03:04:19 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/classgen/asm/util/TypeUtil.java   | 10 +++++-----
 .../java/org/codehaus/groovy/reflection/ClassInfo.java    |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/17fe44d7/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
index 23fbebc..9b79858 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeUtil.java
@@ -52,6 +52,11 @@ import static org.objectweb.asm.Opcodes.LRETURN;
  * @since 2.5.0
  */
 public abstract class TypeUtil {
+    public static Class autoboxType(Class type) {
+        final Class res = PRIMITIVE_TYPE_TO_WRAPPED_CLASS_MAP.get(type);
+        return res == null ? type : res;
+    }
+
     public static int getLoadInsnByType(Type type) {
         Integer insn = PRIMITIVE_TYPE_TO_LOAD_INSN_MAP.get(type);
 
@@ -140,11 +145,6 @@ public abstract class TypeUtil {
         return new Tuple2<ClassNode, Integer>(type, dimension);
     }
 
-    public static Class autoboxType(Class type) {
-        final Class res = PRIMITIVE_TYPE_TO_WRAPPED_CLASS_MAP.get(type);
-        return res == null ? type : res;
-    }
-
     private static final String REF_DESCRIPTION = "L";
     private static final Map<ClassNode, String> PRIMITIVE_TYPE_TO_DESCRIPTION_MAP = Maps.of(
             int_TYPE, "I",

http://git-wip-us.apache.org/repos/asf/groovy/blob/17fe44d7/src/main/java/org/codehaus/groovy/reflection/ClassInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/reflection/ClassInfo.java b/src/main/java/org/codehaus/groovy/reflection/ClassInfo.java
index b4dc133..c7abeff 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ClassInfo.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ClassInfo.java
@@ -384,7 +384,7 @@ public class ClassInfo implements Finalizable {
                 cachedClass = new CachedClass(klazz, classInfo);
             }
         } else {
-            if (klazz.getName().charAt(0) == '[')
+            if (klazz.isArray())
               cachedClass = new ArrayCachedClass(klazz, classInfo);
             else if (klazz == Boolean.class) {
                 cachedClass = new BooleanCachedClass(klazz, classInfo, true);

Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun