--- a/jdk/src/share/classes/java/beans/Introspector.java Thu Dec 01 11:09:54 2011 +0000
+++ b/jdk/src/share/classes/java/beans/Introspector.java Thu Dec 01 18:34:23 2011 +0000
@@ -99,17 +99,17 @@
// Static Caches to speed up introspection.
private static WeakCache<Class<?>, Method[]> declaredMethodCache =
- new WeakCache<Class<?>, Method[]>();
+ new WeakCache<>();
private static final Object BEANINFO_CACHE = new Object();
- 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;
@@ -117,14 +117,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];
@@ -163,9 +163,11 @@
Map<Class<?>, BeanInfo> beanInfoCache;
BeanInfo beanInfo;
synchronized (BEANINFO_CACHE) {
- beanInfoCache = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
+ @SuppressWarnings("unchecked")
+ Map<Class<?>, BeanInfo> temp = beanInfoCache =
+ (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache == null) {
- beanInfoCache = new WeakHashMap<Class<?>, BeanInfo>();
+ beanInfoCache = new WeakHashMap<>();
AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
}
beanInfo = beanInfoCache.get(beanClass);
@@ -343,7 +345,7 @@
public static void flushCaches() {
synchronized (BEANINFO_CACHE) {
- Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
+ Map<?,?> beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.clear();
}
@@ -371,7 +373,8 @@
throw new NullPointerException();
}
synchronized (BEANINFO_CACHE) {
- Map beanInfoCache = (Map) AppContext.getAppContext().get(BEANINFO_CACHE);
+ @SuppressWarnings("unchecked")
+ Map<Class<?>, ?> beanInfoCache = (Map<Class<?>, ?>) AppContext.getAppContext().get(BEANINFO_CACHE);
if (beanInfoCache != null) {
beanInfoCache.put(clz, null);
}
@@ -383,14 +386,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;
}
@@ -405,7 +408,7 @@
explicitBeanInfo = findExplicitBeanInfo(beanClass);
}
- Class superClass = beanClass.getSuperclass();
+ Class<?> superClass = beanClass.getSuperclass();
if (superClass != stopClass) {
int newFlags = flags;
if (newFlags == IGNORE_IMMEDIATE_BEANINFO) {
@@ -451,7 +454,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 getFinder().find(beanClass);
}
@@ -501,8 +504,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;
@@ -560,8 +563,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) {
@@ -575,16 +578,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()) {
@@ -639,25 +642,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) {
@@ -686,7 +689,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) {
@@ -804,7 +807,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) {
@@ -823,8 +826,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())) {
@@ -858,7 +861,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);
@@ -898,7 +901,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
@@ -949,9 +952,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];
@@ -970,8 +973,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 &&
@@ -980,7 +983,7 @@
if (listenerName.length() > 0 &&
argTypes[0].getName().endsWith(listenerName)) {
if (adds == null) {
- adds = new HashMap();
+ adds = new HashMap<>();
}
adds.put(listenerName, method);
}
@@ -992,7 +995,7 @@
if (listenerName.length() > 0 &&
argTypes[0].getName().endsWith(listenerName)) {
if (removes == null) {
- removes = new HashMap();
+ removes = new HashMap<>();
}
removes.put(listenerName, method);
}
@@ -1005,7 +1008,7 @@
if (listenerName.length() > 0 &&
resultType.getComponentType().getName().endsWith(listenerName)) {
if (gets == null) {
- gets = new HashMap();
+ gets = new HashMap<>();
}
gets.put(listenerName, method);
}
@@ -1015,26 +1018,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;
@@ -1044,7 +1047,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,
@@ -1067,7 +1070,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) {
@@ -1086,7 +1089,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;
@@ -1101,7 +1104,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
@@ -1154,7 +1157,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;
}
@@ -1165,7 +1168,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);
@@ -1198,7 +1201,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;
@@ -1269,7 +1272,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)) {
@@ -1299,14 +1302,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];
@@ -1357,7 +1360,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);
}
@@ -1373,7 +1376,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;
@@ -1387,7 +1390,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.
@@ -1397,12 +1400,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;
@@ -1416,7 +1419,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) {
@@ -1442,12 +1445,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();
}
@@ -1482,7 +1485,7 @@
this.properties = properties;
this.defaultProperty = defaultProperty;
this.methods = methods;
- this.targetBeanInfoRef = new SoftReference<BeanInfo>(targetBeanInfo);
+ this.targetBeanInfoRef = new SoftReference<>(targetBeanInfo);
}
/**