From 960b539069a57f566cd86d2bf23399fe20e101b7 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 30 Sep 2024 09:24:25 +0200 Subject: [PATCH] Polishing. See #3167 --- .../data/util/KotlinBeanInfoFactory.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java b/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java index 7e608014c3..8d2104ae72 100644 --- a/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java +++ b/src/main/java/org/springframework/data/util/KotlinBeanInfoFactory.java @@ -69,6 +69,27 @@ public BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { Collection> members = kotlinClass.getMembers(); Map 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> members, + Map descriptors) throws IntrospectionException { + for (KCallable member : members) { if (member instanceof KProperty property) { @@ -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 descriptors) + throws IntrospectionException { Class javaClass = beanClass; do { @@ -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