harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r580401 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/StandardBeanInfo.java test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Date Fri, 28 Sep 2007 16:14:26 GMT
Author: ayza
Date: Fri Sep 28 09:14:25 2007
New Revision: 580401

URL: http://svn.apache.org/viewvc?rev=580401&view=rev
Log:
Applying the patch from HARMONY-4861 ([classlib][beans] PropertyDescriptor.getReadMethod()
violates spec). This commit was approved by the community.

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java?rev=580401&r1=580400&r2=580401&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
Fri Sep 28 09:14:25 2007
@@ -658,85 +658,90 @@
 
     @SuppressWarnings("unchecked")
     private static void introspectGet(Method theMethod,
-            HashMap<String, HashMap> propertyTable) {
-        String methodName = theMethod.getName();
-        if (methodName == null) {
-            return;
-        }
-
-        int prefixLength = 0;
-        if (methodName.startsWith(PREFIX_GET)) {
-            prefixLength = PREFIX_GET.length();
-        }
-
-        if (methodName.startsWith(PREFIX_IS)) {
-            prefixLength = PREFIX_IS.length();
-        }
-
-        if (prefixLength == 0) {
-            return;
-        }
-
-        String propertyName = decapitalize(methodName.substring(prefixLength));
-        // validate property name
-        if (!isValidProperty(propertyName)) {
-            return;
-        }
-
-        Class propertyType = theMethod.getReturnType();
-
-        // check return type getMethod
-        if (propertyType.getName().equals(Void.TYPE.getName())) {
-            return;
-        }
-
-        // isXXX return boolean
-        if (prefixLength == 2) {
-            if (!propertyType.getName().equals(Boolean.TYPE.getName())) {
-                return;
-            }
-        }
-
-        // indexed get method
-        Class[] paramTypes = theMethod.getParameterTypes();
-
-        if (paramTypes.length > 1) {
-            return;
-        }
-
-        String tag = "normal"; //$NON-NLS-1$
-
-        if (paramTypes.length == 1) {
-            if (paramTypes[0].getName().equals(Integer.TYPE.getName())) {
-                tag = "indexed"; //$NON-NLS-1$
-            } else {
-                return;
-            }
-
-        }
-
-        HashMap table = propertyTable.get(propertyName);
-        if (table == null) {
-            table = new HashMap();
-        }
-
-        // the "get" propertyType is conflict with "set" propertyType
-        Class oldPropertyType = (Class) table.get(tag + "PropertyType"); //$NON-NLS-1$
-        if ((oldPropertyType != null)
-                && (!oldPropertyType.getName().equals(propertyType.getName()))) {
-            table.put(tag, "invalid"); //$NON-NLS-1$
-            table.put(tag + "get", theMethod); //$NON-NLS-1$
-            table.put(tag + "PropertyType", propertyType); //$NON-NLS-1$
-            table.remove(tag + "set"); //$NON-NLS-1$
-            return;
-        }
-
-        table.put(tag, "valid"); //$NON-NLS-1$
-        table.put(tag + "get", theMethod); //$NON-NLS-1$
-        table.put(tag + "PropertyType", propertyType); //$NON-NLS-1$
-
-        propertyTable.put(propertyName, table);
-    }
+			HashMap<String, HashMap> propertyTable) {
+		String methodName = theMethod.getName();
+		if (methodName == null) {
+			return;
+		}
+
+		int prefixLength = 0;
+		if (methodName.startsWith(PREFIX_GET)) {
+			prefixLength = PREFIX_GET.length();
+		}
+
+		if (methodName.startsWith(PREFIX_IS)) {
+			prefixLength = PREFIX_IS.length();
+		}
+
+		if (prefixLength == 0) {
+			return;
+		}
+
+		String propertyName = decapitalize(methodName.substring(prefixLength));
+		// validate property name
+		if (!isValidProperty(propertyName)) {
+			return;
+		}
+
+		Class propertyType = theMethod.getReturnType();
+
+		// check return type getMethod
+		if (propertyType.getName().equals(Void.TYPE.getName())) {
+			return;
+		}
+
+		// isXXX return boolean
+		if (prefixLength == 2) {
+			if (!propertyType.getName().equals(Boolean.TYPE.getName())) {
+				return;
+			}
+		}
+
+		// indexed get method
+		Class[] paramTypes = theMethod.getParameterTypes();
+
+		if (paramTypes.length > 1) {
+			return;
+		}
+
+		String tag = "normal"; //$NON-NLS-1$
+
+		if (paramTypes.length == 1) {
+			if (paramTypes[0].getName().equals(Integer.TYPE.getName())) {
+				tag = "indexed"; //$NON-NLS-1$
+			} else {
+				return;
+			}
+
+		}
+
+		HashMap table = propertyTable.get(propertyName);
+		if (table == null) {
+			table = new HashMap();
+			propertyTable.put(propertyName, table);
+		}
+
+		// the "get" propertyType is conflict with "set" propertyType
+		Class oldPropertyType = (Class) table.get(tag + "PropertyType"); //$NON-NLS-1$
+		if ((oldPropertyType != null)
+				&& (!oldPropertyType.getName().equals(propertyType.getName()))) {
+			table.put(tag, "invalid"); //$NON-NLS-1$
+			table.remove(tag + "set"); //$NON-NLS-1$
+		} else {
+			table.put(tag, "valid"); //$NON-NLS-1$
+		}
+		
+		table.put(tag + "PropertyType", propertyType); //$NON-NLS-1$
+
+		// According to the spec "is" method should be used prior to "get"
+		if (prefixLength == 3) {
+			if (!table.containsKey(tag + "get")) { //$NON-NLS-1$
+				table.put(tag + "get", theMethod); //$NON-NLS-1$
+			}
+		} else {
+			table.put(tag + "get", theMethod); //$NON-NLS-1$
+		}
+	}
 
     @SuppressWarnings("unchecked")
     private static void introspectSet(Method theMethod,

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?rev=580401&r1=580400&r2=580401&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Fri Sep 28 09:14:25 2007
@@ -1496,6 +1496,34 @@
         assertEquals("property1", pds[0].getName());
         assertEquals("property8", pds[1].getName());
     }
+    
+    public void testHarmony4861() throws IntrospectionException {
+		final PropertyDescriptor[] propertyDescriptors = Introspector
+				.getBeanInfo(TestBean.class).getPropertyDescriptors();
+
+		for (PropertyDescriptor d : propertyDescriptors) {
+			if (d.getName().equals("prop1")) { //$NON-NLS-1$
+				assertEquals("isProp1", d.getReadMethod().getName()); //$NON-NLS-1$
+				return;
+			}
+		}
+	}
+
+	public static class TestBean {
+		boolean prop1;
+
+		public void setProp1(boolean prop1) {
+			this.prop1 = prop1;
+		}
+
+		public boolean isProp1() {
+			return prop1;
+		}
+
+		public boolean getProp1() {
+			return prop1;
+		}
+	}
 
     public static TestSuite suite() {
 //        TestSuite suite = new TestSuite();



Mime
View raw message