Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
See #3167
  • Loading branch information
mp911de committed Sep 30, 2024
1 parent 8ef195f commit 960b539
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
Collection<KCallable<?>> members = kotlinClass.getMembers();
Map<String, PropertyDescriptor> descriptors = new LinkedHashMap<>(members.size(), 1.f);

collectKotlinProperties(beanClass, members, descriptors);
collectBasicJavaProperties(beanClass, descriptors);

PropertyDescriptor[] propertyDescriptors = descriptors.values().toArray(new PropertyDescriptor[0]);

return new SimpleBeanInfo() {
@Override
public BeanDescriptor getBeanDescriptor() {
return new BeanDescriptor(beanClass);
}

@Override
public PropertyDescriptor[] getPropertyDescriptors() {
return propertyDescriptors;
}
};
}

private static void collectKotlinProperties(Class<?> beanClass, Collection<KCallable<?>> members,
Map<String, PropertyDescriptor> descriptors) throws IntrospectionException {

for (KCallable<?> member : members) {

if (member instanceof KProperty<?> property) {
Expand Down Expand Up @@ -100,6 +121,10 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
descriptors.put(property.getName(), new PropertyDescriptor(property.getName(), getter, setter));
}
}
}

private static void collectBasicJavaProperties(Class<?> beanClass, Map<String, PropertyDescriptor> descriptors)
throws IntrospectionException {

Class<?> javaClass = beanClass;
do {
Expand All @@ -123,20 +148,6 @@ public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
descriptors.put(descriptor.getName(), descriptor);
}
}

PropertyDescriptor[] propertyDescriptors = descriptors.values().toArray(new PropertyDescriptor[0]);

return new SimpleBeanInfo() {
@Override
public BeanDescriptor getBeanDescriptor() {
return new BeanDescriptor(beanClass);
}

@Override
public PropertyDescriptor[] getPropertyDescriptors() {
return propertyDescriptors;
}
};
}

@Nullable
Expand Down

0 comments on commit 960b539

Please sign in to comment.