From: adrian Date: Tue, 21 Feb 2006 13:30:23 +0000 (+0000) Subject: Add the ability to change the signature of a constant pool methodref entry. X-Git-Tag: rel_3_17_1_ga~377 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=efa62f09d0bf25f3f571cab4f5f235023315f5e0;p=javassist.git Add the ability to change the signature of a constant pool methodref entry. 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 --- diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index ed4974d5..1d720918 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -361,6 +361,28 @@ public final class ConstPool { } } + /** + * Changed the Utf8Info of the name_index field of the + * CONSTANT_NameAndType_info structure + * indirectly specified by the given index. + * + * @param index an index to a CONSTANT_Methodref_info. + * @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 class_index field of the * CONSTANT_InterfaceMethodref_info structure @@ -443,6 +465,29 @@ public final class ConstPool { return getUtf8Info(n.typeDescriptor); } } + + /** + * Changed the Utf8Info of the name_index field of the + * CONSTANT_NameAndType_info structure + * indirectly specified by the given index. + * + * @param index an index to a CONSTANT_Methodref_info. + * @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 CONSTANT_Integer_info, _Float_info, * _Long_info, _Double_info, or @@ -537,6 +582,18 @@ public final class ConstPool { return utf.string; } + /** + * Sets CONSTANT_utf8_info 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 CONSTANT_Methodref_info * structure at the given index represents the constructor