harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r678337 - 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, 21 Jul 2008 01:39:53 GMT
Author: qiuxx
Date: Sun Jul 20 18:39:52 2008
New Revision: 678337

URL: http://svn.apache.org/viewvc?rev=678337&view=rev
Log:
Apply for HARMONY-5915, ([beans] Introspector.getBeanInfo() will exclude public static methods.)

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=678337&r1=678336&r2=678337&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
Sun Jul 20 18:39:52 2008
@@ -524,7 +524,7 @@
         // Loop over the methods found, looking for public non-static methods
         for (int i = 0; i < basicMethods.length; i++) {
             int modifiers = basicMethods[i].getModifiers();
-            if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
+            if (Modifier.isPublic(modifiers)) {
                 // Allocate a MethodDescriptor for this method
                 MethodDescriptor theDescriptor = new MethodDescriptor(
                         basicMethods[i]);
@@ -557,10 +557,32 @@
             throws IntrospectionException {
 
         // Get descriptors for the public methods
-        MethodDescriptor[] theMethods = introspectMethods();
+        MethodDescriptor[] methodDescriptors = introspectMethods();
+        if (methodDescriptors == null) {
+            return null;
+        }
 
-        if (theMethods == null)
+        ArrayList<MethodDescriptor> methodList = new ArrayList<MethodDescriptor>();
+
+        // Loop over the methods found, looking for public non-static methods
+        for (int index = 0; index < methodDescriptors.length; index++) {
+            int modifiers = methodDescriptors[index].getMethod().getModifiers();
+            if (!Modifier.isStatic(modifiers)) {
+                methodList.add(methodDescriptors[index]);
+            }
+        }
+
+        // Get the list of public non-static methods into an array
+        int methodCount = methodList.size();
+        MethodDescriptor[] theMethods = null;
+        if (methodCount > 0) {
+            theMethods = new MethodDescriptor[methodCount];
+            theMethods = methodList.toArray(theMethods);
+        }
+
+        if (theMethods == null) {
             return null;
+        }
 
         HashMap<String, HashMap> propertyTable = new HashMap<String, HashMap>(
                 theMethods.length);

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=678337&r1=678336&r2=678337&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
Sun Jul 20 18:39:52 2008
@@ -450,7 +450,65 @@
         } catch (IntrospectionException e) {
         }
     }
+    
+    /*
+     * Introspect static methods
+     */
+    public void testGetBeanInfo_StaticMethods() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(StaticClazz.class);
+        PropertyDescriptor[] propertyDescriptors = beanInfo
+                .getPropertyDescriptors();
+        assertEquals(1, propertyDescriptors.length);
+        assertTrue(contains("class", Class.class, propertyDescriptors));
+        MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
+        assertTrue(contains("getStaticMethod", methodDescriptors));
+        assertTrue(contains("setStaticMethod", methodDescriptors));
+
+        beanInfo = Introspector.getBeanInfo(StaticClazzWithProperty.class);
+        propertyDescriptors = beanInfo.getPropertyDescriptors();
+        assertEquals(1, propertyDescriptors.length);
+        methodDescriptors = beanInfo.getMethodDescriptors();
+        assertTrue(contains("getStaticName", methodDescriptors));
+        assertTrue(contains("setStaticName", methodDescriptors));
+    }
+
+    public static class StaticClazz {
+
+        /*
+         * public static get method
+         */
+        public static String getStaticMethod() {
+            return "static class";
+        }
+
+        /*
+         * public static set method
+         */
+        public static void setStaticMethod(String content) {
+            // do nothing
+        }
 
+    }
+
+    public static class StaticClazzWithProperty {
+
+        private static String staticName = "Static Clazz";
+
+        /*
+         * public static get method
+         */
+        public static String getStaticName() {
+            return staticName;
+        }
+
+        /*
+         * public static set method
+         */
+        public static void setStaticName(String name) {
+            staticName = name;
+        }
+    }
+    
     public void testGetBeanInfoClassClass_StopNull()
             throws IntrospectionException {
         BeanInfo info = Introspector.getBeanInfo(MockFoo.class);// , null);



Mime
View raw message