Repository: groovy
Updated Branches:
  refs/heads/master 2ffc1eadc -> b466a0900


Minor refactoring


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

Branch: refs/heads/master
Commit: b466a09005ddc74d88dd7208e0104d3d1d85763c
Parents: 2ffc1ea
Author: sunlan <[email protected]>
Authored: Fri Dec 1 09:19:47 2017 +0800
Committer: sunlan <[email protected]>
Committed: Fri Dec 1 09:19:47 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/b466a090/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java 
b/src/main/groovy/lang/MetaClassImpl.java
index 84b396c..a604fd5 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -1855,29 +1855,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
@@ -1898,6 +1882,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};
@@ -1983,29 +1968,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
@@ -2117,7 +2086,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