Properly handle getMethodDescriptors() null value on IBM JVM
Also internally renaming SimpleNonIndexedPropertyDescriptor to SimplePropertyDescriptor and preferring direct field access wherever possible. Issue: SPR-10862
This commit is contained in:
parent
0c30618ae8
commit
5639aa7064
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
|
||||||
import java.beans.BeanDescriptor;
|
import java.beans.BeanDescriptor;
|
||||||
import java.beans.BeanInfo;
|
import java.beans.BeanInfo;
|
||||||
import java.beans.EventSetDescriptor;
|
import java.beans.EventSetDescriptor;
|
||||||
|
@ -26,10 +25,8 @@ import java.beans.IntrospectionException;
|
||||||
import java.beans.Introspector;
|
import java.beans.Introspector;
|
||||||
import java.beans.MethodDescriptor;
|
import java.beans.MethodDescriptor;
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -84,8 +81,8 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap the given {@link BeanInfo} instance; copy all its existing property descriptors
|
* Wrap the given {@link BeanInfo} instance; copy all its existing property descriptors
|
||||||
* locally, wrapping each in a custom {@link SimpleIndexedPropertyDescriptor indexed} or
|
* locally, wrapping each in a custom {@link SimpleIndexedPropertyDescriptor indexed}
|
||||||
* {@link SimpleNonIndexedPropertyDescriptor non-indexed} {@code PropertyDescriptor}
|
* or {@link SimplePropertyDescriptor non-indexed} {@code PropertyDescriptor}
|
||||||
* variant that bypasses default JDK weak/soft reference management; then search
|
* variant that bypasses default JDK weak/soft reference management; then search
|
||||||
* through its method descriptors to find any non-void returning write methods and
|
* through its method descriptors to find any non-void returning write methods and
|
||||||
* update or create the corresponding {@link PropertyDescriptor} for each one found.
|
* update or create the corresponding {@link PropertyDescriptor} for each one found.
|
||||||
|
@ -96,15 +93,16 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
*/
|
*/
|
||||||
public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
|
public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
|
||||||
for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
|
for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
|
||||||
this.propertyDescriptors.add(pd instanceof IndexedPropertyDescriptor ?
|
this.propertyDescriptors.add(pd instanceof IndexedPropertyDescriptor ?
|
||||||
new SimpleIndexedPropertyDescriptor((IndexedPropertyDescriptor) pd) :
|
new SimpleIndexedPropertyDescriptor((IndexedPropertyDescriptor) pd) :
|
||||||
new SimpleNonIndexedPropertyDescriptor(pd));
|
new SimplePropertyDescriptor(pd));
|
||||||
}
|
}
|
||||||
|
MethodDescriptor[] methodDescriptors = delegate.getMethodDescriptors();
|
||||||
for (Method method : findCandidateWriteMethods(delegate.getMethodDescriptors())) {
|
if (methodDescriptors != null) {
|
||||||
handleCandidateWriteMethod(method);
|
for (Method method : findCandidateWriteMethods(methodDescriptors)) {
|
||||||
|
handleCandidateWriteMethod(method);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,58 +130,44 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
String methodName = method.getName();
|
String methodName = method.getName();
|
||||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||||
int nParams = parameterTypes.length;
|
int nParams = parameterTypes.length;
|
||||||
if (methodName.length() > 3 && methodName.startsWith("set") &&
|
return methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
|
||||||
Modifier.isPublic(method.getModifiers()) &&
|
(!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
|
||||||
(
|
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)));
|
||||||
!void.class.isAssignableFrom(method.getReturnType()) ||
|
|
||||||
Modifier.isStatic(method.getModifiers())
|
|
||||||
) &&
|
|
||||||
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCandidateWriteMethod(Method method) throws IntrospectionException {
|
private void handleCandidateWriteMethod(Method method) throws IntrospectionException {
|
||||||
int nParams = method.getParameterTypes().length;
|
int nParams = method.getParameterTypes().length;
|
||||||
String propertyName = propertyNameFor(method);
|
String propertyName = propertyNameFor(method);
|
||||||
Class<?> propertyType = method.getParameterTypes()[nParams-1];
|
Class<?> propertyType = method.getParameterTypes()[nParams-1];
|
||||||
PropertyDescriptor existingPD = findExistingPropertyDescriptor(propertyName, propertyType);
|
PropertyDescriptor existingPd = findExistingPropertyDescriptor(propertyName, propertyType);
|
||||||
if (nParams == 1) {
|
if (nParams == 1) {
|
||||||
if (existingPD == null) {
|
if (existingPd == null) {
|
||||||
this.propertyDescriptors.add(
|
this.propertyDescriptors.add(new SimplePropertyDescriptor(propertyName, null, method));
|
||||||
new SimpleNonIndexedPropertyDescriptor(propertyName, null, method));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
existingPD.setWriteMethod(method);
|
existingPd.setWriteMethod(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (nParams == 2) {
|
else if (nParams == 2) {
|
||||||
if (existingPD == null) {
|
if (existingPd == null) {
|
||||||
this.propertyDescriptors.add(
|
this.propertyDescriptors.add(
|
||||||
new SimpleIndexedPropertyDescriptor(
|
new SimpleIndexedPropertyDescriptor(propertyName, null, null, null, method));
|
||||||
propertyName, null, null, null, method));
|
|
||||||
}
|
}
|
||||||
else if (existingPD instanceof IndexedPropertyDescriptor) {
|
else if (existingPd instanceof IndexedPropertyDescriptor) {
|
||||||
((IndexedPropertyDescriptor)existingPD).setIndexedWriteMethod(method);
|
((IndexedPropertyDescriptor) existingPd).setIndexedWriteMethod(method);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.propertyDescriptors.remove(existingPD);
|
this.propertyDescriptors.remove(existingPd);
|
||||||
this.propertyDescriptors.add(
|
this.propertyDescriptors.add(new SimpleIndexedPropertyDescriptor(
|
||||||
new SimpleIndexedPropertyDescriptor(
|
propertyName, existingPd.getReadMethod(), existingPd.getWriteMethod(), null, method));
|
||||||
propertyName, existingPD.getReadMethod(),
|
|
||||||
existingPD.getWriteMethod(), null, method));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Write method must have exactly 1 or 2 parameters: " + method);
|
||||||
"write method must have exactly 1 or 2 parameters: " + method);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyDescriptor findExistingPropertyDescriptor(
|
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
|
||||||
String propertyName, Class<?> propertyType) {
|
|
||||||
|
|
||||||
for (PropertyDescriptor pd : this.propertyDescriptors) {
|
for (PropertyDescriptor pd : this.propertyDescriptors) {
|
||||||
final Class<?> candidateType;
|
final Class<?> candidateType;
|
||||||
final String candidateName = pd.getName();
|
final String candidateName = pd.getName();
|
||||||
|
@ -191,16 +175,14 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||||
candidateType = ipd.getIndexedPropertyType();
|
candidateType = ipd.getIndexedPropertyType();
|
||||||
if (candidateName.equals(propertyName) &&
|
if (candidateName.equals(propertyName) &&
|
||||||
(candidateType.equals(propertyType) ||
|
(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
|
||||||
candidateType.equals(propertyType.getComponentType()))) {
|
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
candidateType = pd.getPropertyType();
|
candidateType = pd.getPropertyType();
|
||||||
if (candidateName.equals(propertyName) &&
|
if (candidateName.equals(propertyName) &&
|
||||||
(candidateType.equals(propertyType) ||
|
(candidateType.equals(propertyType) || propertyType.equals(candidateType.getComponentType()))) {
|
||||||
propertyType.equals(candidateType.getComponentType()))) {
|
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,8 +191,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String propertyNameFor(Method method) {
|
private String propertyNameFor(Method method) {
|
||||||
return Introspector.decapitalize(
|
return Introspector.decapitalize(method.getName().substring(3, method.getName().length()));
|
||||||
method.getName().substring(3, method.getName().length()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,8 +202,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
* @see #ExtendedBeanInfo(BeanInfo)
|
* @see #ExtendedBeanInfo(BeanInfo)
|
||||||
*/
|
*/
|
||||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||||
return this.propertyDescriptors.toArray(
|
return this.propertyDescriptors.toArray(new PropertyDescriptor[this.propertyDescriptors.size()]);
|
||||||
new PropertyDescriptor[this.propertyDescriptors.size()]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeanInfo[] getAdditionalBeanInfo() {
|
public BeanInfo[] getAdditionalBeanInfo() {
|
||||||
|
@ -255,31 +235,28 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SimpleNonIndexedPropertyDescriptor extends PropertyDescriptor {
|
class SimplePropertyDescriptor extends PropertyDescriptor {
|
||||||
|
|
||||||
private Method readMethod;
|
private Method readMethod;
|
||||||
|
|
||||||
private Method writeMethod;
|
private Method writeMethod;
|
||||||
|
|
||||||
private Class<?> propertyType;
|
private Class<?> propertyType;
|
||||||
|
|
||||||
private Class<?> propertyEditorClass;
|
private Class<?> propertyEditorClass;
|
||||||
|
|
||||||
|
public SimplePropertyDescriptor(PropertyDescriptor original) throws IntrospectionException {
|
||||||
public SimpleNonIndexedPropertyDescriptor(PropertyDescriptor original)
|
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
this(original.getName(), original.getReadMethod(), original.getWriteMethod());
|
this(original.getName(), original.getReadMethod(), original.getWriteMethod());
|
||||||
copyNonMethodProperties(original, this);
|
copyNonMethodProperties(original, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleNonIndexedPropertyDescriptor(String propertyName,
|
public SimplePropertyDescriptor(String propertyName, Method readMethod, Method writeMethod) throws IntrospectionException {
|
||||||
Method readMethod, Method writeMethod) throws IntrospectionException {
|
|
||||||
|
|
||||||
super(propertyName, null, null);
|
super(propertyName, null, null);
|
||||||
this.setReadMethod(readMethod);
|
this.readMethod = readMethod;
|
||||||
this.setWriteMethod(writeMethod);
|
this.writeMethod = writeMethod;
|
||||||
this.propertyType = findPropertyType(readMethod, writeMethod);
|
this.propertyType = findPropertyType(readMethod, writeMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Method getReadMethod() {
|
public Method getReadMethod() {
|
||||||
return this.readMethod;
|
return this.readMethod;
|
||||||
|
@ -305,7 +282,8 @@ class SimpleNonIndexedPropertyDescriptor extends PropertyDescriptor {
|
||||||
if (this.propertyType == null) {
|
if (this.propertyType == null) {
|
||||||
try {
|
try {
|
||||||
this.propertyType = findPropertyType(this.readMethod, this.writeMethod);
|
this.propertyType = findPropertyType(this.readMethod, this.writeMethod);
|
||||||
} catch (IntrospectionException ex) {
|
}
|
||||||
|
catch (IntrospectionException ex) {
|
||||||
// ignore, as does PropertyDescriptor#getPropertyType
|
// ignore, as does PropertyDescriptor#getPropertyType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +300,6 @@ class SimpleNonIndexedPropertyDescriptor extends PropertyDescriptor {
|
||||||
this.propertyEditorClass = propertyEditorClass;
|
this.propertyEditorClass = propertyEditorClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return PropertyDescriptorUtils.equals(this, obj);
|
return PropertyDescriptorUtils.equals(this, obj);
|
||||||
|
@ -331,8 +308,7 @@ class SimpleNonIndexedPropertyDescriptor extends PropertyDescriptor {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s[name=%s, propertyType=%s, readMethod=%s, writeMethod=%s]",
|
return String.format("%s[name=%s, propertyType=%s, readMethod=%s, writeMethod=%s]",
|
||||||
this.getClass().getSimpleName(), this.getName(), this.getPropertyType(),
|
getClass().getSimpleName(), getName(), getPropertyType(), this.readMethod, this.writeMethod);
|
||||||
this.readMethod, this.writeMethod);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,40 +316,37 @@ class SimpleNonIndexedPropertyDescriptor extends PropertyDescriptor {
|
||||||
class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
|
|
||||||
private Method readMethod;
|
private Method readMethod;
|
||||||
|
|
||||||
private Method writeMethod;
|
private Method writeMethod;
|
||||||
|
|
||||||
private Class<?> propertyType;
|
private Class<?> propertyType;
|
||||||
private Class<?> propertyEditorClass;
|
|
||||||
|
|
||||||
private Method indexedReadMethod;
|
private Method indexedReadMethod;
|
||||||
|
|
||||||
private Method indexedWriteMethod;
|
private Method indexedWriteMethod;
|
||||||
|
|
||||||
private Class<?> indexedPropertyType;
|
private Class<?> indexedPropertyType;
|
||||||
|
|
||||||
|
private Class<?> propertyEditorClass;
|
||||||
|
|
||||||
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original)
|
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
|
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
|
||||||
original.getIndexedReadMethod(), original.getIndexedWriteMethod());
|
original.getIndexedReadMethod(), original.getIndexedWriteMethod());
|
||||||
copyNonMethodProperties(original, this);
|
copyNonMethodProperties(original, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleIndexedPropertyDescriptor(String propertyName,
|
public SimpleIndexedPropertyDescriptor(String propertyName, Method readMethod, Method writeMethod,
|
||||||
Method readMethod, Method writeMethod,
|
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
||||||
Method indexedReadMethod, Method indexedWriteMethod)
|
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
super(propertyName, null, null, null, null);
|
super(propertyName, null, null, null, null);
|
||||||
this.setReadMethod(readMethod);
|
this.readMethod = readMethod;
|
||||||
this.setWriteMethod(writeMethod);
|
this.writeMethod = writeMethod;
|
||||||
this.propertyType = findPropertyType(readMethod, writeMethod);
|
this.propertyType = findPropertyType(readMethod, writeMethod);
|
||||||
|
this.indexedReadMethod = indexedReadMethod;
|
||||||
this.setIndexedReadMethod(indexedReadMethod);
|
this.indexedWriteMethod = indexedWriteMethod;
|
||||||
this.setIndexedWriteMethod(indexedWriteMethod);
|
this.indexedPropertyType = findIndexedPropertyType(propertyName, this.propertyType, indexedReadMethod, indexedWriteMethod);
|
||||||
this.indexedPropertyType = findIndexedPropertyType(
|
|
||||||
this.getName(), this.propertyType, indexedReadMethod, indexedWriteMethod);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Method getReadMethod() {
|
public Method getReadMethod() {
|
||||||
return this.readMethod;
|
return this.readMethod;
|
||||||
|
@ -399,7 +372,8 @@ class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
if (this.propertyType == null) {
|
if (this.propertyType == null) {
|
||||||
try {
|
try {
|
||||||
this.propertyType = findPropertyType(this.readMethod, this.writeMethod);
|
this.propertyType = findPropertyType(this.readMethod, this.writeMethod);
|
||||||
} catch (IntrospectionException ex) {
|
}
|
||||||
|
catch (IntrospectionException ex) {
|
||||||
// ignore, as does IndexedPropertyDescriptor#getPropertyType
|
// ignore, as does IndexedPropertyDescriptor#getPropertyType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,9 +405,9 @@ class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
if (this.indexedPropertyType == null) {
|
if (this.indexedPropertyType == null) {
|
||||||
try {
|
try {
|
||||||
this.indexedPropertyType = findIndexedPropertyType(
|
this.indexedPropertyType = findIndexedPropertyType(
|
||||||
this.getName(), this.getPropertyType(),
|
getName(), getPropertyType(), this.indexedReadMethod, this.indexedWriteMethod);
|
||||||
this.indexedReadMethod, this.indexedWriteMethod);
|
}
|
||||||
} catch (IntrospectionException ex) {
|
catch (IntrospectionException ex) {
|
||||||
// ignore, as does IndexedPropertyDescriptor#getIndexedPropertyType
|
// ignore, as does IndexedPropertyDescriptor#getIndexedPropertyType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,26 +424,22 @@ class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
this.propertyEditorClass = propertyEditorClass;
|
this.propertyEditorClass = propertyEditorClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see java.beans.IndexedPropertyDescriptor#equals(java.lang.Object)
|
* See java.beans.IndexedPropertyDescriptor#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj != null && obj instanceof IndexedPropertyDescriptor) {
|
if (obj != null && obj instanceof IndexedPropertyDescriptor) {
|
||||||
IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj;
|
IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj;
|
||||||
if (!compareMethods(getIndexedReadMethod(), other.getIndexedReadMethod())) {
|
if (!compareMethods(getIndexedReadMethod(), other.getIndexedReadMethod())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compareMethods(getIndexedWriteMethod(), other.getIndexedWriteMethod())) {
|
if (!compareMethods(getIndexedWriteMethod(), other.getIndexedWriteMethod())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
|
if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -482,9 +452,8 @@ class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s[name=%s, propertyType=%s, indexedPropertyType=%s, " +
|
return String.format("%s[name=%s, propertyType=%s, indexedPropertyType=%s, " +
|
||||||
"readMethod=%s, writeMethod=%s, indexedReadMethod=%s, indexedWriteMethod=%s]",
|
"readMethod=%s, writeMethod=%s, indexedReadMethod=%s, indexedWriteMethod=%s]",
|
||||||
this.getClass().getSimpleName(), this.getName(), this.getPropertyType(),
|
getClass().getSimpleName(), getName(), getPropertyType(), getIndexedPropertyType(),
|
||||||
this.getIndexedPropertyType(), this.readMethod, this.writeMethod,
|
this.readMethod, this.writeMethod, this.indexedReadMethod, this.indexedWriteMethod);
|
||||||
this.indexedReadMethod, this.indexedWriteMethod);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +461,7 @@ class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
|
||||||
class PropertyDescriptorUtils {
|
class PropertyDescriptorUtils {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* see java.beans.FeatureDescriptor#FeatureDescriptor(FeatureDescriptor)
|
* See java.beans.FeatureDescriptor#FeatureDescriptor(FeatureDescriptor)
|
||||||
*/
|
*/
|
||||||
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target)
|
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target)
|
||||||
throws IntrospectionException {
|
throws IntrospectionException {
|
||||||
|
@ -520,11 +489,8 @@ class PropertyDescriptorUtils {
|
||||||
/*
|
/*
|
||||||
* See PropertyDescriptor#findPropertyType
|
* See PropertyDescriptor#findPropertyType
|
||||||
*/
|
*/
|
||||||
public static Class<?> findPropertyType(Method readMethod, Method writeMethod)
|
public static Class<?> findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException {
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
Class<?> propertyType = null;
|
Class<?> propertyType = null;
|
||||||
|
|
||||||
if (readMethod != null) {
|
if (readMethod != null) {
|
||||||
Class<?>[] params = readMethod.getParameterTypes();
|
Class<?>[] params = readMethod.getParameterTypes();
|
||||||
if (params.length != 0) {
|
if (params.length != 0) {
|
||||||
|
@ -554,8 +520,7 @@ class PropertyDescriptorUtils {
|
||||||
* See IndexedPropertyDescriptor#findIndexedPropertyType
|
* See IndexedPropertyDescriptor#findIndexedPropertyType
|
||||||
*/
|
*/
|
||||||
public static Class<?> findIndexedPropertyType(String name, Class<?> propertyType,
|
public static Class<?> findIndexedPropertyType(String name, Class<?> propertyType,
|
||||||
Method indexedReadMethod, Method indexedWriteMethod)
|
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
Class<?> indexedPropertyType = null;
|
Class<?> indexedPropertyType = null;
|
||||||
|
|
||||||
|
@ -605,7 +570,6 @@ class PropertyDescriptorUtils {
|
||||||
* return {@code true} if they are objects are equivalent, i.e. both are {@code
|
* return {@code true} if they are objects are equivalent, i.e. both are {@code
|
||||||
* PropertyDescriptor}s whose read method, write method, property types, property
|
* PropertyDescriptor}s whose read method, write method, property types, property
|
||||||
* editor and flags are equivalent.
|
* editor and flags are equivalent.
|
||||||
*
|
|
||||||
* @see PropertyDescriptor#equals(Object)
|
* @see PropertyDescriptor#equals(Object)
|
||||||
*/
|
*/
|
||||||
public static boolean equals(PropertyDescriptor pd1, Object obj) {
|
public static boolean equals(PropertyDescriptor pd1, Object obj) {
|
||||||
|
@ -633,13 +597,12 @@ class PropertyDescriptorUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* see PropertyDescriptor#compareMethods
|
* See PropertyDescriptor#compareMethods
|
||||||
*/
|
*/
|
||||||
public static boolean compareMethods(Method a, Method b) {
|
public static boolean compareMethods(Method a, Method b) {
|
||||||
if ((a == null) != (b == null)) {
|
if ((a == null) != (b == null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a != null && b != null) {
|
if (a != null && b != null) {
|
||||||
if (!a.equals(b)) {
|
if (!a.equals(b)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -653,7 +616,6 @@ class PropertyDescriptorUtils {
|
||||||
/**
|
/**
|
||||||
* Sorts PropertyDescriptor instances alpha-numerically to emulate the behavior of
|
* Sorts PropertyDescriptor instances alpha-numerically to emulate the behavior of
|
||||||
* {@link java.beans.BeanInfo#getPropertyDescriptors()}.
|
* {@link java.beans.BeanInfo#getPropertyDescriptors()}.
|
||||||
*
|
|
||||||
* @see ExtendedBeanInfo#propertyDescriptors
|
* @see ExtendedBeanInfo#propertyDescriptors
|
||||||
*/
|
*/
|
||||||
class PropertyDescriptorComparator implements Comparator<PropertyDescriptor> {
|
class PropertyDescriptorComparator implements Comparator<PropertyDescriptor> {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 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.
|
||||||
|
@ -28,7 +28,7 @@ import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link SimpleNonIndexedPropertyDescriptor} and
|
* Unit tests for {@link SimplePropertyDescriptor} and
|
||||||
* {@link SimpleIndexedPropertyDescriptor}.
|
* {@link SimpleIndexedPropertyDescriptor}.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
@ -39,7 +39,7 @@ public class SimplePropertyDescriptorTests {
|
||||||
@Test
|
@Test
|
||||||
public void toStringOutput() throws IntrospectionException, SecurityException, NoSuchMethodException {
|
public void toStringOutput() throws IntrospectionException, SecurityException, NoSuchMethodException {
|
||||||
{
|
{
|
||||||
Object pd = new SimpleNonIndexedPropertyDescriptor("foo", null, null);
|
Object pd = new SimplePropertyDescriptor("foo", null, null);
|
||||||
assertThat(pd.toString(), containsString(
|
assertThat(pd.toString(), containsString(
|
||||||
"PropertyDescriptor[name=foo, propertyType=null, readMethod=null"));
|
"PropertyDescriptor[name=foo, propertyType=null, readMethod=null"));
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class SimplePropertyDescriptorTests {
|
||||||
public Object setFoo(String foo) { return null; }
|
public Object setFoo(String foo) { return null; }
|
||||||
}
|
}
|
||||||
Method m = C.class.getMethod("setFoo", String.class);
|
Method m = C.class.getMethod("setFoo", String.class);
|
||||||
Object pd = new SimpleNonIndexedPropertyDescriptor("foo", null, m);
|
Object pd = new SimplePropertyDescriptor("foo", null, m);
|
||||||
assertThat(pd.toString(), allOf(
|
assertThat(pd.toString(), allOf(
|
||||||
containsString("PropertyDescriptor[name=foo"),
|
containsString("PropertyDescriptor[name=foo"),
|
||||||
containsString("propertyType=class java.lang.String"),
|
containsString("propertyType=class java.lang.String"),
|
||||||
|
@ -76,10 +76,10 @@ public class SimplePropertyDescriptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonIndexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException {
|
public void nonIndexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException {
|
||||||
Object pd1 = new SimpleNonIndexedPropertyDescriptor("foo", null, null);
|
Object pd1 = new SimplePropertyDescriptor("foo", null, null);
|
||||||
assertThat(pd1, equalTo(pd1));
|
assertThat(pd1, equalTo(pd1));
|
||||||
|
|
||||||
Object pd2 = new SimpleNonIndexedPropertyDescriptor("foo", null, null);
|
Object pd2 = new SimplePropertyDescriptor("foo", null, null);
|
||||||
assertThat(pd1, equalTo(pd2));
|
assertThat(pd1, equalTo(pd2));
|
||||||
assertThat(pd2, equalTo(pd1));
|
assertThat(pd2, equalTo(pd1));
|
||||||
|
|
||||||
|
@ -89,12 +89,12 @@ public class SimplePropertyDescriptorTests {
|
||||||
public String getFoo() { return null; }
|
public String getFoo() { return null; }
|
||||||
}
|
}
|
||||||
Method wm1 = C.class.getMethod("setFoo", String.class);
|
Method wm1 = C.class.getMethod("setFoo", String.class);
|
||||||
Object pd3 = new SimpleNonIndexedPropertyDescriptor("foo", null, wm1);
|
Object pd3 = new SimplePropertyDescriptor("foo", null, wm1);
|
||||||
assertThat(pd1, not(equalTo(pd3)));
|
assertThat(pd1, not(equalTo(pd3)));
|
||||||
assertThat(pd3, not(equalTo(pd1)));
|
assertThat(pd3, not(equalTo(pd1)));
|
||||||
|
|
||||||
Method rm1 = C.class.getMethod("getFoo");
|
Method rm1 = C.class.getMethod("getFoo");
|
||||||
Object pd4 = new SimpleNonIndexedPropertyDescriptor("foo", rm1, null);
|
Object pd4 = new SimplePropertyDescriptor("foo", rm1, null);
|
||||||
assertThat(pd1, not(equalTo(pd4)));
|
assertThat(pd1, not(equalTo(pd4)));
|
||||||
assertThat(pd4, not(equalTo(pd1)));
|
assertThat(pd4, not(equalTo(pd1)));
|
||||||
|
|
||||||
|
@ -147,4 +147,5 @@ public class SimplePropertyDescriptorTests {
|
||||||
assertThat(pd1, not(equalTo(pd7)));
|
assertThat(pd1, not(equalTo(pd7)));
|
||||||
assertThat(pd7, not(equalTo(pd1)));
|
assertThat(pd7, not(equalTo(pd1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue