diff options
Diffstat (limited to 'src/main/javassist/bytecode/InnerClassesAttribute.java')
-rw-r--r-- | src/main/javassist/bytecode/InnerClassesAttribute.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/InnerClassesAttribute.java b/src/main/javassist/bytecode/InnerClassesAttribute.java index 5dffd6ee..cf021791 100644 --- a/src/main/javassist/bytecode/InnerClassesAttribute.java +++ b/src/main/javassist/bytecode/InnerClassesAttribute.java @@ -198,6 +198,40 @@ public class InnerClassesAttribute extends AttributeInfo { } /** + * Removes the {@code nth} entry. It does not eliminate + * constant pool items that the removed entry refers to. + * {@link ClassFile#compact()} should be executed to remove + * these unnecessary items. + * + * @param nth 0, 1, 2, ... + * @return the number of items after the removal. + * @see ClassFile#compact() + */ + public int remove(int nth) { + byte[] data = get(); + int len = data.length; + if (len < 10) + return 0; + + int n = ByteArray.readU16bit(data, 0); + int nthPos = 2 + nth * 8; + if (n <= nth) + return n; + + byte[] newData = new byte[len - 8]; + ByteArray.write16bit(n - 1, newData, 0); + int i = 2, j = 2; + while (i < len) + if (i == nthPos) + i += 8; + else + newData[j++] = data[i++]; + + set(newData); + return n - 1; + } + + /** * Makes a copy. Class names are replaced according to the * given <code>Map</code> object. * |