[jboss-cvs] JBossAS SVN: r77023 - in projects/jboss-mdr/trunk/src: main/org/jboss/metadata/spi/signature and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 13 14:04:01 EDT 2008


Author: adrian at jboss.org
Date: 2008-08-13 14:04:01 -0400 (Wed, 13 Aug 2008)
New Revision: 77023

Added:
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestAnnotationWithValue.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSub.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSuper.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase.java
Modified:
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
   projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/ReflectionMetaDataLoaderTestSuite.java
Log:
[JBMDR-35] - Add experimental support for DeclaredMethodSignature

Modified: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2008-08-13 17:33:09 UTC (rev 77022)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -41,6 +41,7 @@
 import org.jboss.metadata.spi.scope.ScopeKey;
 import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
 import org.jboss.metadata.spi.signature.ConstructorSignature;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
 import org.jboss.metadata.spi.signature.FieldSignature;
 import org.jboss.metadata.spi.signature.MethodParametersSignature;
 import org.jboss.metadata.spi.signature.MethodSignature;
@@ -153,6 +154,25 @@
             }
             return new AnnotatedElementMetaDataLoader(method);
          }
+         else if (signature instanceof DeclaredMethodSignature)
+         {
+            DeclaredMethodSignature methodSignature = (DeclaredMethodSignature) signature;
+            Method method = methodSignature.getMethod();
+            if (method == null)
+            {
+               clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
+               if (clazz == null)
+                  return null;
+               method = ReflectionUtils.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+            }
+            if (method == null)
+            {
+               if (log.isTraceEnabled())
+                  log.trace("Method with signature " + signature + " does not exist on class " + clazz.getName());
+               return null;
+            }
+            return new AnnotatedElementMetaDataLoader(method);
+         }
          else if (signature instanceof MethodParametersSignature)
          {
             MethodParametersSignature methodParametersSignature = (MethodParametersSignature) signature;
@@ -239,4 +259,23 @@
       buffer.append("]");
       return buffer.toString();
    }
