Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 5c4360725 -> 9fe6cea27


Minor refactoring

(cherry picked from commit b466a09)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 9fe6cea2711a115b6dd5c7446f8b2be6d9088bbe
Parents: 5c43607
Author: sunlan <[email protected]>
Authored: Fri Dec 1 09:19:47 2017 +0800
Committer: sunlan <[email protected]>
Committed: Fri Dec 1 09:20:46 2017 +0800

----------------------------------------------------------------------
 src/main/groovy/lang/MetaClassImpl.java | 67 ++++++++++++----------------
 1 file changed, 29 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9fe6cea2/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java 
b/src/main/groovy/lang/MetaClassImpl.java
index 616b740..6c38e7e 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -1792,29 +1792,13 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
             return ((Map) object).get(name);
         }
 
-        MetaMethod method = null;
-        Object[] arguments = EMPTY_ARGUMENTS;
+        Tuple2<MetaMethod, MetaProperty> methodAndProperty = 
createMetaMethodAndMetaProperty(sender, sender, name, useSuper, isStatic);
+        MetaMethod method = methodAndProperty.getFirst();
 
         
//----------------------------------------------------------------------
         // getter
         
//----------------------------------------------------------------------
-        MetaProperty mp = getMetaProperty(sender, name, useSuper, isStatic);
-        if (mp != null) {
-            if (mp instanceof MetaBeanProperty) {
-                MetaBeanProperty mbp = (MetaBeanProperty) mp;
-                method = mbp.getGetter();
-                mp = mbp.getField();
-            }
-        }
-
-        // check for a category method named like a getter
-        if (!useSuper && !isStatic && 
GroovyCategorySupport.hasCategoryInCurrentThread()) {
-            String getterName = 
GroovyCategorySupport.getPropertyCategoryGetterName(name);
-            if (getterName != null) {
-                MetaMethod categoryMethod = getCategoryMethodGetter(sender, 
getterName, false);
-                if (categoryMethod != null) method = categoryMethod;
-            }
-        }
+        MetaProperty mp = methodAndProperty.getSecond();
 
         
//----------------------------------------------------------------------
         // field
@@ -1835,6 +1819,7 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
         // generic get method
         
//----------------------------------------------------------------------
         // check for a generic get method provided through a category
+        Object[] arguments = EMPTY_ARGUMENTS;
         if (method == null && !useSuper && !isStatic && 
GroovyCategorySupport.hasCategoryInCurrentThread()) {
             method = getCategoryMethodGetter(sender, "get", true);
             if (method != null) arguments = new Object[]{name};
@@ -1920,29 +1905,13 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
             };
         }
 
-        MetaMethod method = null;
+        Tuple2<MetaMethod, MetaProperty> methodAndProperty = 
createMetaMethodAndMetaProperty(sender, theClass, name, useSuper, isStatic);
+        MetaMethod method = methodAndProperty.getFirst();
 
         
//----------------------------------------------------------------------
         // getter
         
//----------------------------------------------------------------------
-        MetaProperty mp = getMetaProperty(sender, name, useSuper, isStatic);
-        if (mp != null) {
-            if (mp instanceof MetaBeanProperty) {
-                MetaBeanProperty mbp = (MetaBeanProperty) mp;
-                method = mbp.getGetter();
-                mp = mbp.getField();
-            }
-        }
-
-        // check for a category method named like a getter
-        if (!useSuper && !isStatic && 
GroovyCategorySupport.hasCategoryInCurrentThread()) {
-            String getterName = 
GroovyCategorySupport.getPropertyCategoryGetterName(name);
-            if (getterName != null) {
-                MetaMethod categoryMethod = getCategoryMethodGetter(theClass, 
getterName, false);
-                if (categoryMethod != null)
-                    method = categoryMethod;
-            }
-        }
+        MetaProperty mp = methodAndProperty.getSecond();
 
         
//----------------------------------------------------------------------
         // field
@@ -2054,7 +2023,29 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
             };
     }
 
+    private Tuple2<MetaMethod, MetaProperty> 
createMetaMethodAndMetaProperty(final Class senderForMP, final Class 
senderForCMG, final String name, final boolean useSuper, final boolean 
isStatic) {
+        MetaMethod method = null;
+        MetaProperty mp = getMetaProperty(senderForMP, name, useSuper, 
isStatic);
+        if (mp != null) {
+            if (mp instanceof MetaBeanProperty) {
+                MetaBeanProperty mbp = (MetaBeanProperty) mp;
+                method = mbp.getGetter();
+                mp = mbp.getField();
+            }
+        }
 
+        // check for a category method named like a getter
+        if (!useSuper && !isStatic && 
GroovyCategorySupport.hasCategoryInCurrentThread()) {
+            String getterName = 
GroovyCategorySupport.getPropertyCategoryGetterName(name);
+            if (getterName != null) {
+                MetaMethod categoryMethod = 
getCategoryMethodGetter(senderForCMG, getterName, false);
+                if (categoryMethod != null)
+                    method = categoryMethod;
+            }
+        }
+
+        return new Tuple2<MetaMethod, MetaProperty>(method, mp);
+    }
 
     private static MetaMethod getCategoryMethodGetter(Class sender, String 
name, boolean useLongVersion) {
         List possibleGenericMethods = 
GroovyCategorySupport.getCategoryMethods(name);

Reply via email to