This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new f920377931 Trivial refactoring: extract duplicated code
f920377931 is described below

commit f920377931c1c6f717e3604e357aa1a257896b87
Author: Daniel Sun <[email protected]>
AuthorDate: Sun Jan 5 05:41:18 2025 +0900

    Trivial refactoring: extract duplicated code
---
 src/main/java/groovy/lang/MetaClassImpl.java | 31 ++++++++++------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java 
b/src/main/java/groovy/lang/MetaClassImpl.java
index bc6234617c..549f8e1a11 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -2617,25 +2617,12 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
                 continue;
 
             // get the getter method
-            Method method = pd.getReadMethod();
-            MetaMethod getter;
-
-            if (method != null) {
-                CachedMethod cachedGetter = CachedMethod.find(method);
-                getter = cachedGetter == null ? null : 
findMethod(cachedGetter);
-            } else {
-                getter = null;
-            }
+            Method readMethod = pd.getReadMethod();
+            MetaMethod getter = readMethod != null ? findMethod(readMethod) : 
null;
 
             // get the setter method
-            MetaMethod setter;
-            method = pd.getWriteMethod();
-            if (method != null) {
-                CachedMethod cachedSetter = CachedMethod.find(method);
-                setter = cachedSetter == null ? null : 
findMethod(cachedSetter);
-            } else {
-                setter = null;
-            }
+            Method writeMethod = pd.getWriteMethod();
+            MetaMethod setter = writeMethod != null ? findMethod(writeMethod) 
: null;
 
             // now create the MetaProperty object
             MetaBeanProperty mp = new MetaBeanProperty(pd.getName(), 
pd.getPropertyType(), getter, setter);
@@ -3178,6 +3165,11 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
         list.add(method);
     }
 
+    private MetaMethod findMethod(Method method) {
+        CachedMethod cachedMethod = CachedMethod.find(method);
+        return cachedMethod == null ? null : findMethod(cachedMethod);
+    }
+
     /**
      * @return the matching method which should be found
      */
@@ -3415,9 +3407,8 @@ public class MetaClassImpl implements MetaClass, 
MutableMetaClass {
                 if (md.getMethod().getParameterCount() != 0) continue;
                 String name = md.getName();
                 if (componentNames.contains(name)) {
-                    CachedMethod cachedMethod = 
CachedMethod.find(md.getMethod());
-                    if (cachedMethod != null) {
-                        MetaMethod accessor = findMethod(cachedMethod);
+                    MetaMethod accessor = findMethod(md.getMethod());
+                    if (accessor != null) {
                         createMetaBeanProperty(propIndex, name, true, 
accessor);
                     }
                 }

Reply via email to