+
+   /**
+    * Get the declaring class from the reference class
+    * 
+    * @param reference the reference class
+    * @param declaringClass the declaring class
+    * @return the class or null if the declaring class is not a super class of the reference
+    */
+   private Class<?> getDeclaringClass(Class<?> reference, String declaringClass)
+   {
+      while (reference != null)
+      {
+         if (declaringClass.equals(reference.getName()))
+            return reference;
+         
+         reference = reference.getSuperclass();
+      }
+      return null;
+   }
 }

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.metadata.spi.signature;
+
+import java.lang.reflect.Method;
+
+import org.jboss.reflect.spi.MethodInfo;
+
+/**
+ * Method Signature.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeclaredMethodSignature extends Signature
+{
+   /** The declaring class */
+   private String declaringClass;
+   
+   /** The method */
+   private Method method;
+   
+   /**
+    * Create a new Signature.
+    *
+    * @param declaringClass the declaring class
+    * @param name the name
+    * @param parameters the parameters
+    */
+   public DeclaredMethodSignature(String declaringClass, String name, String[] parameters)
+   {
+      super(name, parameters);
+      this.declaringClass = declaringClass;
+   }
+
+   /**
+    * Create a new Signature.
+    * 
+    * @param declaringClass the declaring class
+    * @param name the name
+    * @param parameters the parameters
+    */
+   public DeclaredMethodSignature(String declaringClass, String name, Class<?>... parameters)
+   {
+      super(name, parameters);
+      this.declaringClass = declaringClass;
+   }
+
+   /**
+    * Create a new Signature.
+    * 
+    * @param method the method
+    */
+   public DeclaredMethodSignature(Method method)
+   {
+      super(method.getName(), (Class<?>[]) null);
+      this.method = method;
+      this.declaringClass = method.getDeclaringClass().getName();
+   }
+
+   /**
+    * Create a new Signature.
+    * 
+    * @param method the method
+    */
+   public DeclaredMethodSignature(MethodInfo method)
+   {
+      super(method.getName(), convertParameterTypes(method.getParameterTypes()));
+      this.declaringClass = method.getDeclaringClass().getName();
+   }
+
+   /**
+    * Get the declaringClass.
+    * 
+    * @return the declaringClass.
+    */
+   public String getDeclaringClass()
+   {
+      return declaringClass;
+   }
+
+   /**
+    * Get the method.
+    * 
+    * @return the method could be null if not created using a method
+    */
+   public Method getMethod()
+   {
+      return method;
+   }
+
+   @Override
+   protected Class<?>[] getParameterTypes()
+   {
+      if (method != null)
+         return method.getParameterTypes();
+      return super.getParameterTypes();
+   }
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestAnnotationWithValue.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestAnnotationWithValue.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestAnnotationWithValue.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -0,0 +1,31 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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 java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface TestAnnotationWithValue
+{
+   String value();
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSub.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSub.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSub.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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;
+
+/**
+ * TestSub.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestSub extends TestSuper
+{
+   @SuppressWarnings("unused")
+   @TestAnnotationWithValue("sub")
+   private void doSomething()
+   {
+   }
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSuper.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSuper.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/support/TestSuper.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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;
+
+/**
+ * TestSuper.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestSuper
+{
+   @SuppressWarnings("unused")
+   @TestAnnotationWithValue("super")
+   private void doSomething()
+   {
+   }
+}

Added: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.test;
+
+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.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.test.metadata.AbstractMetaDataTest;
+import org.jboss.test.metadata.loader.reflection.support.TestAnnotationWithValue;
+import org.jboss.test.metadata.loader.reflection.support.TestSub;
+import org.jboss.test.metadata.loader.reflection.support.TestSuper;
+
+/**
+ * AnnotatedElementLoaderNotPublicUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase extends AbstractMetaDataTest
+{
+   public AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testSubClassMethodConstructor() throws Exception
+   {
+      MetaData metaData = createMetaData();
+      Method method = TestSub.class.getDeclaredMethod("doSomething");
+      doTest(metaData.getComponentMetaData(new DeclaredMethodSignature(method)), "sub");
+   }
+   
+   public void testSubClassStringConstructor() throws Exception
+   {
+      MetaData metaData = createMetaData();
+      doTest(metaData.getComponentMetaData(new DeclaredMethodSignature(TestSub.class.getName(), "doSomething")), "sub");
+   }
+   
+   public void testSuperClassMethodConstructor() throws Exception
+   {
+      MetaData metaData = createMetaData();
+      Method method = TestSuper.class.getDeclaredMethod("doSomething");
+      doTest(metaData.getComponentMetaData(new DeclaredMethodSignature(method)), "super");
+   }
+   
+   public void testSuperClassStringConstructor() throws Exception
+   {
+      MetaData metaData = createMetaData();
+      doTest(metaData.getComponentMetaData(new DeclaredMethodSignature(TestSuper.class.getName(), "doSomething")), "super");
+   }
+   
+   protected void doTest(MetaData metaData, String expected) throws Exception
+   {
+      assertNotNull(metaData);
+
+      TestAnnotationWithValue annotation = metaData.getAnnotation(TestAnnotationWithValue.class);
+      assertNotNull(annotation);
+      assertEquals(expected, annotation.value());
+   }
+
+   protected MetaData createMetaData()
+   {
+      AnnotatedElementMetaDataLoader loader = new AnnotatedElementMetaDataLoader(TestSub.class);
+      return new MetaDataRetrievalToMetaDataBridge(loader);
+   }
+}

Modified: projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/ReflectionMetaDataLoaderTestSuite.java
===================================================================
--- projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/ReflectionMetaDataLoaderTestSuite.java	2008-08-13 17:33:09 UTC (rev 77022)
+++ projects/jboss-mdr/trunk/src/tests/org/jboss/test/metadata/loader/reflection/test/ReflectionMetaDataLoaderTestSuite.java	2008-08-13 18:04:01 UTC (rev 77023)
@@ -46,6 +46,7 @@
       suite.addTest(new TestSuite(AnnotatedElementLoaderComponentBasicAnnotationsUnitTestCase.class));
       suite.addTest(new TestSuite(AnnotatedElementLoaderScopeUnitTestCase.class));
       suite.addTest(new TestSuite(AnnotatedElementLoaderNotPublicUnitTestCase.class));
+      suite.addTest(new TestSuite(AnnotatedElementLoaderDeclaredMethodSignatureUnitTestCase.class));
       return suite;
    }
 }




More information about the jboss-cvs-commits mailing list