harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r693047 - 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 Mon, 08 Sep 2008 10:41:08 GMT
Author: tellison
Date: Mon Sep  8 03:41:06 2008
New Revision: 693047

URL: http://svn.apache.org/viewvc?rev=693047&view=rev
Log:
Apply patch HARMONY-5973 ([classlib] [beans] StandardBeanInfo fails to gain correct indexed
read and write methods of a indexed property)

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=693047&r1=693046&r2=693047&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
Mon Sep  8 03:41:06 2008
@@ -968,16 +968,11 @@
             // Both normal getter and setter of the same type were defined;
             // no indexed getter/setter *PAIR* of the other type defined
             if (normalGetter != null && normalSetter != null &&
-                    (indexedGetter == null || indexedSetter == null) &&
-                    normalPropType != indexedPropType) {
-//                String tag = normalPropType.isArray() ?
-//                        STR_INDEXED : STR_NORMAL;
-                String tag = STR_NORMAL;
-
-                table.put(tag, STR_VALID);
-                table.put(tag + PREFIX_GET, normalGetter);
-                table.put(tag + PREFIX_SET, normalSetter);
-                table.put(tag + STR_PROPERTY_TYPE, normalPropType);
+                    (indexedGetter == null || indexedSetter == null)) {
+                table.put(STR_NORMAL, STR_VALID);
+                table.put(STR_NORMAL + PREFIX_GET, normalGetter);
+                table.put(STR_NORMAL + PREFIX_SET, normalSetter);
+                table.put(STR_NORMAL + STR_PROPERTY_TYPE, normalPropType);
                 continue;
             }
 
@@ -986,14 +981,10 @@
             // getters & setters defined
             if ((normalGetter != null || normalSetter != null) &&
                     indexedGetter == null && indexedSetter == null) {
-//                String tag = normalPropType.isArray() ?
-//                        STR_INDEXED : STR_NORMAL;
-                String tag = STR_NORMAL;
-
-                table.put(tag, STR_VALID);
-                table.put(tag + PREFIX_GET, normalGetter);
-                table.put(tag + PREFIX_SET, normalSetter);
-                table.put(tag + STR_PROPERTY_TYPE, normalPropType);
+                table.put(STR_NORMAL, STR_VALID);
+                table.put(STR_NORMAL + PREFIX_GET, normalGetter);
+                table.put(STR_NORMAL + PREFIX_SET, normalSetter);
+                table.put(STR_NORMAL + STR_PROPERTY_TYPE, normalPropType);
                 continue;
             }
 
@@ -1030,6 +1021,18 @@
                         indexedPropType);
                 continue;
             }
+            
+            // RULE5
+            // Both indexed getter and setter methods are defined
+            // no normal getter/setter *PAIR* of the other type defined
+            if ((normalSetter != null || normalGetter != null)
+                    && indexedGetter != null && indexedSetter != null) {
+                table.put(STR_INDEXED, STR_VALID);
+                table.put(STR_INDEXED + PREFIX_GET, indexedGetter);
+                table.put(STR_INDEXED + PREFIX_SET, indexedSetter);
+                table.put(STR_INDEXED + STR_PROPERTY_TYPE, indexedPropType);
+                continue;
+            }
 
             // default rule - invalid property
             table.put(STR_NORMAL, STR_INVALID);

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=693047&r1=693046&r2=693047&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
Mon Sep  8 03:41:06 2008
@@ -471,6 +471,138 @@
         assertTrue(contains("getStaticName", methodDescriptors));
         assertTrue(contains("setStaticName", methodDescriptors));
     }
