[jboss-cvs] JBossAS SVN: r110271 - in projects/jboss-mdr/trunk/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
Wed Jan 5 01:07:38 EST 2011


Author: jameslivingston
Date: 2011-01-05 01:07:37 -0500 (Wed, 05 Jan 2011)
New Revision: 110271

Added:
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodChildBean.java
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodParentBean.java
Modified:
   projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
   projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
Log:
[JBMDR-72] AnnotatedElementMetaDataLoader doesn't work on bridge methods from parent classes

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	2011-01-05 06:01:30 UTC (rev 110270)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2011-01-05 06:07:37 UTC (rev 110271)
@@ -323,15 +323,18 @@
       Class<?>[] parameters = bridge.getParameterTypes();
 
       List<Method> matching = new ArrayList<Method>();
+      Class<?> searchClass = declaringClass;
       Method[] all = declaringClass.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);
-      }
+      do {
+         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);
+         }
+      } while ((matching.size() == 0) && (searchClass != null));
       
       if (matching.size() == 1)
          return matching.get(0);

Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodChildBean.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodChildBean.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodChildBean.java	2011-01-05 06:07:37 UTC (rev 110271)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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;
+
+
+/**
+ * @author <a href="jlivings at redhat.com">James Livingston</a>
+ */
+public class BridgeMethodChildBean extends BridgeMethodParentBean implements BridgeInterface<String> {
+
+}

Added: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodParentBean.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodParentBean.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/support/BridgeMethodParentBean.java	2011-01-05 06:07:37 UTC (rev 110271)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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 org.jboss.test.metadata.shared.support.TestAnnotation;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class BridgeMethodParentBean
+{
+   @TestAnnotation
+   public String unambiguous(String t)
+   {
+      throw new RuntimeException("NYI: org.jboss.test.metadata.loader.reflection.support.BridgedMethodBean.unambiguous");
+   }
+   
+   @TestAnnotation
+   public String ambiguous(String t)
+   {
+      throw new RuntimeException("NYI: org.jboss.test.metadata.loader.reflection.support.BridgedMethodBean.ambiguous");
+   }
+   
+   @TestAnnotation
+   public Long ambiguous(Long t)
+   {
+      throw new RuntimeException("NYI: org.jboss.test.metadata.loader.reflection.support.BridgedMethodBean.ambiguous");
+   }
+}

Modified: projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2011-01-05 06:01:30 UTC (rev 110270)
+++ projects/jboss-mdr/trunk/src/test/java/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementMetadataLoaderTestCase.java	2011-01-05 06:07:37 UTC (rev 110271)
@@ -22,6 +22,9 @@
 
 package org.jboss.test.metadata.loader.reflection.test;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
 import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
 import org.jboss.metadata.spi.MetaData;
 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
@@ -31,12 +34,10 @@
 import org.jboss.metadata.spi.signature.Signature;
 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.MethodBean;
 import org.jboss.test.metadata.loader.reflection.support.NoAnnotationBean;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
 /**
  * AnnotatedElementMetadataLoaderTestCase
  *
@@ -182,4 +183,50 @@
       methodSignature = new DeclaredMethodSignature(method);
       assertNull(annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature));
    }
+
+   /**
+    * Tests that the {@link AnnotatedElementMetaDataLoader} correctly identifies
+    * bridge methods.
+    */
+   public void testMethodLevelAnnotationOnBridgeMethodFromParent() throws Exception
+   {
+      AnnotatedElementMetaDataLoader annotatedElementLoader = new AnnotatedElementMetaDataLoader(BridgeMethodChildBean.class);
+      
+      Method method = BridgeMethodChildBean.class.getMethod("unambiguous", Object.class);
+      assertTrue(method.isBridge());
+      MethodSignature methodSignature = new MethodSignature(method);
+      MetaDataRetrieval retrieval = annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature);
+      assertNotNull("Expected a MetaDataRetrieval for method " + method, retrieval);
+      MetaData metadata = new MetaDataRetrievalToMetaDataBridge(retrieval);
+      Annotation[] annotations = metadata.getAnnotations();
+      assertTrue("Expected one annotation on unambiguous method of " + BridgeMethodChildBean.class, annotations.length == 1);
+      
+      method = BridgeMethodChildBean.class.getMethod("ambiguous", Object.class);
+      assertTrue(method.isBridge());
+      methodSignature = new MethodSignature(method);
+      assertNull(annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature));
+   }
+
+   /**
+    * Tests that the {@link AnnotatedElementMetaDataLoader} correctly identifies
+    * bridge methods.
+    */
+   public void testMethodLevelAnnotationOnDeclaredBridgeMethodFromParent() throws Exception
+   {
+      AnnotatedElementMetaDataLoader annotatedElementLoader = new AnnotatedElementMetaDataLoader(BridgeMethodChildBean.class);
+
+      Method method = BridgeMethodChildBean.class.getMethod("unambiguous", Object.class);
+      assertTrue(method.isBridge());
+      Signature methodSignature = new DeclaredMethodSignature(method);
+      MetaDataRetrieval retrieval = annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature);
+      assertNotNull("Expected a MetaDataRetrieval for method " + method, retrieval);
+      MetaData metadata = new MetaDataRetrievalToMetaDataBridge(retrieval);
+      Annotation[] annotations = metadata.getAnnotations();
+      assertTrue("Expected one annotation on unambiguous method of " + BridgeMethodChildBean.class, annotations.length == 1);
+
+      method = BridgeMethodChildBean.class.getMethod("ambiguous", Object.class);
+      assertTrue(method.isBridge());
+      methodSignature = new DeclaredMethodSignature(method);
+      assertNull(annotatedElementLoader.getComponentMetaDataRetrieval(methodSignature));
+   }
 }



More information about the jboss-cvs-commits mailing list