[jboss-cvs] javassist SVN: r552 - trunk/src/main/javassist.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 8 07:01:36 EDT 2010


Author: chiba
Date: 2010-07-08 07:01:36 -0400 (Thu, 08 Jul 2010)
New Revision: 552

Modified:
   trunk/src/main/javassist/CtClass.java
   trunk/src/main/javassist/CtClassType.java
   trunk/src/main/javassist/CtField.java
Log:
fixed JASSIST-119

Modified: trunk/src/main/javassist/CtClass.java
===================================================================
--- trunk/src/main/javassist/CtClass.java	2010-07-08 09:46:32 UTC (rev 551)
+++ trunk/src/main/javassist/CtClass.java	2010-07-08 11:01:36 UTC (rev 552)
@@ -52,7 +52,7 @@
     /**
      * The version number of this release.
      */
-    public static final String version = "3.12.0.GA";
+    public static final String version = "3.13.0.GA";
 
     /**
      * Prints the version number and the copyright notice.
@@ -681,13 +681,28 @@
      * may be a private field declared in a super class or interface.
      */
     public CtField getField(String name) throws NotFoundException {
+        return getField(name, null);
+    }
+
+    /**
+     * Returns the field with the specified name and type.  The returned field
+     * may be a private field declared in a super class or interface.
+     * Unlike Java, the JVM allows a class to have
+     * multiple fields with the same name but different types.
+     *
+     * @param name      the field name.
+     * @param desc      the type descriptor of the field.  It is available by
+     *                  {@link CtField#getSignature()}.
+     * @see CtField#getSignature()
+     */
+    public CtField getField(String name, String desc) throws NotFoundException {
         throw new NotFoundException(name);
     }
 
     /**
      * @return null     if the specified field is not found.
      */
-    CtField getField2(String name) { return null; }
+    CtField getField2(String name, String desc) { return null; }
 
     /**
      * Gets all the fields declared in the class.  The inherited fields
@@ -701,13 +716,29 @@
      * Retrieves the field with the specified name among the fields
      * declared in the class.
      *
-     * <p>Note: this method does not search the superclasses.
+     * <p>Note: this method does not search the super classes.
      */
     public CtField getDeclaredField(String name) throws NotFoundException {
         throw new NotFoundException(name);
     }
 
     /**
+     * Retrieves the field with the specified name and type among the fields
+     * declared in the class.  Unlike Java, the JVM allows a class to have
+     * multiple fields with the same name but different types.
+     *
+     * <p>Note: this method does not search the super classes.
+     *
+     * @param name      the field name.
+     * @param desc      the type descriptor of the field.  It is available by
+     *                  {@link CtField#getSignature()}.
+     * @see CtField#getSignature()
+     */
+    public CtField getDeclaredField(String name, String desc) throws NotFoundException {
+        throw new NotFoundException(name);
+    }
+
+    /**
      * Gets all the constructors and methods declared in the class.
      */
     public CtBehavior[] getDeclaredBehaviors() {

Modified: trunk/src/main/javassist/CtClassType.java
===================================================================
--- trunk/src/main/javassist/CtClassType.java	2010-07-08 09:46:32 UTC (rev 551)
+++ trunk/src/main/javassist/CtClassType.java	2010-07-08 11:01:36 UTC (rev 552)
@@ -893,16 +893,27 @@
         }
     }
 
-    public CtField getField(String name) throws NotFoundException {
-        CtField f = getField2(name);
-        if (f == null)
-            throw new NotFoundException("field: " + name + " in " + getName());
+    public CtField getField(String name, String desc) throws NotFoundException {
+        CtField f = getField2(name, desc);
+        return checkGetField(f, name, desc);
+    }
+
+    private CtField checkGetField(CtField f, String name, String desc)
+        throws NotFoundException
+    {
+        if (f == null) {
+            String msg = "field: " + name;
+            if (desc != null)
+                msg += " type " + desc;
+
+            throw new NotFoundException(msg + " in " + getName());
+        }
         else
             return f;
     }
 
-    CtField getField2(String name) {
-        CtField df = getDeclaredField2(name);
+    CtField getField2(String name, String desc) {
+        CtField df = getDeclaredField2(name, desc);
         if (df != null)
             return df;
 
@@ -910,14 +921,14 @@
             CtClass[] ifs = getInterfaces();
             int num = ifs.length;
             for (int i = 0; i < num; ++i) {
-                CtField f = ifs[i].getField2(name);
+                CtField f = ifs[i].getField2(name, desc);
                 if (f != null)
                     return f;
             }
 
             CtClass s = getSuperclass();
             if (s != null)
-                return s.getField2(name);
+                return s.getField2(name, desc);
         }
         catch (NotFoundException e) {}
         return null;
@@ -939,20 +950,22 @@
     }
 
     public CtField getDeclaredField(String name) throws NotFoundException {
-        CtField f = getDeclaredField2(name);
-        if (f == null)
-            throw new NotFoundException("field: " + name + " in " + getName());
-        else
-            return f;
+        return getDeclaredField(name, null);
     }
 
-    private CtField getDeclaredField2(String name) {
+    public CtField getDeclaredField(String name, String desc) throws NotFoundException {
+        CtField f = getDeclaredField2(name, desc);
+        return checkGetField(f, name, desc);
+    }
+
+    private CtField getDeclaredField2(String name, String desc) {
         CtMember.Cache memCache = getMembers();
         CtMember field = memCache.fieldHead();
         CtMember tail = memCache.lastField();
         while (field != tail) {
             field = field.next();
-            if (field.getName().equals(name))
+            if (field.getName().equals(name)
+                && (desc == null || desc.equals(field.getSignature())))
                 return (CtField)field;
         }
 

Modified: trunk/src/main/javassist/CtField.java
===================================================================
--- trunk/src/main/javassist/CtField.java	2010-07-08 09:46:32 UTC (rev 551)
+++ trunk/src/main/javassist/CtField.java	2010-07-08 11:01:36 UTC (rev 552)
@@ -319,6 +319,8 @@
 
     /**
      * Returns the character string representing the type of the field.
+     * The field signature is represented by a character string
+     * called a field descriptor, which is defined in the JVM specification.
      * If two fields have the same type,
      * <code>getSignature()</code> returns the same string.
      *



More information about the jboss-cvs-commits mailing list