Skip to content

Commit

Permalink
Trivial refactoring: extract duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellansun committed Jan 4, 2025
1 parent c4a4754 commit f920377
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/main/java/groovy/lang/MetaClassImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f920377

Please sign in to comment.