You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/19 21:28:26 UTC
svn commit: r476910 - in
/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans:
BeanInfoImpl.java EventHandler.java EventSetDescriptor.java
IndexedPropertyDescriptor.java PropertyDescriptor.java Statement.java
Author: ndbeyer
Date: Sun Nov 19 12:28:25 2006
New Revision: 476910
URL: http://svn.apache.org/viewvc?view=rev&rev=476910
Log:
Add missing type variables (Class<?>[]), remove unnecessary initializations, add missing modifiers, format code
Modified:
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/BeanInfoImpl.java Sun Nov 19 12:28:25 2006
@@ -153,7 +153,7 @@
}
if (result.get(listenerName) == null) {
- Class[] parameterTypes = method.getParameterTypes();
+ Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1) {
Class<?> listenerType = parameterTypes[0];
@@ -199,7 +199,7 @@
Method[] methods = listenerType.getMethods();
Vector<Method> listenerMethodsVec = new Vector<Method>();
for (Method element : methods) {
- Class[] listenerMethodParams = element
+ Class<?>[] listenerMethodParams = element
.getParameterTypes();
if (listenerMethodParams.length == 1
@@ -320,7 +320,7 @@
int modifiers = method.getModifiers();
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
- Class[] parameterTypes = method.getParameterTypes();
+ Class<?>[] parameterTypes = method.getParameterTypes();
Class<?> returnType = method.getReturnType();
if (name.startsWith("get") && (parameterTypes.length == 0) //$NON-NLS-1$
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventHandler.java Sun Nov 19 12:28:25 2006
@@ -221,7 +221,7 @@
// can be invoke with any listener method
if (listenerMethodName == null) {
- Class[] proxyInterfaces = proxy.getClass().getInterfaces();
+ Class<?>[] proxyInterfaces = proxy.getClass().getInterfaces();
for (Class<?> proxyInstance : proxyInterfaces) {
Method[] interfaceMethods = proxyInstance.getMethods();
@@ -353,7 +353,7 @@
}
private static boolean canInvokeWithArguments(Method m, Object[] arguments) {
- Class[] parameterTypes = m.getParameterTypes();
+ Class<?>[] parameterTypes = m.getParameterTypes();
if (parameterTypes.length == arguments.length) {
for (int i = 0; i < arguments.length; ++i) {
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java Sun Nov 19 12:28:25 2006
@@ -21,188 +21,129 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TooManyListenersException;
-
import org.apache.harmony.beans.internal.nls.Messages;
public class EventSetDescriptor extends FeatureDescriptor {
-
- // XXX: never read
- // private String eventSetName = null;
-
- private Class<?> listenerType = null;
+ private Class<?> listenerType;
private final ArrayList<MethodDescriptor> listenerMethodDescriptors = new ArrayList<MethodDescriptor>();
- private Method getListenerMethod = null;
+ private Method getListenerMethod;
- private Method addListenerMethod = null;
+ private Method addListenerMethod;
- private Method removeListenerMethod = null;
+ private Method removeListenerMethod;
- private boolean unicast = false;
+ private boolean unicast;
private boolean inDefaultEventSet = true;
- public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
- Class<?> listenerType, String listenerMethodName)
- throws IntrospectionException {
-
+ public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?> listenerType,
+ String listenerMethodName) throws IntrospectionException {
super();
-
if (eventSetName == null) {
throw new NullPointerException();
}
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
- this.listenerMethodDescriptors.add(new MethodDescriptor(
- findMethodByName(listenerType, listenerMethodName)));
-
+ this.listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(listenerType,
+ listenerMethodName)));
this.addListenerMethod = findMethodByPrefix(sourceClass, "add", "", //$NON-NLS-1$ //$NON-NLS-2$
listenerType);
this.removeListenerMethod = findMethodByPrefix(sourceClass, "remove", //$NON-NLS-1$
"", listenerType); //$NON-NLS-1$
-
if (addListenerMethod == null && removeListenerMethod == null) {
throw new IntrospectionException(Messages.getString("beans.38")); //$NON-NLS-1$
}
-
this.getListenerMethod = findMethodByPrefix(sourceClass, "get", "s", //$NON-NLS-1$ //$NON-NLS-2$
listenerType);
-
this.unicast = isUnicastByDefault(addListenerMethod);
}
- public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
- Class<?> listenerType, String[] listenerMethodNames,
- String addListenerMethodName, String removeListenerMethodName)
- throws IntrospectionException {
+ public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?> listenerType,
+ String[] listenerMethodNames, String addListenerMethodName,
+ String removeListenerMethodName) throws IntrospectionException {
super();
-
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
if (listenerMethodNames == null) {
throw new NullPointerException();
}
-
for (String element : listenerMethodNames) {
try {
- listenerMethodDescriptors
- .add(new MethodDescriptor(findMethodByName(
- listenerType, element)));
+ listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(
+ listenerType, element)));
} catch (IntrospectionException ie) {
listenerMethodDescriptors.clear();
throw ie;
}
}
-
- this.addListenerMethod = findMethodByName(listenerType,
- addListenerMethodName);
- this.removeListenerMethod = findMethodByName(listenerType,
- removeListenerMethodName);
+ this.addListenerMethod = findMethodByName(listenerType, addListenerMethodName);
+ this.removeListenerMethod = findMethodByName(listenerType, removeListenerMethodName);
this.getListenerMethod = null;
-
this.unicast = isUnicastByDefault(addListenerMethod);
}
- public EventSetDescriptor(Class<?> sourceClass, String eventSetName,
- Class<?> listenerType, String[] listenerMethodNames,
- String addListenerMethodName, String removeListenerMethodName,
- String getListenerMethodName) throws IntrospectionException {
+ public EventSetDescriptor(Class<?> sourceClass, String eventSetName, Class<?> listenerType,
+ String[] listenerMethodNames, String addListenerMethodName,
+ String removeListenerMethodName, String getListenerMethodName)
+ throws IntrospectionException {
super();
-
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
if (listenerMethodNames == null) {
throw new NullPointerException();
}
for (String element : listenerMethodNames) {
try {
- listenerMethodDescriptors.add(new MethodDescriptor(
- findMethodByName(listenerType, element)));
+ listenerMethodDescriptors.add(new MethodDescriptor(findMethodByName(
+ listenerType, element)));
} catch (IntrospectionException ie) {
listenerMethodDescriptors.clear();
throw ie;
}
}
-
- this.addListenerMethod = findMethodByName(listenerType,
- addListenerMethodName);
- this.removeListenerMethod = findMethodByName(listenerType,
- removeListenerMethodName);
- this.getListenerMethod = findMethodByName(listenerType,
- getListenerMethodName);
-
+ this.addListenerMethod = findMethodByName(listenerType, addListenerMethodName);
+ this.removeListenerMethod = findMethodByName(listenerType, removeListenerMethodName);
+ this.getListenerMethod = findMethodByName(listenerType, getListenerMethodName);
this.unicast = isUnicastByDefault(addListenerMethod);
}
public EventSetDescriptor(String eventSetName, Class<?> listenerType,
- Method[] listenerMethods, Method addListenerMethod,
- Method removeListenerMethod) throws IntrospectionException {
+ Method[] listenerMethods, Method addListenerMethod, Method removeListenerMethod)
+ throws IntrospectionException {
super();
-
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
if (listenerMethods != null) {
for (Method element : listenerMethods) {
if (checkMethod(listenerType, element)) {
- this.listenerMethodDescriptors.add(new MethodDescriptor(
- element));
+ this.listenerMethodDescriptors.add(new MethodDescriptor(element));
}
}
}
-
this.addListenerMethod = addListenerMethod;
this.removeListenerMethod = removeListenerMethod;
}
public EventSetDescriptor(String eventSetName, Class<?> listenerType,
- Method[] listenerMethods, Method addListenerMethod,
- Method removeListenerMethod, Method getListenerMethod)
- throws IntrospectionException {
-
+ Method[] listenerMethods, Method addListenerMethod, Method removeListenerMethod,
+ Method getListenerMethod) throws IntrospectionException {
super();
-
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
if (listenerMethods != null) {
for (Method element : listenerMethods) {
if (checkMethod(listenerType, element)) {
- this.listenerMethodDescriptors.add(new MethodDescriptor(
- element));
+ this.listenerMethodDescriptors.add(new MethodDescriptor(element));
}
}
}
-
this.addListenerMethod = addListenerMethod;
this.removeListenerMethod = removeListenerMethod;
this.getListenerMethod = getListenerMethod;
@@ -210,23 +151,15 @@
}
public EventSetDescriptor(String eventSetName, Class<?> listenerType,
- MethodDescriptor[] listenerMethodDescriptors,
- Method addListenerMethod, Method removeListenerMethod)
- throws IntrospectionException {
+ MethodDescriptor[] listenerMethodDescriptors, Method addListenerMethod,
+ Method removeListenerMethod) throws IntrospectionException {
super();
-
setName(eventSetName);
setDisplayName(eventSetName);
-
- // XXX: never read
- // this.eventSetName = eventSetName;
-
this.listenerType = listenerType;
-
if (listenerMethodDescriptors != null) {
for (MethodDescriptor element : listenerMethodDescriptors) {
Method listenerMethod = element.getMethod();
-
if (checkMethod(listenerType, listenerMethod)) {
this.listenerMethodDescriptors.add(element);
}
@@ -242,10 +175,8 @@
Method[] result = new Method[listenerMethodDescriptors.size()];
Iterator<MethodDescriptor> i = listenerMethodDescriptors.iterator();
int idx = 0;
-
while (i.hasNext()) {
MethodDescriptor md = i.next();
-
result[idx] = md.getMethod();
idx++;
}
@@ -253,11 +184,9 @@
}
public MethodDescriptor[] getListenerMethodDescriptors() {
- MethodDescriptor[] result = new MethodDescriptor[listenerMethodDescriptors
- .size()];
+ MethodDescriptor[] result = new MethodDescriptor[listenerMethodDescriptors.size()];
Iterator<MethodDescriptor> i = listenerMethodDescriptors.iterator();
int idx = 0;
-
while (i.hasNext()) {
result[idx] = i.next();
idx++;
@@ -297,31 +226,28 @@
return inDefaultEventSet;
}
- private Class<?> getEventType(Class<?> listenerType)
- throws ClassNotFoundException {
+ private Class<?> getEventType(Class<?> listenerType) throws ClassNotFoundException {
String listenerTypeName = listenerType.getName();
int idx = listenerTypeName.lastIndexOf("Listener"); //$NON-NLS-1$
String eventTypeName = listenerTypeName;
if (idx != -1) {
eventTypeName = listenerTypeName.substring(0, idx) + "Event"; //$NON-NLS-1$
}
- return Class
- .forName(eventTypeName, true, listenerType.getClassLoader());
+ return Class.forName(eventTypeName, true, listenerType.getClassLoader());
}
private boolean checkMethod(Class<?> listenerType, Method listenerMethod)
throws IntrospectionException {
if (listenerMethod != null
- && !listenerMethod.getDeclaringClass().isAssignableFrom(
- listenerType)) {
+ && !listenerMethod.getDeclaringClass().isAssignableFrom(listenerType)) {
throw new IntrospectionException(Messages.getString("beans.31", //$NON-NLS-1$
listenerMethod.getName(), listenerType.getName()));
}
return true;
}
- private Method findMethodByName(Class<?> listenerType,
- String listenerMethodName) throws IntrospectionException {
+ private Method findMethodByName(Class<?> listenerType, String listenerMethodName)
+ throws IntrospectionException {
try {
return listenerType.getMethod(listenerMethodName,
new Class[] { getEventType(listenerType) });
@@ -334,29 +260,24 @@
}
}
- private Method findMethodByPrefix(Class<?> sourceClass, String prefix,
- String postfix, Class<?> listenerType) {
-
+ private Method findMethodByPrefix(Class<?> sourceClass, String prefix, String postfix,
+ Class<?> listenerType) {
String fullName = listenerType.getName();
int idx = fullName.lastIndexOf("."); //$NON-NLS-1$
String methodName = prefix + fullName.substring(idx + 1) + postfix;
-
try {
if (prefix.equals("get")) { //$NON-NLS-1$
return sourceClass.getMethod(methodName, new Class[] {});
}
- return sourceClass.getMethod(methodName,
- new Class[] { listenerType });
+ return sourceClass.getMethod(methodName, new Class[] { listenerType });
} catch (NoSuchMethodException nsme) {
return null;
}
-
}
private static boolean isUnicastByDefault(Method addMethod) {
if (addMethod != null) {
- Class[] exceptionTypes = addMethod.getExceptionTypes();
-
+ Class<?>[] exceptionTypes = addMethod.getExceptionTypes();
for (Class<?> element : exceptionTypes) {
if (element.equals(TooManyListenersException.class)) {
return true;
@@ -372,13 +293,11 @@
return null;
}
Class<?> returnType = registrationMethod.getReturnType();
- Class[] parameterTypes;
-
+ Class<?>[] parameterTypes;
if (returnType != void.class) {
throw new IntrospectionException(Messages.getString(
"beans.33", registrationMethod.getName())); //$NON-NLS-1$
}
-
parameterTypes = registrationMethod.getParameterTypes();
if (parameterTypes == null || parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString(
@@ -391,21 +310,18 @@
}
}
- private static Method checkGetListenerMethod(Class<?> listenerType,
- Method getListenerMethod) throws IntrospectionException {
+ private static Method checkGetListenerMethod(Class<?> listenerType, Method getListenerMethod)
+ throws IntrospectionException {
if (getListenerMethod == null) {
return null;
}
- Class[] parameterTypes = getListenerMethod.getParameterTypes();
+ Class<?>[] parameterTypes = getListenerMethod.getParameterTypes();
Class<?> returnType;
-
if (parameterTypes.length != 0) {
throw new IntrospectionException(Messages.getString("beans.36")); //$NON-NLS-1$
}
-
returnType = getListenerMethod.getReturnType();
- if (returnType.isArray()
- && returnType.getComponentType() == listenerType) {
+ if (returnType.isArray() && returnType.getComponentType() == listenerType) {
return getListenerMethod;
}
throw new IntrospectionException(Messages.getString("beans.37")); //$NON-NLS-1$
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java Sun Nov 19 12:28:25 2006
@@ -19,28 +19,23 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-
import org.apache.harmony.beans.internal.nls.Messages;
public class IndexedPropertyDescriptor extends PropertyDescriptor {
+ private Method indexedGetter;
- private Method indexedGetter = null;
-
- private Method indexedSetter = null;
+ private Method indexedSetter;
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass,
String getterName, String setterName, String indexedGetterName,
String indexedSetterName) throws IntrospectionException {
-
super(propertyName, beanClass, getterName, setterName);
setIndexedReadMethod(beanClass, indexedGetterName);
setIndexedWriteMethod(beanClass, indexedSetterName);
}
- public IndexedPropertyDescriptor(String propertyName, Method getter,
- Method setter, Method indexedGetter, Method indexedSetter)
- throws IntrospectionException {
-
+ public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter,
+ Method indexedGetter, Method indexedSetter) throws IntrospectionException {
super(propertyName, getter, setter);
setIndexedReadMethod(indexedGetter);
setIndexedWriteMethod(indexedSetter);
@@ -48,109 +43,87 @@
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
-
super(propertyName, beanClass, null, null);
-
String getterName;
String setterName;
String indexedGetterName;
String indexedSetterName;
-
// array getter
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
}
-
// array setter
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
- }
-
+ }
// indexed getter
indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedGetterName)) {
setIndexedReadMethod(beanClass, indexedGetterName);
}
-
// indexed setter
indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, indexedSetterName)) {
setIndexedWriteMethod(beanClass, indexedSetterName);
}
-
// RI seems to behave a bit differently
- if (indexedGetter == null && indexedSetter == null &&
- getReadMethod() == null && getWriteMethod() == null) {
- throw new IntrospectionException(Messages.getString(
- "beans.01", propertyName)); //$NON-NLS-1$
+ if (indexedGetter == null && indexedSetter == null && getReadMethod() == null
+ && getWriteMethod() == null) {
+ throw new IntrospectionException(Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
}
}
- public void setIndexedReadMethod(Method indexedGetter)
- throws IntrospectionException {
+ public void setIndexedReadMethod(Method indexedGetter) throws IntrospectionException {
if (indexedGetter != null) {
int modifiers = indexedGetter.getModifiers();
- Class[] parameterTypes;
+ Class<?>[] parameterTypes;
Class<?> returnType;
Class<?> indexedPropertyType;
-
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
}
-
parameterTypes = indexedGetter.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
}
-
if (!parameterTypes[0].equals(int.class)) {
throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
}
-
returnType = indexedGetter.getReturnType();
indexedPropertyType = getIndexedPropertyType();
- if ((indexedPropertyType != null)
- && !returnType.equals(indexedPropertyType)) {
+ if ((indexedPropertyType != null) && !returnType.equals(indexedPropertyType)) {
throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
}
}
-
this.indexedGetter = indexedGetter;
}
- public void setIndexedWriteMethod(Method indexedSetter)
- throws IntrospectionException {
-
+ public void setIndexedWriteMethod(Method indexedSetter) throws IntrospectionException {
if (indexedSetter != null) {
int modifiers = indexedSetter.getModifiers();
- Class[] parameterTypes;
+ Class<?>[] parameterTypes;
Class<?> firstParameterType;
Class<?> secondParameterType;
Class<?> propType;
-
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
}
-
parameterTypes = indexedSetter.getParameterTypes();
if (parameterTypes.length != 2) {
throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
}
-
firstParameterType = parameterTypes[0];
if (!firstParameterType.equals(int.class)) {
throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
}
-
secondParameterType = parameterTypes[1];
propType = getIndexedPropertyType();
if (propType != null && !secondParameterType.equals(propType)) {
throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
}
}
-
this.indexedSetter = indexedSetter;
}
@@ -179,31 +152,28 @@
if (indexedGetter != null) {
result = indexedGetter.getReturnType();
} else if (indexedSetter != null) {
- Class[] parameterTypes = indexedSetter.getParameterTypes();
+ Class<?>[] parameterTypes = indexedSetter.getParameterTypes();
result = parameterTypes[1];
}
return result;
}
- private void setIndexedReadMethod(Class<?> beanClass,
- String indexedGetterName) {
+ private void setIndexedReadMethod(Class<?> beanClass, String indexedGetterName) {
Method[] getters = findMethods(beanClass, indexedGetterName);
boolean result = false;
-
for (Method element : getters) {
try {
setIndexedReadMethod(element);
result = true;
- } catch (IntrospectionException ie) {}
-
+ } catch (IntrospectionException ie) {
+ }
if (result) {
break;
}
}
}
- private void setIndexedWriteMethod(Class<?> beanClass,
- String indexedSetterName) {
+ private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName) {
Method[] setters = findMethods(beanClass, indexedSetterName);
boolean result = false;
for (Method element : setters) {
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Sun Nov 19 12:28:25 2006
@@ -21,43 +21,30 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Vector;
-
import org.apache.harmony.beans.internal.nls.Messages;
public class PropertyDescriptor extends FeatureDescriptor {
+ private Method getter;
- Class<?> beanClass = null;
-
- String propertyName = null;
-
- Method getter = null;
-
- Method setter = null;
-
- Class<?> propertyEditorClass = null;
+ private Method setter;
- boolean constrained = false;
+ private Class<?> propertyEditorClass;
- boolean bound = false;
+ private boolean constrained;
- public PropertyDescriptor(String propertyName, Class<?> beanClass,
- String getterName, String setterName) throws IntrospectionException {
+ private boolean bound;
+ public PropertyDescriptor(String propertyName, Class<?> beanClass, String getterName,
+ String setterName) throws IntrospectionException {
super();
-
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
-
- this.beanClass = beanClass;
- this.propertyName = propertyName;
-
this.setName(propertyName);
this.setDisplayName(propertyName);
-
if (setterName != null) {
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
@@ -65,7 +52,6 @@
throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
}
}
-
if (getterName != null) {
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
@@ -81,12 +67,8 @@
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
-
- this.propertyName = propertyName;
-
this.setName(propertyName);
this.setDisplayName(propertyName);
-
setWriteMethod(setter);
setReadMethod(getter);
}
@@ -95,19 +77,14 @@
throws IntrospectionException {
String getterName;
String setterName;
-
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
-
- this.propertyName = propertyName;
-
this.setName(propertyName);
this.setDisplayName(propertyName);
-
getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
@@ -117,17 +94,13 @@
setReadMethod(beanClass, getterName);
}
}
-
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
}
-
if (getter == null && setter == null) {
- throw new IntrospectionException(Messages.getString(
- "beans.01", propertyName)); //$NON-NLS-1$
+ throw new IntrospectionException(Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
}
-
}
public void setWriteMethod(Method setter) throws IntrospectionException {
@@ -136,19 +109,16 @@
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.05")); //$NON-NLS-1$
}
-
- Class[] parameterTypes = setter.getParameterTypes();
+ Class<?>[] parameterTypes = setter.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString("beans.06")); //$NON-NLS-1$
}
-
Class<?> parameterType = parameterTypes[0];
Class<?> propertyType = getPropertyType();
if (propertyType != null && !propertyType.equals(parameterType)) {
throw new IntrospectionException(Messages.getString("beans.07")); //$NON-NLS-1$
}
}
-
this.setter = setter;
}
@@ -158,12 +128,10 @@
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.0A")); //$NON-NLS-1$
}
-
- Class[] parameterTypes = getter.getParameterTypes();
+ Class<?>[] parameterTypes = getter.getParameterTypes();
if (parameterTypes.length != 0) {
throw new IntrospectionException(Messages.getString("beans.08")); //$NON-NLS-1$
}
-
Class<?> returnType = getter.getReturnType();
if (returnType.equals(Void.TYPE)) {
throw new IntrospectionException(Messages.getString("beans.33")); //$NON-NLS-1$
@@ -173,7 +141,6 @@
throw new IntrospectionException(Messages.getString("beans.09")); //$NON-NLS-1$
}
}
-
this.getter = getter;
}
@@ -190,26 +157,18 @@
boolean result = (object != null && object instanceof PropertyDescriptor);
if (result) {
PropertyDescriptor pd = (PropertyDescriptor) object;
-
- boolean gettersAreEqual = (this.getter == null)
- && (pd.getReadMethod() == null) || (this.getter != null)
- && (this.getter.equals(pd.getReadMethod()));
-
- boolean settersAreEqual = (this.setter == null)
- && (pd.getWriteMethod() == null) || (this.setter != null)
- && (this.setter.equals(pd.getWriteMethod()));
-
- boolean propertyTypesAreEqual = this.getPropertyType() == pd
- .getPropertyType();
- boolean propertyEditorClassesAreEqual = this
- .getPropertyEditorClass() == pd.getPropertyEditorClass();
+ boolean gettersAreEqual = (this.getter == null) && (pd.getReadMethod() == null)
+ || (this.getter != null) && (this.getter.equals(pd.getReadMethod()));
+ boolean settersAreEqual = (this.setter == null) && (pd.getWriteMethod() == null)
+ || (this.setter != null) && (this.setter.equals(pd.getWriteMethod()));
+ boolean propertyTypesAreEqual = this.getPropertyType() == pd.getPropertyType();
+ boolean propertyEditorClassesAreEqual = this.getPropertyEditorClass() == pd
+ .getPropertyEditorClass();
boolean boundPropertyAreEqual = this.isBound() == pd.isBound();
- boolean constrainedPropertyAreEqual = this.isConstrained() == pd
- .isConstrained();
-
- result = gettersAreEqual && settersAreEqual
- && propertyTypesAreEqual && propertyEditorClassesAreEqual
- && boundPropertyAreEqual && constrainedPropertyAreEqual;
+ boolean constrainedPropertyAreEqual = this.isConstrained() == pd.isConstrained();
+ result = gettersAreEqual && settersAreEqual && propertyTypesAreEqual
+ && propertyEditorClassesAreEqual && boundPropertyAreEqual
+ && constrainedPropertyAreEqual;
}
return result;
}
@@ -223,7 +182,7 @@
if (getter != null) {
result = getter.getReturnType();
} else if (setter != null) {
- Class[] parameterTypes = setter.getParameterTypes();
+ Class<?>[] parameterTypes = setter.getParameterTypes();
result = parameterTypes[0];
}
return result;
@@ -268,52 +227,42 @@
Method[] allMethods = aClass.getMethods();
Vector<Method> matchedMethods = new Vector<Method>();
Method[] result;
-
for (Method method : allMethods) {
if (method.getName().equals(methodName)) {
matchedMethods.add(method);
}
}
-
result = new Method[matchedMethods.size()];
for (int j = 0; j < matchedMethods.size(); ++j) {
result[j] = matchedMethods.elementAt(j);
}
-
return result;
}
void setReadMethod(Class<?> beanClass, String getterName) {
boolean result = false;
-
Method[] getters = findMethods(beanClass, getterName);
-
for (Method element : getters) {
try {
setReadMethod(element);
result = true;
} catch (IntrospectionException ie) {
}
-
if (result) {
break;
}
}
}
- void setWriteMethod(Class<?> beanClass, String setterName)
- throws IntrospectionException {
+ void setWriteMethod(Class<?> beanClass, String setterName) throws IntrospectionException {
boolean result = false;
-
Method[] setters = findMethods(beanClass, setterName);
-
for (Method element : setters) {
try {
setWriteMethod(element);
result = true;
} catch (IntrospectionException ie) {
}
-
if (result) {
break;
}
@@ -322,20 +271,16 @@
public PropertyEditor createPropertyEditor(Object bean) {
PropertyEditor editor;
-
if (propertyEditorClass == null) {
return null;
}
-
if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) {
// beans.48=Property editor is not assignable from the
// PropertyEditor interface
throw new ClassCastException(Messages.getString("beans.48")); //$NON-NLS-1$
}
-
try {
Constructor<?> constr;
-
try {
// try to look for the constructor with single Object argument
constr = propertyEditorClass.getConstructor(Object.class);
@@ -347,9 +292,7 @@
}
} catch (Exception e) {
// beans.47=Unable to instantiate property editor
- RuntimeException re = new RuntimeException(Messages
- .getString("beans.47"), e); //$NON-NLS-1$
-
+ RuntimeException re = new RuntimeException(Messages.getString("beans.47"), e); //$NON-NLS-1$
throw re;
}
return editor;
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java?view=diff&rev=476910&r1=476909&r2=476910
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java Sun Nov 19 12:28:25 2006
@@ -25,12 +25,11 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Map;
import java.util.Vector;
-
import org.apache.harmony.beans.internal.nls.Messages;
public class Statement {
-
private Object target;
private String methodName;
@@ -49,21 +48,17 @@
@Override
public String toString() {
- StringBuffer sb = new StringBuffer();
- String targetVar = target != null ? convertClassName(target.getClass())
- : "null"; //$NON-NLS-1$
-
+ StringBuilder sb = new StringBuilder();
+ String targetVar = target != null ? convertClassName(target.getClass()) : "null"; //$NON-NLS-1$
sb.append(targetVar);
sb.append('.');
sb.append(methodName);
sb.append('(');
-
if (arguments != null) {
for (int i = 0; i < arguments.length; ++i) {
if (i > 0) {
sb.append(", "); //$NON-NLS-1$
}
-
if (arguments[i] == null) {
sb.append("null"); //$NON-NLS-1$
} else if (arguments[i] instanceof String) {
@@ -102,70 +97,57 @@
if (target.getClass().isArray()) {
Method method = findArrayMethod();
Object[] ama = getArrayMethodArguments();
-
result = method.invoke(null, ama);
} else if (methodName.equals("newInstance") //$NON-NLS-1$
&& target == Array.class) {
Class<?> componentType = (Class) arguments[0];
int length = ((Integer) arguments[1]).intValue();
-
result = Array.newInstance(componentType, length);
} else if (methodName.equals("new") //$NON-NLS-1$
|| methodName.equals("newInstance")) { //$NON-NLS-1$
if (target instanceof Class) {
Constructor<?> constructor = findConstructor();
-
result = constructor.newInstance(arguments);
} else {
// XXX should be investigated, dead code?
Constructor<?> constructor = findConstructor();
-
result = constructor.newInstance(arguments);
}
} else if (target instanceof Class) {
Method method = null;
boolean found = false;
-
try {
- // try to look for a static method of class
- // described by the given Class object at first
-
- // process only if the class differs from Class itself
+ /*
+ * Try to look for a static method of class described by the
+ * given Class object at first process only if the class
+ * differs from Class itself
+ */
if (target != Class.class) {
- method = findMethod((Class) target, methodName,
- arguments, true);
+ method = findMethod((Class) target, methodName, arguments, true);
result = method.invoke(null, arguments);
found = true;
}
} catch (NoSuchMethodException e) {
}
-
if (!found) {
// static method was not found
// try to invoke method of Class object
-
if (methodName.equals("forName") //$NON-NLS-1$
- && arguments.length == 1
- && arguments[0] instanceof String) {
+ && arguments.length == 1 && arguments[0] instanceof String) {
// special handling of Class.forName(String)
-
try {
result = Class.forName((String) arguments[0]);
} catch (ClassNotFoundException e2) {
- result = Class.forName((String) arguments[0], true,
- Thread.currentThread()
- .getContextClassLoader());
+ result = Class.forName((String) arguments[0], true, Thread
+ .currentThread().getContextClassLoader());
}
} else {
- method = findMethod(target.getClass(), methodName,
- arguments, false);
+ method = findMethod(target.getClass(), methodName, arguments, false);
result = method.invoke(target, arguments);
}
}
} else {
- Method method = findMethod(target.getClass(), methodName,
- arguments, false);
-
+ Method method = findMethod(target.getClass(), methodName, arguments, false);
// XXX investigate: do we really need this?
// AccessController.doPrivileged(new PrivilegedAction<Object>()
// {
@@ -175,12 +157,10 @@
// return null;
// }
// });
-
result = method.invoke(target, arguments);
}
} catch (InvocationTargetException ite) {
Throwable t = ite.getCause();
-
throw (t != null) && (t instanceof Exception) ? (Exception) t : ite;
}
return result;
@@ -190,17 +170,13 @@
// the code below reproduces exact RI exception throwing behavior
if (!methodName.equals("set") && !methodName.equals("get")) { //$NON-NLS-1$ //$NON-NLS-2$
throw new NoSuchMethodException(Messages.getString("beans.3C")); //$NON-NLS-1$
- } else if (arguments.length > 0
- && arguments[0].getClass() != Integer.class) {
+ } else if (arguments.length > 0 && arguments[0].getClass() != Integer.class) {
throw new ClassCastException(Messages.getString("beans.3D")); //$NON-NLS-1$
} else if (methodName.equals("get") && (arguments.length != 1)) { //$NON-NLS-1$
- throw new ArrayIndexOutOfBoundsException(Messages
- .getString("beans.3E")); //$NON-NLS-1$
+ throw new ArrayIndexOutOfBoundsException(Messages.getString("beans.3E")); //$NON-NLS-1$
} else if (methodName.equals("set") && (arguments.length != 2)) { //$NON-NLS-1$
- throw new ArrayIndexOutOfBoundsException(Messages
- .getString("beans.3F")); //$NON-NLS-1$
+ throw new ArrayIndexOutOfBoundsException(Messages.getString("beans.3F")); //$NON-NLS-1$
}
-
if (methodName.equals("get")) { //$NON-NLS-1$
return Array.class.getMethod("get", new Class[] { Object.class, //$NON-NLS-1$
int.class });
@@ -219,120 +195,91 @@
}
private Constructor<?> findConstructor() throws NoSuchMethodException {
- Class[] argClasses = getClasses(arguments);
+ Class<?>[] argClasses = getClasses(arguments);
Class<?> targetClass = (Class) target;
-
Constructor<?> result = null;
- Constructor[] constructors = targetClass.getConstructors();
-
+ Constructor<?>[] constructors = targetClass.getConstructors();
for (Constructor<?> constructor : constructors) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
-
if (parameterTypes.length == argClasses.length) {
boolean found = true;
-
for (int j = 0; j < parameterTypes.length; ++j) {
boolean argIsNull = argClasses[j] == null;
- boolean argIsPrimitiveWrapper = isPrimitiveWrapper(
- argClasses[j], parameterTypes[j]);
+ boolean argIsPrimitiveWrapper = isPrimitiveWrapper(argClasses[j],
+ parameterTypes[j]);
boolean paramIsPrimitive = parameterTypes[j].isPrimitive();
- boolean paramIsAssignable = argIsNull ? false
- : parameterTypes[j].isAssignableFrom(argClasses[j]);
-
- if (!argIsNull && !paramIsAssignable
- && !argIsPrimitiveWrapper || argIsNull
+ boolean paramIsAssignable = argIsNull ? false : parameterTypes[j]
+ .isAssignableFrom(argClasses[j]);
+ if (!argIsNull && !paramIsAssignable && !argIsPrimitiveWrapper || argIsNull
&& paramIsPrimitive) {
found = false;
break;
}
}
-
if (found) {
result = constructor;
break;
}
}
}
-
if (result == null) {
throw new NoSuchMethodException(Messages.getString(
"beans.40", targetClass.getName())); //$NON-NLS-1$
}
-
return result;
}
/**
* Searches for best matching method for given name and argument types.
*/
- static Method findMethod(Class<?> targetClass, String methodName,
- Object[] arguments, boolean methodIsStatic)
- throws NoSuchMethodException {
-
- Class[] argClasses = getClasses(arguments);
+ static Method findMethod(Class<?> targetClass, String methodName, Object[] arguments,
+ boolean methodIsStatic) throws NoSuchMethodException {
+ Class<?>[] argClasses = getClasses(arguments);
Method[] methods = targetClass.getMethods();
Vector<Method> foundMethods = new Vector<Method>();
Method[] foundMethodsArr;
-
for (Method method : methods) {
int mods = method.getModifiers();
-
if (method.getName().equals(methodName)
&& (methodIsStatic ? Modifier.isStatic(mods) : true)) {
-
Class<?>[] parameterTypes = method.getParameterTypes();
-
if (parameterTypes.length == argClasses.length) {
boolean found = true;
-
for (int j = 0; j < parameterTypes.length; ++j) {
boolean argIsNull = (argClasses[j] == null);
- boolean argIsPrimitiveWrapper = isPrimitiveWrapper(
- argClasses[j], parameterTypes[j]);
- boolean paramIsPrimitive = parameterTypes[j]
- .isPrimitive();
- boolean paramIsAssignable = argIsNull ? false
- : parameterTypes[j]
- .isAssignableFrom(argClasses[j]);
-
- if (!argIsNull && !paramIsAssignable
- && !argIsPrimitiveWrapper || argIsNull
- && paramIsPrimitive) {
+ boolean argIsPrimitiveWrapper = isPrimitiveWrapper(argClasses[j],
+ parameterTypes[j]);
+ boolean paramIsPrimitive = parameterTypes[j].isPrimitive();
+ boolean paramIsAssignable = argIsNull ? false : parameterTypes[j]
+ .isAssignableFrom(argClasses[j]);
+ if (!argIsNull && !paramIsAssignable && !argIsPrimitiveWrapper
+ || argIsNull && paramIsPrimitive) {
found = false;
break;
}
}
-
if (found) {
foundMethods.addElement(method);
}
}
}
}
-
if (foundMethods.size() == 0) {
- throw new NoSuchMethodException(Messages.getString(
- "beans.41", methodName)); //$NON-NLS-1$
+ throw new NoSuchMethodException(Messages.getString("beans.41", methodName)); //$NON-NLS-1$
}
-
foundMethodsArr = foundMethods.toArray(new Method[foundMethods.size()]);
- Arrays.sort(foundMethodsArr, new MethodComparator(methodName,
- argClasses));
-
+ Arrays.sort(foundMethodsArr, new MethodComparator(methodName, argClasses));
return foundMethodsArr[0];
}
static boolean isStaticMethodCall(Statement stmt) {
Object target = stmt.getTarget();
String mName = stmt.getMethodName();
-
if (!(target instanceof Class)) {
return false;
}
-
try {
- Statement.findMethod((Class) target, mName, stmt.getArguments(),
- true);
+ Statement.findMethod((Class) target, mName, stmt.getArguments(), true);
return true;
} catch (NoSuchMethodException e) {
return false;
@@ -365,43 +312,34 @@
String methodName = stmt.getMethodName();
Object[] args = stmt.getArguments();
String[] sig = new String[pdConstructorSignatures[0].length];
-
- if (target == null || methodName == null || args == null
- || args.length == 0) {
+ if (target == null || methodName == null || args == null || args.length == 0) {
// not a constructor for sure
return false;
}
-
sig[0] = target.getClass().getName();
sig[1] = methodName;
-
for (int i = 2; i < sig.length; i++) {
if (args.length > i - 2) {
- sig[i] = args[i - 2] != null ? args[i - 2].getClass().getName()
- : "null"; //$NON-NLS-1$
+ sig[i] = args[i - 2] != null ? args[i - 2].getClass().getName() : "null"; //$NON-NLS-1$
} else {
sig[i] = ""; //$NON-NLS-1$
}
-
}
-
for (String[] element : pdConstructorSignatures) {
if (Arrays.equals(sig, element)) {
return true;
}
}
-
return false;
}
private static boolean isPrimitiveWrapper(Class<?> wrapper, Class<?> base) {
- return (base == boolean.class) && (wrapper == Boolean.class)
- || (base == byte.class) && (wrapper == Byte.class)
- || (base == char.class) && (wrapper == Character.class)
- || (base == short.class) && (wrapper == Short.class)
- || (base == int.class) && (wrapper == Integer.class)
- || (base == long.class) && (wrapper == Long.class)
- || (base == float.class) && (wrapper == Float.class)
+ return (base == boolean.class) && (wrapper == Boolean.class) || (base == byte.class)
+ && (wrapper == Byte.class) || (base == char.class)
+ && (wrapper == Character.class) || (base == short.class)
+ && (wrapper == Short.class) || (base == int.class)
+ && (wrapper == Integer.class) || (base == long.class)
+ && (wrapper == Long.class) || (base == float.class) && (wrapper == Float.class)
|| (base == double.class) && (wrapper == Double.class);
}
@@ -432,21 +370,17 @@
Class<?> resultType = (componentType == null) ? type : componentType;
String result = resultType.getName();
int k = result.lastIndexOf('.');
-
if (k != -1 && k < result.length()) {
result = result.substring(k + 1);
}
-
if (componentType != null) {
result += "Array"; //$NON-NLS-1$
}
-
return result;
}
- private static Class[] getClasses(Object[] arguments) {
- Class[] result = new Class[arguments.length];
-
+ private static Class<?>[] getClasses(Object[] arguments) {
+ Class<?>[] result = new Class[arguments.length];
for (int i = 0; i < arguments.length; ++i) {
result[i] = (arguments[i] == null) ? null : arguments[i].getClass();
}
@@ -457,7 +391,6 @@
public boolean equals(Object o) {
if (o instanceof Statement) {
Statement s = (Statement) o;
-
Object[] otherArguments = s.getArguments();
boolean argsEqual = (otherArguments.length == arguments.length);
if (argsEqual) {
@@ -468,13 +401,11 @@
}
}
}
-
if (!argsEqual) {
return false;
}
- return (s.getTarget() == this.getTarget() && s.getMethodName()
- .equals(this.getMethodName()));
-
+ return (s.getTarget() == this.getTarget() && s.getMethodName().equals(
+ this.getMethodName()));
}
return false;
}
@@ -484,16 +415,15 @@
* method.
*/
static class MethodComparator implements Comparator<Method> {
-
static int INFINITY = Integer.MAX_VALUE;
private String referenceMethodName;
- private Class[] referenceMethodArgumentTypes;
+ private Class<?>[] referenceMethodArgumentTypes;
- private final HashMap<Method, Integer> cache;
+ private final Map<Method, Integer> cache;
- public MethodComparator(String refMethodName, Class[] refArgumentTypes) {
+ public MethodComparator(String refMethodName, Class<?>[] refArgumentTypes) {
this.referenceMethodName = refMethodName;
this.referenceMethodArgumentTypes = refArgumentTypes;
cache = new HashMap<Method, Integer>();
@@ -502,7 +432,6 @@
public int compare(Method m1, Method m2) {
Integer norm1 = cache.get(m1);
Integer norm2 = cache.get(m2);
-
if (norm1 == null) {
norm1 = Integer.valueOf(getNorm(m1));
cache.put(m1, norm1);
@@ -524,16 +453,13 @@
*/
private int getNorm(Method m) {
String methodName = m.getName();
- Class[] argumentTypes = m.getParameterTypes();
+ Class<?>[] argumentTypes = m.getParameterTypes();
int totalNorm = 0;
-
if (!referenceMethodName.equals(methodName)
|| referenceMethodArgumentTypes.length != argumentTypes.length) {
return INFINITY;
}
-
for (int i = 0; i < referenceMethodArgumentTypes.length; i++) {
-
if (referenceMethodArgumentTypes[i] == null) {
if (argumentTypes[i].isPrimitive()) {
return INFINITY;
@@ -541,19 +467,14 @@
// doesn't affect the norm calculation if null
continue;
}
-
if (referenceMethodArgumentTypes[i].isPrimitive()) {
referenceMethodArgumentTypes[i] = getPrimitiveWrapper(referenceMethodArgumentTypes[i]);
}
-
if (argumentTypes[i].isPrimitive()) {
argumentTypes[i] = getPrimitiveWrapper(argumentTypes[i]);
}
-
- totalNorm += getDistance(referenceMethodArgumentTypes[i],
- argumentTypes[i]);
+ totalNorm += getDistance(referenceMethodArgumentTypes[i], argumentTypes[i]);
}
-
return totalNorm;
}
@@ -569,30 +490,25 @@
private static int getDistance(Class<?> clz1, Class<?> clz2) {
Class<?> superClz;
int superDist = INFINITY;
-
if (!clz2.isAssignableFrom(clz1)) {
return INFINITY;
}
if (clz1.getName().equals(clz2.getName())) {
return 0;
}
-
superClz = clz1.getSuperclass();
if (superClz != null) {
superDist = getDistance(superClz, clz2);
}
if (clz2.isInterface()) {
- Class[] interfaces = clz1.getInterfaces();
+ Class<?>[] interfaces = clz1.getInterfaces();
int bestDist = INFINITY;
-
for (Class<?> element : interfaces) {
int curDist = getDistance(element, clz2);
-
if (curDist < bestDist) {
bestDist = curDist;
}
}
-
if (superDist < bestDist) {
bestDist = superDist;
}
@@ -601,5 +517,4 @@
return (superDist != INFINITY ? superDist + 1 : INFINITY);
}
}
-
}