Repository: groovy Updated Branches: refs/heads/GROOVY_2_4_X 497e0be62 -> 549733551
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/54973355 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/54973355 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/54973355 Branch: refs/heads/GROOVY_2_4_X Commit: 549733551330d0dcb47ca0e78cec539a76b48965 Parents: 497e0be Author: sunlan <[email protected]> Authored: Fri Dec 1 09:19:47 2017 +0800 Committer: sunlan <[email protected]> Committed: Fri Dec 1 09:21:27 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/54973355/src/main/groovy/lang/MetaClassImpl.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java index 0b2e814..8c4cc05 100644 --- a/src/main/groovy/lang/MetaClassImpl.java +++ b/src/main/groovy/lang/MetaClassImpl.java @@ -1781,29 +1781,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 @@ -1821,6 +1805,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}; @@ -1906,29 +1891,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 @@ -2040,7 +2009,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);
