]> source.dussan.org Git - javassist.git/commitdiff
Add the ability to change the signature of a constant pool methodref entry.
authoradrian <adrian@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 21 Feb 2006 13:30:23 +0000 (13:30 +0000)
committeradrian <adrian@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 21 Feb 2006 13:30:23 +0000 (13:30 +0000)
This is useful for JDK5 to 1.4 mapping, e.g.
java.lang.String.clone()Ljava.lang.String; -> java.lang.String.clone()Ljava.lang.Object;

git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@250 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/bytecode/ConstPool.java

index ed4974d5a74fb840862a2049ca13fea98f51b92f..1d720918e0691d55a45711caa740e710270c44a9 100644 (file)
@@ -361,6 +361,28 @@ public final class ConstPool {
         }
     }
 
+    /**
+     * Changed the Utf8Info of the <code>name_index</code> field of the
+     * <code>CONSTANT_NameAndType_info</code> structure
+     * indirectly specified by the given index.
+     *
+     * @param index     an index to a <code>CONSTANT_Methodref_info</code>.
+     * @param string    the new Utf8 string
+     */
+    public void setMethodrefType(int index, String string) {
+        MethodrefInfo minfo = (MethodrefInfo)getItem(index);
+        if (minfo == null)
+            throw new IllegalArgumentException("Not a Methodref_info " + index);
+        else {
+            NameAndTypeInfo n
+                = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+            if(n == null)
+                throw new IllegalStateException("Unable to find NameAndTypeInfo " + index);
+            else
+                setUtf8Info(n.typeDescriptor, string);
+        }
+    }
+
     /**
      * Reads the <code>class_index</code> field of the
      * <code>CONSTANT_InterfaceMethodref_info</code> structure
@@ -443,6 +465,29 @@ public final class ConstPool {
                 return getUtf8Info(n.typeDescriptor);
         }
     }
+    
+    /**
+     * Changed the Utf8Info of the <code>name_index</code> field of the
+     * <code>CONSTANT_NameAndType_info</code> structure
+     * indirectly specified by the given index.
+     *
+     * @param index     an index to a <code>CONSTANT_Methodref_info</code>.
+     * @param string    the new Utf8 string
+     */
+    public void setInterfaceMethodrefType(int index, String string) {
+        InterfaceMethodrefInfo minfo = (InterfaceMethodrefInfo)getItem(index);
+        if (minfo == null)
+            throw new IllegalArgumentException("Not an InterfaceMethodref_info " + index);
+        else {
+            NameAndTypeInfo n
+                = (NameAndTypeInfo)getItem(minfo.nameAndTypeIndex);
+            if(n == null)
+                throw new IllegalStateException("Unable to find NameAndTypeInfo " + index);
+            else
+                setUtf8Info(n.typeDescriptor, string);
+        }
+    }
+
     /**
      * Reads <code>CONSTANT_Integer_info</code>, <code>_Float_info</code>,
      * <code>_Long_info</code>, <code>_Double_info</code>, or
@@ -537,6 +582,18 @@ public final class ConstPool {
         return utf.string;
     }
 
+    /**
+     * Sets <code>CONSTANT_utf8_info</code> structure
+     * at the given index.
+     *
+     * @param index the index
+     * @param string the string specified by this entry.
+     */
+    public void setUtf8Info(int index, String string) {
+        Utf8Info utf = (Utf8Info)getItem(index);
+        utf.string = string;
+    }
+
     /**
      * Determines whether <code>CONSTANT_Methodref_info</code>
      * structure at the given index represents the constructor