[jboss-cvs] JBossAS SVN: r110580 - in projects/jboss-mdr/branches/Branch_2_0/src: test/java/org/jboss/test/metadata/loader/reflection/support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 10 09:02:46 EST 2011


Author: alesj
Date: 2011-02-10 09:02:45 -0500 (Thu, 10 Feb 2011)
New Revision: 110580

Added:
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Child.java
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Event.java
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/IBean.java
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/NamedEvent.java
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Parent.java
Modified:
   projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
   projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
Log:
Port JBMDR-73 fix.

Modified: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2011-02-10 13:43:11 UTC (rev 110579)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -21,6 +21,15 @@
 */
 package org.jboss.metadata.plugins.loader.reflection;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.jboss.logging.Logger;
 import org.jboss.metadata.plugins.loader.BasicMetaDataLoader;
 import org.jboss.metadata.plugins.loader.SimpleMetaDataLoader;
@@ -36,16 +45,12 @@
 import org.jboss.util.JBossStringBuilder;
 import org.jboss.util.Strings;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * AnnotatedElementMetaDataLoader.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision$
  */
 public class AnnotatedElementMetaDataLoader extends BasicMetaDataLoader 
@@ -291,7 +296,7 @@
       }
       return null;
    }
-   
+
    /**
     * Search for real bridge method.
     *
@@ -303,60 +308,65 @@
       Class<?> declaringClass = bridge.getDeclaringClass();
       Class<?>[] parameters = bridge.getParameterTypes();
 
-      List<Method> matching = new ArrayList<Method>();
+      List<Method> simpleMatch = new ArrayList<Method>();
       Class<?> searchClass = declaringClass;
 
       while (searchClass != null && Object.class.equals(searchClass) == false)
       {
-	      Method[] all = searchClass.getDeclaredMethods();
-	      for (Method m : all)
-	      {
-	         if (m.getName().equals(bridge.getName()) &&
-	               m.getParameterTypes().length == parameters.length &&
-	               m.equals(bridge) == false &&
-	               m.isBridge() == false)
-	            matching.add(m);
-	      }
-	      searchClass = searchClass.getSuperclass();
+         Method[] all = searchClass.getDeclaredMethods();
+         for (Method m : all)
+         {
+            if (m.getName().equals(bridge.getName()) &&
+                  m.getParameterTypes().length == parameters.length &&
+                  m.equals(bridge) == false &&
+                  m.isBridge() == false)
+               simpleMatch.add(m);
+         }
+         searchClass = searchClass.getSuperclass();
       }
 
-      if (matching.size() == 1)
-         return matching.get(0);
+      if (simpleMatch.size() == 1)
+         return simpleMatch.get(0);
 
       //Should not happen
-      if (matching.size() == 0)
+      if (simpleMatch.size() == 0)
          throw new IllegalStateException("No original methods found: " + bridge);
 
-      for (Iterator<Method> it = matching.iterator() ; it.hasNext() ; )
+      List<Method> typesMatch = new ArrayList<Method>();
+
+      for (Method cur : simpleMatch)
       {
-         Method cur = it.next();
-
-         if (bridge.getReturnType().isAssignableFrom(cur.getReturnType()) == false)
+         Class<?> brt = bridge.getReturnType();
+         Class<?> crt = cur.getReturnType();
+         if (brt.isAssignableFrom(crt) == false && crt.isAssignableFrom(brt) == false)
          {
-            it.remove();
             continue;
          }
 
+         boolean parametersMatch = true;
          Class<?>[] currentParameters = cur.getParameterTypes();
-         for (int i = 0 ; i < parameters.length ; i++)
+         for (int i = 0; i < parameters.length; i++)
          {
-            if (parameters[i].isAssignableFrom(currentParameters[i]) == false)
+            if (parameters[i].isAssignableFrom(currentParameters[i]) == false && currentParameters[i].isAssignableFrom(parameters[i]) == false)
             {
-               it.remove();
+               parametersMatch = false;
                break;
             }
          }
+
+         if (parametersMatch)
+            typesMatch.add(cur);
       }
 
-      if (matching.size() == 1)
-         return matching.get(0);
+      if (typesMatch.size() == 1)
+         return typesMatch.get(0);
 
       //Should not happen
-      if (matching.size() == 0)
+      if (typesMatch.size() == 0)
          throw new IllegalStateException("No original methods found: " + bridge);
 
       if (log.isTraceEnabled())
-         log.trace("Could not determine original method for " + bridge + " found: " + matching);
+         log.trace("Could not determine original method for " + bridge + " found: " + typesMatch);
 
       return null;
    }

Added: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Child.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Child.java	                        (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Child.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.metadata.loader.reflection.support;
+
+/**
+ * User: Jaikiran Pai
+ */
+public class Child extends Parent<Event> implements IBean<Event>
+{
+}

