From f920377931c1c6f717e3604e357aa1a257896b87 Mon Sep 17 00:00:00 2001 From: Daniel Sun Date: Sun, 5 Jan 2025 05:41:18 +0900 Subject: [PATCH] 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 bc6234617cb..549f8e1a118 100644 --- a/src/main/java/groovy/lang/MetaClassImpl.java +++ b/src/main/java/groovy/lang/MetaClassImpl.java @@ -2617,25 +2617,12 @@ protected void applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors 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 @@ private static void filterMatchingMethodForCategory(FastArray list, MetaMethod m 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 @@ private void addRecordProperties(BeanInfo info) { 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); } }