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:19:34 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X c0a1bd05a -> 3da502e4f


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/3da502e4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3da502e4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3da502e4

Branch: refs/heads/GROOVY_2_6_X
Commit: 3da502e4f5a91d22d39a71489aad31e84fa54a99
Parents: c0a1bd0
Author: sunlan <sunlan@apache.org>
Authored: Fri Dec 1 08:18:56 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri Dec 1 08:19:28 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/3da502e4/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index af984c9..84b396c 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -1643,19 +1643,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) {
@@ -1677,6 +1665,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
@@ -1698,19 +1703,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