--- a/jdk/src/share/classes/java/beans/Introspector.java Tue Dec 06 16:17:15 2011 -0800
+++ b/jdk/src/share/classes/java/beans/Introspector.java Tue Dec 06 20:25:20 2011 -0800
@@ -97,13 +97,13 @@
// Static Caches to speed up introspection.
private static final WeakCache<Class<?>, Method[]> declaredMethodCache = new WeakCache<>();
- private Class beanClass;
+ private Class<?> beanClass;
private BeanInfo explicitBeanInfo;
private BeanInfo superBeanInfo;
private BeanInfo additionalBeanInfo[];
private boolean propertyChangeSource = false;
- private static Class eventListenerType = EventListener.class;
+ private static Class<EventListener> eventListenerType = EventListener.class;
// These should be removed.
private String defaultEventName;
@@ -111,14 +111,14 @@
private int defaultEventIndex = -1;
private int defaultPropertyIndex = -1;
- // Methods maps from Method objects to MethodDescriptors
- private Map methods;
+ // Methods maps from Method names to MethodDescriptors
+ private Map<String, MethodDescriptor> methods;
// properties maps from String names to PropertyDescriptors
- private Map properties;
+ private Map<String, PropertyDescriptor> properties;
// events maps from String names to EventSetDescriptors
- private Map events;
+ private Map<String, EventSetDescriptor> events;
private final static EventSetDescriptor[] EMPTY_EVENTSETDESCRIPTORS = new EventSetDescriptor[0];
@@ -364,14 +364,14 @@
// Private implementation methods
//======================================================================
- private Introspector(Class beanClass, Class stopClass, int flags)
+ private Introspector(Class<?> beanClass, Class<?> stopClass, int flags)
throws IntrospectionException {
this.beanClass = beanClass;
// Check stopClass is a superClass of startClass.
if (stopClass != null) {
boolean isSuper = false;
- for (Class c = beanClass.getSuperclass(); c != null; c = c.getSuperclass()) {
+ for (Class<?> c = beanClass.getSuperclass(); c != null; c = c.getSuperclass()) {
if (c == stopClass) {
isSuper = true;
}
@@ -386,7 +386,7 @@
explicitBeanInfo = findExplicitBeanInfo(beanClass);
}
- Class superClass = beanClass.getSuperclass();
+ Class<?> superClass = beanClass.getSuperclass();
if (superClass != stopClass) {
int newFlags = flags;
if (newFlags == IGNORE_IMMEDIATE_BEANINFO) {
@@ -432,7 +432,7 @@
* @param beanClass the class type of the bean
* @return Instance of an explicit BeanInfo class or null if one isn't found.
*/
- private static BeanInfo findExplicitBeanInfo(Class beanClass) {
+ private static BeanInfo findExplicitBeanInfo(Class<?> beanClass) {
return ThreadGroupContext.getContext().getBeanInfoFinder().find(beanClass);
}
@@ -482,8 +482,8 @@
continue;
}
String name = method.getName();
- Class argTypes[] = method.getParameterTypes();
- Class resultType = method.getReturnType();
+ Class<?>[] argTypes = method.getParameterTypes();
+ Class<?> resultType = method.getReturnType();
int argCount = argTypes.length;
PropertyDescriptor pd = null;
@@ -541,8 +541,8 @@
processPropertyDescriptors();
// Allocate and populate the result array.
- PropertyDescriptor result[] = new PropertyDescriptor[properties.size()];
- result = (PropertyDescriptor[])properties.values().toArray(result);
+ PropertyDescriptor result[] =
+ properties.values().toArray(new PropertyDescriptor[properties.size()]);
// Set the default index.
if (defaultPropertyName != null) {
@@ -556,16 +556,16 @@
return result;
}
- private HashMap pdStore = new HashMap();
+ private HashMap<String, List<PropertyDescriptor>> pdStore = new HashMap<>();
/**
* Adds the property descriptor to the list store.
*/
private void addPropertyDescriptor(PropertyDescriptor pd) {
String propName = pd.getName();
- List list = (List)pdStore.get(propName);
+ List<PropertyDescriptor> list = pdStore.get(propName);
if (list == null) {
- list = new ArrayList();
+ list = new ArrayList<>();
pdStore.put(propName, list);
}
if (this.beanClass != pd.getClass0()) {
@@ -620,25 +620,25 @@
*/
private void processPropertyDescriptors() {
if (properties == null) {
- properties = new TreeMap();
+ properties = new TreeMap<>();
}
- List list;
+ List<PropertyDescriptor> list;
PropertyDescriptor pd, gpd, spd;
IndexedPropertyDescriptor ipd, igpd, ispd;
- Iterator it = pdStore.values().iterator();
+ Iterator<List<PropertyDescriptor>> it = pdStore.values().iterator();
while (it.hasNext()) {
pd = null; gpd = null; spd = null;
ipd = null; igpd = null; ispd = null;
- list = (List)it.next();
+ list = it.next();
// First pass. Find the latest getter method. Merge properties
// of previous getter methods.
for (int i = 0; i < list.size(); i++) {
- pd = (PropertyDescriptor)list.get(i);
+ pd = list.get(i);
if (pd instanceof IndexedPropertyDescriptor) {
ipd = (IndexedPropertyDescriptor)pd;
if (ipd.getIndexedReadMethod() != null) {
@@ -667,7 +667,7 @@
// Second pass. Find the latest setter method which
// has the same type as the getter method.
for (int i = 0; i < list.size(); i++) {
- pd = (PropertyDescriptor)list.get(i);
+ pd = list.get(i);
if (pd instanceof IndexedPropertyDescriptor) {
ipd = (IndexedPropertyDescriptor)pd;
if (ipd.getIndexedWriteMethod() != null) {
@@ -785,7 +785,7 @@
// which does not have getter and setter methods.
// See regression bug 4984912.
if ( (pd == null) && (list.size() > 0) ) {
- pd = (PropertyDescriptor) list.get(0);
+ pd = list.get(0);
}
if (pd != null) {
@@ -804,8 +804,8 @@
PropertyDescriptor pd) {
PropertyDescriptor result = null;
- Class propType = pd.getPropertyType();
- Class ipropType = ipd.getIndexedPropertyType();
+ Class<?> propType = pd.getPropertyType();
+ Class<?> ipropType = ipd.getIndexedPropertyType();
if (propType.isArray() && propType.getComponentType() == ipropType) {
if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
@@ -839,7 +839,7 @@
if (write == null && read != null) {
write = findMethod(result.getClass0(),
SET_PREFIX + NameGenerator.capitalize(result.getName()), 1,
- new Class[] { FeatureDescriptor.getReturnType(result.getClass0(), read) });
+ new Class<?>[] { FeatureDescriptor.getReturnType(result.getClass0(), read) });
if (write != null) {
try {
result.setWriteMethod(write);
@@ -879,7 +879,7 @@
*/
private EventSetDescriptor[] getTargetEventInfo() throws IntrospectionException {
if (events == null) {
- events = new HashMap();
+ events = new HashMap<>();
}
// Check if the bean has its own BeanInfo that will provide
@@ -930,9 +930,9 @@
// Find all suitable "add", "remove" and "get" Listener methods
// The name of the listener type is the key for these hashtables
// i.e, ActionListener
- Map adds = null;
- Map removes = null;
- Map gets = null;
+ Map<String, Method> adds = null;
+ Map<String, Method> removes = null;
+ Map<String, Method> gets = null;
for (int i = 0; i < methodList.length; i++) {
Method method = methodList[i];
@@ -951,8 +951,8 @@
continue;
}
- Class argTypes[] = FeatureDescriptor.getParameterTypes(beanClass, method);
- Class resultType = FeatureDescriptor.getReturnType(beanClass, method);
+ Class<?>[] argTypes = FeatureDescriptor.getParameterTypes(beanClass, method);
+ Class<?> resultType = FeatureDescriptor.getReturnType(beanClass, method);
if (name.startsWith(ADD_PREFIX) && argTypes.length == 1 &&
resultType == Void.TYPE &&
@@ -961,7 +961,7 @@
if (listenerName.length() > 0 &&
argTypes[0].getName().endsWith(listenerName)) {
if (adds == null) {
- adds = new HashMap();
+ adds = new HashMap<>();
}
adds.put(listenerName, method);
}
@@ -973,7 +973,7 @@
if (listenerName.length() > 0 &&
argTypes[0].getName().endsWith(listenerName)) {
if (removes == null) {
- removes = new HashMap();
+ removes = new HashMap<>();
}
removes.put(listenerName, method);
}
@@ -986,7 +986,7 @@
if (listenerName.length() > 0 &&
resultType.getComponentType().getName().endsWith(listenerName)) {
if (gets == null) {
- gets = new HashMap();
+ gets = new HashMap<>();
}
gets.put(listenerName, method);
}
@@ -996,26 +996,26 @@
if (adds != null && removes != null) {
// Now look for matching addFooListener+removeFooListener pairs.
// Bonus if there is a matching getFooListeners method as well.
- Iterator keys = adds.keySet().iterator();
+ Iterator<String> keys = adds.keySet().iterator();
while (keys.hasNext()) {
- String listenerName = (String) keys.next();
+ String listenerName = keys.next();
// Skip any "add" which doesn't have a matching "remove" or
// a listener name that doesn't end with Listener
if (removes.get(listenerName) == null || !listenerName.endsWith("Listener")) {
continue;
}
String eventName = decapitalize(listenerName.substring(0, listenerName.length()-8));
- Method addMethod = (Method)adds.get(listenerName);
- Method removeMethod = (Method)removes.get(listenerName);
+ Method addMethod = adds.get(listenerName);
+ Method removeMethod = removes.get(listenerName);
Method getMethod = null;
if (gets != null) {
- getMethod = (Method)gets.get(listenerName);
+ getMethod = gets.get(listenerName);
}
- Class argType = FeatureDescriptor.getParameterTypes(beanClass, addMethod)[0];
+ Class<?> argType = FeatureDescriptor.getParameterTypes(beanClass, addMethod)[0];
// generate a list of Method objects for each of the target methods:
Method allMethods[] = getPublicDeclaredMethods(argType);
- List validMethods = new ArrayList(allMethods.length);
+ List<Method> validMethods = new ArrayList<>(allMethods.length);
for (int i = 0; i < allMethods.length; i++) {
if (allMethods[i] == null) {
continue;
@@ -1025,7 +1025,7 @@
validMethods.add(allMethods[i]);
}
}
- Method[] methods = (Method[])validMethods.toArray(new Method[validMethods.size()]);
+ Method[] methods = validMethods.toArray(new Method[validMethods.size()]);
EventSetDescriptor esd = new EventSetDescriptor(eventName, argType,
methods, addMethod,
@@ -1048,7 +1048,7 @@
} else {
// Allocate and populate the result array.
result = new EventSetDescriptor[events.size()];
- result = (EventSetDescriptor[])events.values().toArray(result);
+ result = events.values().toArray(result);
// Set the default index.
if (defaultEventName != null) {
@@ -1067,7 +1067,7 @@
if (esd.getName().equals("propertyChange")) {
propertyChangeSource = true;
}
- EventSetDescriptor old = (EventSetDescriptor)events.get(key);
+ EventSetDescriptor old = events.get(key);
if (old == null) {
events.put(key, esd);
return;
@@ -1082,7 +1082,7 @@
*/
private MethodDescriptor[] getTargetMethodInfo() {
if (methods == null) {
- methods = new HashMap(100);
+ methods = new HashMap<>(100);
}
// Check if the bean has its own BeanInfo that will provide
@@ -1135,7 +1135,7 @@
// Allocate and populate the result array.
MethodDescriptor result[] = new MethodDescriptor[methods.size()];
- result = (MethodDescriptor[])methods.values().toArray(result);
+ result = methods.values().toArray(result);
return result;
}
@@ -1146,7 +1146,7 @@
// This method gets called a *lot, so we try to be efficient.
String name = md.getName();
- MethodDescriptor old = (MethodDescriptor)methods.get(name);
+ MethodDescriptor old = methods.get(name);
if (old == null) {
// This is the common case.
methods.put(name, md);
@@ -1179,7 +1179,7 @@
// This is very rare.
String longKey = makeQualifiedMethodName(name, p1);
- old = (MethodDescriptor)methods.get(longKey);
+ old = methods.get(longKey);
if (old == null) {
methods.put(longKey, md);
return;
@@ -1250,7 +1250,7 @@
/*
* Internal method to return *public* methods within a class.
*/
- private static Method[] getPublicDeclaredMethods(Class clz) {
+ private static Method[] getPublicDeclaredMethods(Class<?> clz) {
// Looking up Class.getDeclaredMethods is relatively expensive,
// so we cache the results.
if (!ReflectUtil.isPackageAccessible(clz)) {
@@ -1280,14 +1280,14 @@
* Internal support for finding a target methodName with a given
* parameter list on a given class.
*/
- private static Method internalFindMethod(Class start, String methodName,
+ private static Method internalFindMethod(Class<?> start, String methodName,
int argCount, Class args[]) {
// For overriden methods we need to find the most derived version.
// So we start with the given class and walk up the superclass chain.
Method method = null;
- for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
+ for (Class<?> cl = start; cl != null; cl = cl.getSuperclass()) {
Method methods[] = getPublicDeclaredMethods(cl);
for (int i = 0; i < methods.length; i++) {
method = methods[i];
@@ -1338,7 +1338,7 @@
/**
* Find a target methodName on a given class.
*/
- static Method findMethod(Class cls, String methodName, int argCount) {
+ static Method findMethod(Class<?> cls, String methodName, int argCount) {
return findMethod(cls, methodName, argCount, null);
}
@@ -1354,7 +1354,7 @@
* @param args Array of argument types for the method.
* @return the method or null if not found
*/
- static Method findMethod(Class cls, String methodName, int argCount,
+ static Method findMethod(Class<?> cls, String methodName, int argCount,
Class args[]) {
if (methodName == null) {
return null;
@@ -1368,7 +1368,7 @@
* or "implements" b.
* Note tht either or both "Class" objects may represent interfaces.
*/
- static boolean isSubclass(Class a, Class b) {
+ static boolean isSubclass(Class<?> a, Class<?> b) {
// We rely on the fact that for any given java class or
// primtitive type there is a unqiue Class object, so
// we can use object equivalence in the comparisons.
@@ -1378,12 +1378,12 @@
if (a == null || b == null) {
return false;
}
- for (Class x = a; x != null; x = x.getSuperclass()) {
+ for (Class<?> x = a; x != null; x = x.getSuperclass()) {
if (x == b) {
return true;
}
if (b.isInterface()) {
- Class interfaces[] = x.getInterfaces();
+ Class<?>[] interfaces = x.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (isSubclass(interfaces[i], b)) {
return true;
@@ -1397,7 +1397,7 @@
/**
* Return true iff the given method throws the given exception.
*/
- private boolean throwsException(Method method, Class exception) {
+ private boolean throwsException(Method method, Class<?> exception) {
Class exs[] = method.getExceptionTypes();
for (int i = 0; i < exs.length; i++) {
if (exs[i] == exception) {
@@ -1412,12 +1412,12 @@
* First try the classloader of "sibling", then try the system
* classloader then the class loader of the current Thread.
*/
- static Object instantiate(Class sibling, String className)
+ static Object instantiate(Class<?> sibling, String className)
throws InstantiationException, IllegalAccessException,
ClassNotFoundException {
// First check with sibling's classloader (if any).
ClassLoader cl = sibling.getClassLoader();
- Class cls = ClassFinder.findClass(className, cl);
+ Class<?> cls = ClassFinder.findClass(className, cl);
return cls.newInstance();
}
@@ -1452,7 +1452,7 @@
this.properties = properties;
this.defaultProperty = defaultProperty;
this.methods = methods;
- this.targetBeanInfoRef = new SoftReference<BeanInfo>(targetBeanInfo);
+ this.targetBeanInfoRef = new SoftReference<>(targetBeanInfo);
}
/**