You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2007/07/16 10:58:35 UTC

svn commit: r556561 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/EventSetDescriptor.java test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java

Author: tonywu
Date: Mon Jul 16 01:58:34 2007
New Revision: 556561

URL: http://svn.apache.org/viewvc?view=rev&rev=556561
Log:
Fix bug: Some condition check for listener methods are not compatible with RI

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

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java?view=diff&rev=556561&r1=556560&r2=556561
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/EventSetDescriptor.java Mon Jul 16 01:58:34 2007
@@ -162,11 +162,11 @@
 
             for (Method element : listenerMethods) {
                 // XXX do we need this check?
-                //checkEventType(eventSetName, element);
-                if (checkMethod(listenerType, element)) {
-                    this.listenerMethodDescriptors.add(
-                            new MethodDescriptor(element));
-                }
+                // checkEventType(eventSetName, element);
+                // if (checkMethod(listenerType, element)) {
+                this.listenerMethodDescriptors
+                        .add(new MethodDescriptor(element));
+                // }
             }
         }
 
@@ -190,10 +190,10 @@
                 Method listenerMethod = element.getMethod();
 
                 // XXX
-                //checkEventType(eventSetName, listenerMethod);
-                if (checkMethod(listenerType, listenerMethod)) {
-                    this.listenerMethodDescriptors.add(element);
-                }
+                // checkEventType(eventSetName, listenerMethod);
+                // if (checkMethod(listenerType, listenerMethod)) {
+                this.listenerMethodDescriptors.add(element);
+                //                }
             }
         }
     }
@@ -358,17 +358,17 @@
             if (m.getName().equals(methodName)) {
                 Class[] paramTypes = m.getParameterTypes();
                 if (paramTypes.length == 1) {
-                    String paramTypeName = paramTypes[0].getName();
-                    paramTypeName = paramTypeName.substring(paramTypeName
-                            .lastIndexOf(".") + 1);
-                    if (paramTypeName.endsWith("Listener")) {
-                        paramTypeName = paramTypeName.substring(0,
-                                paramTypeName.length() - "Listener".length());
-                        if (expectedListenerTypeName.startsWith(paramTypeName)) {
+//                    String paramTypeName = paramTypes[0].getName();
+//                    paramTypeName = paramTypeName.substring(paramTypeName
+//                            .lastIndexOf(".") + 1);
+//                    if (paramTypeName.endsWith("Listener")) {
+//                        paramTypeName = paramTypeName.substring(0,
+//                                paramTypeName.length() - "Listener".length());
+//                        if (expectedListenerTypeName.startsWith(paramTypeName)) {
                             method = m;
                             break;
-                        }
-                    }
+//                        }
+//                    }
                 }
             }
         }
@@ -405,15 +405,23 @@
                 listenerType.getPackage().getName().length() + 1);
         }
         String methodName = prefix + shortName + postfix;
-        Class listenerType = this.awtEventListener == null? this.listenerType:this.awtEventListener;
         try {
             if (prefix.equals("get")) { //$NON-NLS-1$
                 return sourceClass.getMethod(methodName);
             }
-            return sourceClass.getMethod(methodName, listenerType);
         } catch (NoSuchMethodException nsme) {
             return null;
         }
+        Method[] m = sourceClass.getMethods();
+        for(int i = 0; i < m.length; i++){
+            if(m[i].getName().equals(methodName)){
+                Class[] paramTypes = m[i].getParameterTypes();
+                if (paramTypes.length == 1) {
+                    return m[i];
+                }
+            }
+        }
+        return null;
     }
 
     private static boolean isUnicastByDefault(Method addMethod) {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java?view=diff&rev=556561&r1=556560&r2=556561
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/EventSetDescriptorTest.java Mon Jul 16 01:58:34 2007
@@ -1286,6 +1286,22 @@
             // expected
         }
     }
+    
+    public void testConstructor_withAnotherListener() throws Exception {
+        Method[] listenermethods = AnotherObjectListener.class
+                .getDeclaredMethods();
+
+        Method add = AnObject.class.getDeclaredMethod(
+                "addEventSetDescriptorTest$AnObjectListener",
+                AnObjectListener.class);
+        Method remove = AnObject.class.getDeclaredMethod(
+                "removeEventSetDescriptorTest$AnObjectListener",
+                AnObjectListener.class);
+
+        EventSetDescriptor esd = new EventSetDescriptor("something",
+                AnObjectListener.class, listenermethods, add, remove);
+        assertNotNull(esd);
+    }
 
     protected String getUnQualifiedClassName(Class<?> classType) {
         String qName = classType.getName();
@@ -1349,6 +1365,33 @@
     
     private static class SomethingEvent {
     
+    }
+    
+    public static void main(String[] args) throws Exception {
+
+        try {
+                // No need to do anything clever, there's only one method and it's
+                // the one we want.
+                // Swap these two lines to make Harmony pass.
+                //Method[] listenermethods = AnObjectListener.class.getDeclaredMethods();
+                Method[] listenermethods = AnotherObjectListener.class.getDeclaredMethods();
+
+                Method add = AnObject.class.getDeclaredMethod( "addEventSetDescriptorTest3$AnObjectListener",
+                                                                AnObjectListener.class );
+                Method remove = AnObject.class.getDeclaredMethod( "removeEventSetDescriptorTest3$AnObjectListener",
+                                                                AnObjectListener.class );
+
+                EventSetDescriptor esd = new EventSetDescriptor("something",
+                    AnObjectListener.class, listenermethods, add, remove);
+            System.out.println("Test passed.");
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.out.println("Test failed.");
+        }
+    }
+
+    private interface AnotherObjectListener {
+        public void anotherMethod(SomethingEvent s);
     }
 
 }