groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/3] groovy git commit: Revert "Trivial refactoring: remove duplicated code of `ClassHelper` and fix typo"
Date Sun, 18 Feb 2018 11:49:43 GMT
Revert "Trivial refactoring: remove duplicated code of `ClassHelper` and fix typo"

This reverts commit d074aca


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

Branch: refs/heads/GROOVY_2_6_X
Commit: c77ed94d200709b0efdf2075bf160fc0dfe82ca2
Parents: d074aca
Author: danielsun1106 <realbluesun@hotmail.com>
Authored: Sun Feb 18 19:48:38 2018 +0800
Committer: danielsun1106 <realbluesun@hotmail.com>
Committed: Sun Feb 18 19:48:38 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/ast/ClassHelper.java    | 24 ++++++++------------
 .../classgen/asm/util/TypeDescriptionUtil.java  | 12 +++++-----
 2 files changed, 16 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c77ed94d/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index 7081b01..b81c969 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -45,11 +45,9 @@ import java.lang.ref.SoftReference;
 import java.lang.reflect.Modifier;
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.regex.Pattern;
 
 /**
@@ -71,12 +69,10 @@ public class ClassHelper {
             Iterator.class, GeneratedClosure.class, GeneratedLambda.class, GroovyObjectSupport.class
     };
 
-    private static final String[] PRIMITIVE_CLASS_NAMES;
-    static {
-        Set<String> primitiveClassNameSet = new HashSet<>(TypeDescriptionUtil.NAME_TO_PRIMITIVE_TYPE_MAP.keySet());
-        primitiveClassNameSet.add(""); // TODO confirm why should we need the empty string?
-        PRIMITIVE_CLASS_NAMES = primitiveClassNameSet.toArray(new String[0]);
-    }
+    private static final String[] primitiveClassNames = new String[]{
+            "", "boolean", "char", "byte", "short",
+            "int", "long", "double", "float", "void"
+    };
 
     public static final ClassNode
             DYNAMIC_TYPE = makeCached(Object.class), OBJECT_TYPE = DYNAMIC_TYPE,
@@ -242,8 +238,8 @@ public class ClassHelper {
     public static ClassNode make(String name) {
         if (name == null || name.length() == 0) return DYNAMIC_TYPE;
 
-        for (int i = 0; i < PRIMITIVE_CLASS_NAMES.length; i++) {
-            if (PRIMITIVE_CLASS_NAMES[i].equals(name)) return types[i];
+        for (int i = 0; i < primitiveClassNames.length; i++) {
+            if (primitiveClassNames[i].equals(name)) return types[i];
         }
 
         for (int i = 0; i < classes.length; i++) {
@@ -253,7 +249,7 @@ public class ClassHelper {
         return makeWithoutCaching(name);
     }
 
-    private static final Map<ClassNode, ClassNode> PRIMITIVE_TYPE_TO_WRAPPER_TYPE_MAP
= Maps.of(
+    private static final Map<ClassNode, ClassNode> PRIMARY_TYPE_TO_WRAPPER_TYPE_MAP
= Maps.of(
             boolean_TYPE, Boolean_TYPE,
             byte_TYPE, Byte_TYPE,
             char_TYPE, Character_TYPE,
@@ -286,7 +282,7 @@ public class ClassHelper {
         cn = cn.redirect();
         if (!isPrimitiveType(cn)) return cn;
 
-        ClassNode result = PRIMITIVE_TYPE_TO_WRAPPER_TYPE_MAP.get(cn);
+        ClassNode result = PRIMARY_TYPE_TO_WRAPPER_TYPE_MAP.get(cn);
 
         if (null != result) {
             return result;
@@ -295,13 +291,13 @@ public class ClassHelper {
         return cn;
     }
 
-    private static final Map<ClassNode, ClassNode> WRAPPER_TYPE_TO_PRIMITIVE_TYPE_MAP
= Maps.inverse(PRIMITIVE_TYPE_TO_WRAPPER_TYPE_MAP);
+    private static final Map<ClassNode, ClassNode> WRAPPER_TYPE_TO_PRIMARY_TYPE_MAP
= Maps.inverse(PRIMARY_TYPE_TO_WRAPPER_TYPE_MAP);
 
     public static ClassNode getUnwrapper(ClassNode cn) {
         cn = cn.redirect();
         if (isPrimitiveType(cn)) return cn;
 
-        ClassNode result = WRAPPER_TYPE_TO_PRIMITIVE_TYPE_MAP.get(cn);
+        ClassNode result = WRAPPER_TYPE_TO_PRIMARY_TYPE_MAP.get(cn);
 
         if (null != result) {
             return result;

http://git-wip-us.apache.org/repos/asf/groovy/blob/c77ed94d/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeDescriptionUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeDescriptionUtil.java
b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeDescriptionUtil.java
index 56a2e06..2f7349a 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeDescriptionUtil.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/util/TypeDescriptionUtil.java
@@ -40,7 +40,7 @@ import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
  */
 public class TypeDescriptionUtil {
     private static final String REF_DESCRIPTION = "L";
-    private static final Map<ClassNode, String> PRIMITIVE_TYPE_TO_DESCRIPTION_MAP =
Maps.of(
+    private static final Map<ClassNode, String> TYPE_TO_DESCRIPTION_MAP = Maps.of(
             int_TYPE, "I",
             VOID_TYPE,"V",
             boolean_TYPE, "Z",
@@ -52,7 +52,7 @@ public class TypeDescriptionUtil {
             long_TYPE, "J"
     );
 
-    public static final Map<String, ClassNode> NAME_TO_PRIMITIVE_TYPE_MAP = Maps.of(
+    private static final Map<String, ClassNode> NAME_TO_TYPE_MAP = Maps.of(
             "int", int_TYPE,
             "void", VOID_TYPE,
             "boolean", boolean_TYPE,
@@ -65,15 +65,15 @@ public class TypeDescriptionUtil {
     );
 
     public static boolean isPrimitiveType(String name) {
-        return NAME_TO_PRIMITIVE_TYPE_MAP.containsKey(name);
+        return NAME_TO_TYPE_MAP.containsKey(name);
     }
 
     public static boolean isPrimitiveType(ClassNode type) {
-        return PRIMITIVE_TYPE_TO_DESCRIPTION_MAP.containsKey(type);
+        return TYPE_TO_DESCRIPTION_MAP.containsKey(type);
     }
 
     public static String getDescriptionByType(ClassNode type) {
-        String desc = PRIMITIVE_TYPE_TO_DESCRIPTION_MAP.get(type);
+        String desc = TYPE_TO_DESCRIPTION_MAP.get(type);
 
         if (null == desc) { // reference type
             if (!type.isArray()) {
@@ -95,7 +95,7 @@ public class TypeDescriptionUtil {
     }
 
     public static String getDescriptionByName(String name) {
-        ClassNode type = NAME_TO_PRIMITIVE_TYPE_MAP.get(name);
+        ClassNode type = NAME_TO_TYPE_MAP.get(name);
 
         if (null == type) {
             return makeRefDescription(name);


Mime
View raw message