Browse Source

Backport of recent ExtendedBeanInfo refinements from 5.1.x

Closes gh-24109
pull/28406/head
Juergen Hoeller 6 years ago
parent
commit
ea1992c8d1
  1. 19
      spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

19
spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,8 +41,8 @@ import org.springframework.util.ObjectUtils;
/** /**
* Decorator for a standard {@link BeanInfo} object, e.g. as created by * Decorator for a standard {@link BeanInfo} object, e.g. as created by
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static * {@link Introspector#getBeanInfo(Class)}, designed to discover and register
* and/or non-void returning setter methods. For example: * static and/or non-void returning setter methods. For example:
* *
* <pre class="code"> * <pre class="code">
* public class Bean { * public class Bean {
@ -145,11 +145,10 @@ class ExtendedBeanInfo implements BeanInfo {
public static boolean isCandidateWriteMethod(Method method) { public static boolean isCandidateWriteMethod(Method method) {
String methodName = method.getName(); String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes(); int nParams = method.getParameterCount();
int nParams = parameterTypes.length;
return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) && return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
(!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) && (!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
(nParams == 1 || (nParams == 2 && int.class == parameterTypes[0]))); (nParams == 1 || (nParams == 2 && int.class == method.getParameterTypes()[0])));
} }
private void handleCandidateWriteMethod(Method method) throws IntrospectionException { private void handleCandidateWriteMethod(Method method) throws IntrospectionException {
@ -209,7 +208,7 @@ class ExtendedBeanInfo implements BeanInfo {
} }
private String propertyNameFor(Method method) { private String propertyNameFor(Method method) {
return Introspector.decapitalize(method.getName().substring(3, method.getName().length())); return Introspector.decapitalize(method.getName().substring(3));
} }
@ -488,7 +487,7 @@ class ExtendedBeanInfo implements BeanInfo {
} }
/* /*
* See java.beans.IndexedPropertyDescriptor#equals(java.lang.Object) * See java.beans.IndexedPropertyDescriptor#equals
*/ */
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
@ -535,11 +534,13 @@ class ExtendedBeanInfo implements BeanInfo {
public int compare(PropertyDescriptor desc1, PropertyDescriptor desc2) { public int compare(PropertyDescriptor desc1, PropertyDescriptor desc2) {
String left = desc1.getName(); String left = desc1.getName();
String right = desc2.getName(); String right = desc2.getName();
byte[] leftBytes = left.getBytes();
byte[] rightBytes = right.getBytes();
for (int i = 0; i < left.length(); i++) { for (int i = 0; i < left.length(); i++) {
if (right.length() == i) { if (right.length() == i) {
return 1; return 1;
} }
int result = left.getBytes()[i] - right.getBytes()[i]; int result = leftBytes[i] - rightBytes[i];
if (result != 0) { if (result != 0) {
return result; return result;
} }

Loading…
Cancel
Save