Added: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Event.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Event.java	                        (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Event.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.metadata.loader.reflection.support;
+
+/**
+ * User: jpai
+ */
+public class Event extends NamedEvent
+{
+}

Added: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/IBean.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/IBean.java	                        (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/IBean.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.metadata.loader.reflection.support;
+
+import java.util.Map;
+
+/**
+ * User: jpai
+ */
+public interface IBean <T extends Event>
+{
+   T loadByExample(T entity, Map<String, Object> parameters);
+}

Added: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/NamedEvent.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/NamedEvent.java	                        (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/NamedEvent.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.metadata.loader.reflection.support;
+
+/**
+ * User: jpai
+ */
+public abstract class NamedEvent
+{
+}

Added: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Parent.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Parent.java	                        (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/support/Parent.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.metadata.loader.reflection.support;
+
+import java.util.Map;
+
+/**
+ * User: jpai
+ */
+public abstract class Parent<T extends NamedEvent>
+{
+   public T loadByExample(T entity, Map<String, Object> parameters)
+   {
+      return null;
+   }
+
+   // dummy overloaded method to reproduce JBMDR-73
+   public T loadByExample(T entity, String dummy)
+   {
+      return null;
+   }
+}

Modified: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2011-02-10 13:43:11 UTC (rev 110579)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2011-02-10 14:02:45 UTC (rev 110580)
@@ -24,6 +24,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Map;
 
 import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
 import org.jboss.metadata.spi.MetaData;
@@ -35,6 +36,8 @@
 import org.jboss.test.metadata.AbstractMetaDataTest;
 import org.jboss.test.metadata.loader.reflection.support.BridgeMethodBean;
 import org.jboss.test.metadata.loader.reflection.support.BridgeMethodChildBean;
+import org.jboss.test.metadata.loader.reflection.support.Child;
+import org.jboss.test.metadata.loader.reflection.support.Event;
 import org.jboss.test.metadata.loader.reflection.support.MethodBean;
 import org.jboss.test.metadata.loader.reflection.support.NoAnnotationBean;
 
@@ -229,4 +232,26 @@
       methodSignature = new DeclaredMethodSignature(method);
       assertNull(annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature));
    }
+
+   /**
+    * Test the bug fix for JBMDR-73
+    * <p/>
+    *
+    * Tests that overlaoded methods don't cause "No original methods found for..." exception
+    * while looking for real method corresponding to a bridged method, through {@link AnnotatedElementMetaDataLoader}
+    */
+   public void testBridgedMethodWithOverloadedMethods() throws Exception
+   {
+      AnnotatedElementMetaDataLoader annotatedElementLoader = new AnnotatedElementMetaDataLoader(Child.class);
+      // get the bridged method
+      Method method = Child.class.getMethod("loadByExample", Event.class, Map.class);
+      // Ensure that the bridged method was picked up
+      assertTrue("Method " + method + " was expected to be a bridged method", method.isBridge());
+
+      // now just get the ComponentMetaDataRetrieval (which internally triggers the call to search for the
+      // non-bridged method).
+      Signature methodSignature = new DeclaredMethodSignature(method);
+      MetaDataRetrieval retrieval = annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature);
+      assertNotNull("Expected a MetaDataRetrieval for method " + method, retrieval);
+   }
 }



More information about the jboss-cvs-commits mailing list