[jboss-cvs] JBossAS SVN: r105213 - projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 25 09:25:40 EDT 2010


Author: alesj
Date: 2010-05-25 09:25:40 -0400 (Tue, 25 May 2010)
New Revision: 105213

Modified:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
Log:
Small code refactor; parameters get cloned on every call.

Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2010-05-25 13:19:45 UTC (rev 105212)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2010-05-25 13:25:40 UTC (rev 105213)
@@ -47,6 +47,8 @@
  * 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 
@@ -149,14 +151,14 @@
             }
             if (method.getAnnotations().length == 0)
             {
-               if (!method.isBridge())
-                  return null;
-               else
+               if (method.isBridge())
                {
                   method = searchForRealBridgeMethodSignature(method); 
                   if (method == null)
                      return null;
                }
+               else
+                  return null;
             }
             return new AnnotatedElementMetaDataLoader(method);
          }
@@ -182,14 +184,14 @@
             }
             if (method.getAnnotations().length == 0)
             {
-               if (!method.isBridge())
-                  return null;
-               else
+               if (method.isBridge())
                {
                   method = searchForRealBridgeMethodSignature(method);
                   if (method == null)
                      return null;
                }
+               else
+                  return null;
             }
             return new AnnotatedElementMetaDataLoader(method);
          }
@@ -308,18 +310,27 @@
       }
       return null;
    }
-   
+
+   /**
+    * Search for real bridge method.
+    *
+    * @param bridge the current method
+    * @return real bridge method
+    */
    private Method searchForRealBridgeMethodSignature(Method bridge)
    {
+      Class<?> declaringClass = bridge.getDeclaringClass();
+      Class<?>[] parameters = bridge.getParameterTypes();
+
       List<Method> matching = new ArrayList<Method>();
-      Method[] all = bridge.getDeclaringClass().getDeclaredMethods();
-      for (int i = 0 ; i < all.length ; i++)
+      Method[] all = declaringClass.getDeclaredMethods();
+      for (Method m : all)
       {
-         if (all[i].getName().equals(bridge.getName()) &&
-               all[i].getParameterTypes().length == bridge.getParameterTypes().length &&
-               !all[i].equals(bridge) &&
-               !all[i].isBridge())
-            matching.add(all[i]);
+         if (m.getName().equals(bridge.getName()) &&
+               m.getParameterTypes().length == parameters.length &&
+               m.equals(bridge) == false &&
+               m.isBridge() == false)
+            matching.add(m);
       }
       
       if (matching.size() == 1)
@@ -327,24 +338,25 @@
       
       //Should not happen
       if (matching.size() == 0)
-         throw new IllegalStateException("No original methods found");
+         throw new IllegalStateException("No original methods found: " + bridge);
       
       for (Iterator<Method> it = matching.iterator() ; it.hasNext() ; )
       {
          Method cur = it.next();
-         if (!bridge.getReturnType().isAssignableFrom(cur.getReturnType()))
+         
+         if (bridge.getReturnType().isAssignableFrom(cur.getReturnType()) == false)
          {
             it.remove();
             continue;
          }
-         
-         
-         for (int i = 0 ; i < bridge.getParameterTypes().length ; i++)
+
+         Class<?>[] currentParameters = cur.getParameterTypes();
+         for (int i = 0 ; i < parameters.length ; i++)
          {
-            if (!bridge.getParameterTypes()[i].isAssignableFrom(cur.getParameterTypes()[i]))
+            if (parameters[i].isAssignableFrom(currentParameters[i]) == false)
             {
                it.remove();
-               continue;
+               break;
             }
          }
       }
@@ -354,7 +366,7 @@
        
       //Should not happen
       if (matching.size() == 0)
-         throw new IllegalStateException("No original methods found");
+         throw new IllegalStateException("No original methods found: " + bridge);
 
       if (log.isTraceEnabled())
          log.trace("Could not determine original method for " + bridge + " found: " + matching);




More information about the jboss-cvs-commits mailing list