+    
+    public void testMockIncompatibleGetterAndIndexedGetterBean() throws Exception {
+        Class beanClass = MockIncompatibleGetterAndIndexedGetterBean.class;
+        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
+        PropertyDescriptor pd = null;
+        PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
+        for (int i = 0; i < pds.length; i++) {
+            pd = pds[i];
+            if (pd.getName().equals("data")) {
+                break;
+            }
+        }
+        assertNotNull(pd);
+        assertTrue(pd instanceof IndexedPropertyDescriptor);
+        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+        assertNull(ipd.getReadMethod());
+        assertNull(ipd.getWriteMethod());
+        Method indexedReadMethod = beanClass.getMethod("getData",
+                new Class[] { int.class });
+        Method indexedWriteMethod = beanClass.getMethod("setData", new Class[] {
+                int.class, int.class });
+        assertEquals(indexedReadMethod, ipd.getIndexedReadMethod());
+        assertEquals(indexedWriteMethod, ipd.getIndexedWriteMethod());
+    }
+    
+    public void testMockIncompatibleSetterAndIndexedSetterBean() throws Exception {
+        Class beanClass = MockIncompatibleSetterAndIndexedSetterBean.class;
+        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
+        PropertyDescriptor pd = null;
+        PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
+        for (int i = 0; i < pds.length; i++) {
+            pd = pds[i];
+            if (pd.getName().equals("data")) {
+                break;
+            }
+        }
+        assertNotNull(pd);
+        assertTrue(pd instanceof IndexedPropertyDescriptor);
+        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+        assertNull(ipd.getReadMethod());
+        assertNull(ipd.getWriteMethod());
+        Method indexedReadMethod = beanClass.getMethod("getData",
+                new Class[] { int.class });
+        Method indexedWriteMethod = beanClass.getMethod("setData", new Class[] {
+                int.class, int.class });
+        assertEquals(indexedReadMethod, ipd.getIndexedReadMethod());
+        assertEquals(indexedWriteMethod, ipd.getIndexedWriteMethod());
+    }
+    
+    public void testMockIncompatibleAllSetterAndGetterBean() throws Exception {
+        Class beanClass = MockIncompatibleAllSetterAndGetterBean.class;
+        BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
+        PropertyDescriptor pd = null;
+        PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
+        for (int i = 0; i < pds.length; i++) {
+            pd = pds[i];
+            if (pd.getName().equals("data")) {
+                break;
+            }
+        }
+        assertNotNull(pd);
+        assertTrue(pd instanceof IndexedPropertyDescriptor);
+        IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
+        assertNull(ipd.getReadMethod());
+        assertNull(ipd.getWriteMethod());
+        Method indexedReadMethod = beanClass.getMethod("getData",
+                new Class[] { int.class });
+        Method indexedWriteMethod = beanClass.getMethod("setData", new Class[] {
+                int.class, int.class });
+        assertEquals(indexedReadMethod, ipd.getIndexedReadMethod());
+        assertEquals(indexedWriteMethod, ipd.getIndexedWriteMethod());
+    }
+    
+    public class MockIncompatibleGetterAndIndexedGetterBean {
+        private int[] datas;
+
+        public int getData() {
+            return datas[0];
+        }
+
+        public int getData(int index) {
+            return datas[index];
+        }
+
+        public void setData(int index, int data) {
+            this.datas[index] = data;
+        }
+    }
+    
+    public class MockIncompatibleSetterAndIndexedSetterBean {
+        
+        private int[] datas;
+        
+        public int getData(int index){
+            return datas[index];
+        }
+        
+        public void setData(int index, int data) {
+            this.datas[index] = data;
+        }
+        
+        public void setData(int data){
+            this.datas[0] = data;
+        }
+        
+    }
+    
+    public class MockIncompatibleAllSetterAndGetterBean {
+        
+        private int[] datas;
+        
+        public int getData(){
+            return datas[0];
+        }
+        
+        public int getData(int index){
+            return datas[index];
+        }
+        
+        public void setData(int index, int data) {
+            this.datas[index] = data;
+        }
+        
+        public void setData(int data){
+            this.datas[0] = data;
+        }
+        
+        public void setData(){
+            this.datas[0] = 0;
+        }
+        
+    }
 
     public static class StaticClazz {
 



Mime
View raw message