summaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-08-19 14:04:32 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2004-08-19 14:04:32 +0000
commit8c82477b4172ed0db9e5d866a0dba22ae20eb23f (patch)
tree413e976fd906df977b3ebf383f4eddf9372de84e /src/main/javassist/bytecode
parent7fd8dd68388f6e910b1e0f54df363a84481d0809 (diff)
downloadjavassist-8c82477b4172ed0db9e5d866a0dba22ae20eb23f.tar.gz
javassist-8c82477b4172ed0db9e5d866a0dba22ae20eb23f.zip
implemented pruning
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@125 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode')
-rw-r--r--src/main/javassist/bytecode/AnnotationsAttribute.java4
-rw-r--r--src/main/javassist/bytecode/ClassFile.java36
-rw-r--r--src/main/javassist/bytecode/ConstPool.java5
-rw-r--r--src/main/javassist/bytecode/FieldInfo.java7
-rw-r--r--src/main/javassist/bytecode/MethodInfo.java7
-rw-r--r--src/main/javassist/bytecode/ParameterAnnotationsAttribute.java2
-rw-r--r--src/main/javassist/bytecode/annotation/AnnotationsWriter.java8
-rw-r--r--src/main/javassist/bytecode/annotation/EnumMemberValue.java2
8 files changed, 62 insertions, 9 deletions
diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java
index 6a93f43a..a6dfe87a 100644
--- a/src/main/javassist/bytecode/AnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/AnnotationsAttribute.java
@@ -84,7 +84,7 @@ public class AnnotationsAttribute extends AttributeInfo {
* @param cp constant pool
* @param attrname attribute name (<code>visibleTag</code> or
* <code>invisibleTag</code>).
- * @see #setAnnotations(Annotations[])
+ * @see #setAnnotations(Annotation[])
*/
public AnnotationsAttribute(ConstPool cp, String attrname) {
this(cp, attrname, new byte[] { 0, 0 });
@@ -127,7 +127,7 @@ public class AnnotationsAttribute extends AttributeInfo {
* this object unless the tree is copied back to this object by
* <code>setAnnotations()</code>.
*
- * @see #setAnnotations()
+ * @see #setAnnotations(Annotation[])
*/
public Annotation[] getAnnotations() {
try {
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 79695296..d9b6dfa6 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -99,6 +99,42 @@ public final class ClassFile {
}
/**
+ * Discards all attributes, associated with both the class file and
+ * the members such as a code attribute and exceptions attribute.
+ * The unused constant pool entries are also discarded (a new packed
+ * constant pool is constructed).
+ */
+ public void prune() {
+ ConstPool cp = new ConstPool(thisclassname);
+ superClass = cp.addClassInfo(getSuperclass());
+
+ if (interfaces != null) {
+ int n = interfaces.length;
+ for (int i = 0; i < n; ++i)
+ interfaces[i]
+ = cp.addClassInfo(constPool.getClassInfo(interfaces[i]));
+ }
+
+ ArrayList list = methods;
+ int n = list.size();
+ for (int i = 0; i < n; ++i) {
+ MethodInfo minfo = (MethodInfo)list.get(i);
+ minfo.prune(cp);
+ }
+
+ list = fields;
+ n = list.size();
+ for (int i = 0; i < n; ++i) {
+ FieldInfo finfo = (FieldInfo)list.get(i);
+ finfo.prune(cp);
+ }
+
+ attributes = new LinkedList();
+ cp.prune();
+ constPool = cp;
+ }
+
+ /**
* Returns a constant pool table.
*/
public ConstPool getConstPool() {
diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java
index 6a024dbf..6f0b2bef 100644
--- a/src/main/javassist/bytecode/ConstPool.java
+++ b/src/main/javassist/bytecode/ConstPool.java
@@ -124,6 +124,11 @@ public final class ConstPool {
read(in);
}
+ void prune() {
+ classes = new HashMap();
+ strings = new HashMap();
+ }
+
/**
* Returns the name of the class using this constant pool table.
*/
diff --git a/src/main/javassist/bytecode/FieldInfo.java b/src/main/javassist/bytecode/FieldInfo.java
index 8cdb1ae3..54ae1ba6 100644
--- a/src/main/javassist/bytecode/FieldInfo.java
+++ b/src/main/javassist/bytecode/FieldInfo.java
@@ -59,6 +59,13 @@ public final class FieldInfo {
read(in);
}
+ void prune(ConstPool cp) {
+ attribute = null;
+ name = cp.addUtf8Info(getName());
+ descriptor = cp.addUtf8Info(getDescriptor());
+ constPool = cp;
+ }
+
/**
* Returns the constant pool table used
* by this <code>field_info</code>.
diff --git a/src/main/javassist/bytecode/MethodInfo.java b/src/main/javassist/bytecode/MethodInfo.java
index b3d33213..9e866578 100644
--- a/src/main/javassist/bytecode/MethodInfo.java
+++ b/src/main/javassist/bytecode/MethodInfo.java
@@ -95,6 +95,13 @@ public final class MethodInfo {
read(src, methodname, classnameMap);
}
+ void prune(ConstPool cp) {
+ attribute = null;
+ name = cp.addUtf8Info(getName());
+ descriptor = cp.addUtf8Info(getDescriptor());
+ constPool = cp;
+ }
+
/**
* Returns a method name.
*/
diff --git a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
index d44e4386..e4c6e235 100644
--- a/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
+++ b/src/main/javassist/bytecode/ParameterAnnotationsAttribute.java
@@ -123,7 +123,7 @@ public class ParameterAnnotationsAttribute extends AttributeInfo {
* @return Each element of the returned array represents an array of
* annotations that are associated with each method parameter.
*
- * @see #setAnnotations()
+ * @see #setAnnotations(Annotation[][])
*/
public Annotation[][] getAnnotations() {
try {
diff --git a/src/main/javassist/bytecode/annotation/AnnotationsWriter.java b/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
index 155201c0..0d609503 100644
--- a/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
+++ b/src/main/javassist/bytecode/annotation/AnnotationsWriter.java
@@ -23,7 +23,6 @@ import javassist.bytecode.ConstPool;
/**
* A convenience class for constructing a
* <code>..Annotations_attribute</code>.
- * It is typically used together with <code>AnnotationsVisitor</code>.
* See the source code of the <code>AnnotationsAttribute.Copier</code> class.
*
* <p>The following code snippet is an example of use of this class:
@@ -51,12 +50,11 @@ import javassist.bytecode.ConstPool;
* corresponding to this annotation:
*
* <ul><pre>
- * @Author(name = "chiba", address = "tokyo")
+ * &nbsp;@Author(name = "chiba", address = "tokyo")
* </pre></ul>
*
- * @see AnnotationsAttribute
- * @see ParameterAnnotationsAttribute
- * @see AnnotationsVisitor
+ * @see javassist.bytecode.AnnotationsAttribute
+ * @see javassist.bytecode.ParameterAnnotationsAttribute
*/
public class AnnotationsWriter {
private OutputStream output;
diff --git a/src/main/javassist/bytecode/annotation/EnumMemberValue.java b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
index c059c241..95c617ad 100644
--- a/src/main/javassist/bytecode/annotation/EnumMemberValue.java
+++ b/src/main/javassist/bytecode/annotation/EnumMemberValue.java
@@ -64,7 +64,7 @@ public class EnumMemberValue extends MemberValue {
/**
* Changes the enum type name.
*
- * @param classname a fully-qualified type name.
+ * @param typename a fully-qualified type name.
*/
public void setType(String typename) {
typeIndex = cp.addUtf8Info(Descriptor.of(typename));