From: ejort Date: Fri, 8 Apr 2005 17:19:58 +0000 (+0000) Subject: Add the ability to retrieve and change the Major/Minor versions of the ClassFile X-Git-Tag: rel_3_17_1_ga~456 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e2f3a2907491a7c9e3fe450e94598cbb8dd49f1c;p=javassist.git Add the ability to retrieve and change the Major/Minor versions of the ClassFile git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@165 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 713e509d..74711369 100644 --- a/src/main/javassist/bytecode/ClassFile.java +++ b/src/main/javassist/bytecode/ClassFile.java @@ -623,4 +623,44 @@ public final class ClassFile { out.writeShort(attributes.size()); AttributeInfo.writeAll(attributes, out); } + + /** + * Get the Major version + * + * @return the major version + */ + public int getMajorVersion() + { + return major; + } + + /** + * Set the Major version + * + * @param major the major version + */ + public void setMajorVersion(int major) + { + this.major = major; + } + + /** + * Get the Minor version + * + * @return the minor version + */ + public int getMinorVersion() + { + return minor; + } + + /** + * Set the Minor version + * + * @param minor the minor version + */ + public void setMinorVersion(int minor) + { + this.minor = minor; + } } diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index ad5edc5b..1676c116 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -20,8 +20,10 @@ import java.io.DataOutputStream; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; import java.io.IOException; -import java.util.Map; import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import javassist.CtClass; /** @@ -837,6 +839,25 @@ public final class ConstPool { } } + /** + * Get all the class names + * + * @return a set of class names + */ + public Set getClassNames() + { + HashSet result = new HashSet(); + LongVector v = items; + int size = numOfItems; + for (int i = 1; i < size; ++i) + { + String className = ((ConstInfo) v.elementAt(i)).getClassName(this); + if (className != null) + result.add(className); + } + return result; + } + /** * Replaces all occurrences of a class name. * @@ -961,6 +982,7 @@ public final class ConstPool { abstract class ConstInfo { public abstract int getTag(); + public String getClassName(ConstPool cp) { return null; } public void renameClass(ConstPool cp, String oldName, String newName) {} public void renameClass(ConstPool cp, Map classnames) {} public abstract int copy(ConstPool src, ConstPool dest, Map classnames); @@ -1010,6 +1032,11 @@ class ClassInfo extends ConstInfo { public int getTag() { return tag; } + public String getClassName(ConstPool cp) + { + return cp.getUtf8Info(name); + }; + public void renameClass(ConstPool cp, String oldName, String newName) { String nameStr = cp.getUtf8Info(name); if (nameStr.equals(oldName))