aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2015-07-22 02:30:54 +0900
committerchibash <chiba@javassist.org>2015-07-22 02:30:54 +0900
commit2705a49f8fbe930cffa4358553e625071b3bf8ed (patch)
treeda5cff06388f5952191d071099573621dd902f4d /src/main/javassist/bytecode
parentecd733a236b3963c36ad869e05d14d1f49e99a92 (diff)
downloadjavassist-2705a49f8fbe930cffa4358553e625071b3bf8ed.tar.gz
javassist-2705a49f8fbe930cffa4358553e625071b3bf8ed.zip
added InnerClassAttribute#remove method
Diffstat (limited to 'src/main/javassist/bytecode')
-rw-r--r--src/main/javassist/bytecode/InnerClassesAttribute.java34
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.
*