groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring
Date Fri, 01 Dec 2017 00:20:29 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 833e895ca -> 497e0be62


Minor refactoring

(cherry picked from commit 2ffc1ea)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 497e0be6241d40953444a7c6f229697637c86c26
Parents: 833e895
Author: sunlan <sunlan@apache.org>
Authored: Fri Dec 1 08:18:56 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri Dec 1 08:20:23 2017 +0800

----------------------------------------------------------------------
 src/main/groovy/lang/MetaClassImpl.java | 45 ++++++++++++----------------
 1 file changed, 19 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/497e0be6/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index 8743bd8..0b2e814 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -1569,19 +1569,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                     this.theClass.getName() + " do not match. Expected " + numberOfConstructors
+ " but got " + constructors.size());
         }
 
-        if (arguments == null) arguments = EMPTY_ARGUMENTS;
-        Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
-        MetaClassHelper.unwrap(arguments);
-        CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>",
constructors, argClasses);
-        if (constructor == null) {
-            constructor = (CachedConstructor) chooseMethod("<init>", constructors,
argClasses);
-        }
-        if (constructor == null) {
-            throw new GroovyRuntimeException(
-                    "Could not find matching constructor for: "
-                            + theClass.getName()
-                            + "(" + InvokerHelper.toTypeString(arguments) + ")");
-        }
+        CachedConstructor constructor = createCachedConstructor(arguments);
         List l = new ArrayList(constructors.toList());
         Comparator comp = new Comparator() {
             public int compare(Object arg0, Object arg1) {
@@ -1603,6 +1591,23 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         return 0 | (found << 8);
     }
 
+    private CachedConstructor createCachedConstructor(Object[] arguments) {
+        if (arguments == null) arguments = EMPTY_ARGUMENTS;
+        Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
+        MetaClassHelper.unwrap(arguments);
+        CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>",
constructors, argClasses);
+        if (constructor == null) {
+            constructor = (CachedConstructor) chooseMethod("<init>", constructors,
argClasses);
+        }
+        if (constructor == null) {
+            throw new GroovyRuntimeException(
+                    "Could not find matching constructor for: "
+                            + theClass.getName()
+                            + "(" + InvokerHelper.toTypeString(arguments) + ")");
+        }
+        return constructor;
+    }
+
     /**
      * Constructor selection algorithm for Groovy 2.1.9+.
      * This selection algorithm was introduced as a workaround for GROOVY-6080. Instead of
generating an index between
@@ -1624,19 +1629,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
      * @since 2.1.9
      */
     private int selectConstructorAndTransformArguments1(Object[] arguments) {
-        if (arguments == null) arguments = EMPTY_ARGUMENTS;
-        Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
-        MetaClassHelper.unwrap(arguments);
-        CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>",
constructors, argClasses);
-        if (constructor == null) {
-            constructor = (CachedConstructor) chooseMethod("<init>", constructors,
argClasses);
-        }
-        if (constructor == null) {
-            throw new GroovyRuntimeException(
-                    "Could not find matching constructor for: "
-                            + theClass.getName()
-                            + "(" + InvokerHelper.toTypeString(arguments) + ")");
-        }
+        CachedConstructor constructor = createCachedConstructor(arguments);
         final String methodDescriptor = BytecodeHelper.getMethodDescriptor(Void.TYPE, constructor.getNativeParameterTypes());
         // keeping 3 bits for additional information such as vargs
         return BytecodeHelper.hashCode(methodDescriptor);


Mime
View raw message