[jboss-cvs] JBossAS SVN: r93049 - in projects/jboss-reflect/trunk/src: main/java/org/jboss/reflect/spi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 31 15:42:59 EDT 2009


Author: flavia.rainone at jboss.com
Date: 2009-08-31 15:42:58 -0400 (Mon, 31 Aug 2009)
New Revision: 93049

Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/MutableClassInfo.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/JavassistBodyTestCase.java
Log:
[JBREFLECT-53]Added MutableClassInfo.getDeclaredMethod(String name) and MutableClassInfo.getDeclaredConstructor() for methods and constructors without parameters.

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2009-08-31 19:13:07 UTC (rev 93048)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2009-08-31 19:42:58 UTC (rev 93049)
@@ -237,19 +237,15 @@
       return constructorArray;
    }
 
-   public MutableConstructorInfo getDeclaredConstructor(TypeInfo[] parameters)
+   public MutableConstructorInfo getDeclaredConstructor()
    {
-      SignatureKey key = new SignatureKey(null, parameters);
-      synchronized (constructors)
-      {
-         MutableConstructorInfo constructor = constructors.get(key);
-         if (constructor != null)
-            return constructor;
-      }
-      if (constructorArray != null)
-         return null;
-      return generateConstructorInfo(key);
+      return getDeclaredConstructor(new SignatureKey(null));
    }
+   
+   public MutableConstructorInfo getDeclaredConstructor(TypeInfo... parameters)
+   {
+      return getDeclaredConstructor(new SignatureKey(null, parameters));
+   }
 
    public MutableConstructorInfo getDeclaredConstructor(String... parameters) throws ClassNotFoundException
    {
@@ -262,6 +258,19 @@
       return getDeclaredConstructor(typeParams);
    }
    
+   private MutableConstructorInfo getDeclaredConstructor(SignatureKey key)
+   {
+      synchronized (constructors)
+      {
+         MutableConstructorInfo constructor = constructors.get(key);
+         if (constructor != null)
+            return constructor;
+      }
+      if (constructorArray != null)
+         return null;
+      return generateConstructorInfo(key);
+   }
+   
    public MutableFieldInfo getDeclaredField(String fieldName)
    {
       synchronized (fields)
@@ -305,19 +314,15 @@
       }
       return fieldArray;
    }
+   
+   public MutableMethodInfo getDeclaredMethod(String methodName)
+   {
+      return getDeclaredMethod(new SignatureKey(methodName));
+   }
 
    public MutableMethodInfo getDeclaredMethod(String methodName, TypeInfo... parameters)
    {
-      SignatureKey key = new SignatureKey(methodName, parameters);
-      synchronized (methods)
-      {
-         MutableMethodInfo method = methods.get(key);
-         if (method != null)
-            return method;
-      }
-      if (methodArray != null)
-         return null;
-      return generateMethodInfo(key);
+      return getDeclaredMethod(new SignatureKey(methodName, parameters));
    }
 
    public MutableMethodInfo getDeclaredMethod(String methodName, String... parameters) throws ClassNotFoundException
@@ -331,6 +336,19 @@
       return getDeclaredMethod(methodName, typeParams);
    }
    
+   private MutableMethodInfo getDeclaredMethod(SignatureKey key)
+   {
+      synchronized (methods)
+      {
+         MutableMethodInfo method = methods.get(key);
+         if (method != null)
+            return method;
+      }
+      if (methodArray != null)
+         return null;
+      return generateMethodInfo(key);
+   }
+   
    public MutableMethodInfo[] getDeclaredMethods()
    {
       if (methodArray == null)

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java	2009-08-31 19:13:07 UTC (rev 93048)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SignatureKey.java	2009-08-31 19:42:58 UTC (rev 93049)
@@ -50,6 +50,17 @@
     * @param name the name
     * @param typeInfos the type infos
     */
+   public SignatureKey(String name)
+   {
+      this.name = name;
+   }
+   
+   /**
+    * Create a new SignatureKey.
+    * 
+    * @param name the name
+    * @param typeInfos the type infos
+    */
    public SignatureKey(String name, TypeInfo... typeInfos)
    {
       this.name = name;

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/MutableClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/MutableClassInfo.java	2009-08-31 19:13:07 UTC (rev 93048)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/MutableClassInfo.java	2009-08-31 19:42:58 UTC (rev 93049)
@@ -29,6 +29,13 @@
  */
 public interface MutableClassInfo extends ClassInfo
 {
+   /**
+    * Get the declared method without parameters.
+    * 
+    * @param name the method name
+    * @return the method info
+    */
+   MutableMethodInfo getDeclaredMethod(String name);
    
    /**
     * Get the declared method
@@ -66,6 +73,13 @@
    MutableConstructorInfo[] getDeclaredConstructors();
 
    /**
+    * Gets the default constructor (parameterless)
+    * 
+    * @return the constructor
+    */
+   MutableConstructorInfo getDeclaredConstructor();
+   
+   /**
     * Get a declared constructor
     * 
     * @param parameters the parameters

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/JavassistBodyTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/JavassistBodyTestCase.java	2009-08-31 19:13:07 UTC (rev 93048)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/JavassistBodyTestCase.java	2009-08-31 19:42:58 UTC (rev 93049)
@@ -60,7 +60,7 @@
 
          System.out.println("got method: "+mmi.getName());
          mmi.setBody(new InsertBeforeJavassistBody("i = 42;"));
-         MutableMethodInfo mmi2 = mci.getDeclaredMethod("bar", new TypeInfo[0]);
+         MutableMethodInfo mmi2 = mci.getDeclaredMethod("bar");
          System.out.println("mmi2: "+mmi2.getName());
          mmi2.setBody(new InsertAfterJavassistBody("s = \"after\" + s; return s;"));
          System.out.println("mmi2: "+mmi2.getName());




More information about the jboss-cvs-commits mailing list