From: chibash Date: Mon, 11 Sep 2017 16:17:19 +0000 (+0900) Subject: updates ConstPool to support Module and Package X-Git-Tag: list~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=78223965e57c53959383fe4124f324c00f5545bd;p=javassist.git updates ConstPool to support Module and Package --- diff --git a/.gitignore b/.gitignore index bd3c6ec8..8c7111c3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ target/ runtest/ html/ lib/ +tmp/ .DS_Store .classpath diff --git a/javassist.jar b/javassist.jar index 98e6eebb..c3692a10 100644 Binary files a/javassist.jar and b/javassist.jar differ diff --git a/src/main/javassist/bytecode/AccessFlag.java b/src/main/javassist/bytecode/AccessFlag.java index 736135ec..244e29d4 100644 --- a/src/main/javassist/bytecode/AccessFlag.java +++ b/src/main/javassist/bytecode/AccessFlag.java @@ -41,12 +41,13 @@ public class AccessFlag { public static final int MANDATED = 0x8000; public static final int SUPER = 0x0020; + public static final int MODULE = 0x8000; // Note: 0x0020 is assigned to both ACC_SUPER and ACC_SYNCHRONIZED // although java.lang.reflect.Modifier does not recognize ACC_SUPER. /** - * Truns the public bit on. The protected and private bits are + * Turns the public bit on. The protected and private bits are * cleared. */ public static int setPublic(int accflags) { @@ -54,7 +55,7 @@ public class AccessFlag { } /** - * Truns the protected bit on. The protected and public bits are + * Turns the protected bit on. The protected and public bits are * cleared. */ public static int setProtected(int accflags) { diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index 86d7eb40..2ac31ba2 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -108,6 +108,16 @@ public final class ConstPool { */ public static final int CONST_InvokeDynamic = InvokeDynamicInfo.tag; + /** + * CONSTANT_Module + */ + public static final int CONST_Module = ModuleInfo.tag; + + /** + * CONSTANT_Package + */ + public static final int CONST_Package = PackageInfo.tag; + /** * Represents the class using this constant pool table. */ @@ -737,6 +747,31 @@ public final class ConstPool { } } + /** + * Reads the name_index field of the + * CONSTANT_Module_info structure at the given index. + * + * @return the module name at name_index. + * @since 3.22 + */ + public String getModuleInfo(int index) { + ModuleInfo mi = (ModuleInfo)getItem(index); + return getUtf8Info(mi.name); + } + + /** + * Reads the name_index field of the + * CONSTANT_Package_info structure at the given index. + * + * @return the package name at name_index. It is a slash-separated name + * such as com/oracle/net. + * @since 3.22 + */ + public String getPackageInfo(int index) { + PackageInfo mi = (PackageInfo)getItem(index); + return getUtf8Info(mi.name); + } + /** * Determines whether CONSTANT_Methodref_info * structure at the given index represents the constructor @@ -1117,6 +1152,26 @@ public final class ConstPool { return addItem(new InvokeDynamicInfo(bootstrap, nameAndType, numOfItems)); } + /** + * Adds a new CONSTANT_Module_info + * @param nameIndex the index of the Utf8 entry. + * @return the index of the added entry. + * @since 3.22 + */ + public int addModuleInfo(int nameIndex) { + return addItem(new ModuleInfo(nameIndex, numOfItems)); + } + + /** + * Adds a new CONSTANT_Package_info + * @param nameIndex the index of the Utf8 entry. + * @return the index of the added entry. + * @since 3.22 + */ + public int addPackageInfo(int nameIndex) { + return addItem(new PackageInfo(nameIndex, numOfItems)); + } + /** * Get all the class names. * @@ -1240,6 +1295,12 @@ public final class ConstPool { case InvokeDynamicInfo.tag : // 18 info = new InvokeDynamicInfo(in, numOfItems); break; + case ModuleInfo.tag : // 19 + info = new ModuleInfo(in, numOfItems); + break; + case PackageInfo.tag : // 20 + info = new PackageInfo(in, numOfItems); + break; default : throw new IOException("invalid constant type: " + tag + " at " + numOfItems); } @@ -1996,3 +2057,89 @@ class InvokeDynamicInfo extends ConstInfo { out.println(nameAndType); } } + +class ModuleInfo extends ConstInfo { + static final int tag = 19; + int name; + + public ModuleInfo(int moduleName, int index) { + super(index); + name = moduleName; + } + + public ModuleInfo(DataInputStream in, int index) throws IOException { + super(index); + name = in.readUnsignedShort(); + } + + public int hashCode() { return name; } + + public boolean equals(Object obj) { + return obj instanceof ModuleInfo && ((ModuleInfo)obj).name == name; + } + + public int getTag() { return tag; } + + public String getModuleName(ConstPool cp) { + return cp.getUtf8Info(name); + } + + public int copy(ConstPool src, ConstPool dest, Map map) { + String moduleName = src.getUtf8Info(name); + int newName = dest.addUtf8Info(moduleName); + return dest.addModuleInfo(newName); + } + + public void write(DataOutputStream out) throws IOException { + out.writeByte(tag); + out.writeShort(name); + } + + public void print(PrintWriter out) { + out.print("Module #"); + out.println(name); + } +} + +class PackageInfo extends ConstInfo { + static final int tag = 20; + int name; + + public PackageInfo(int moduleName, int index) { + super(index); + name = moduleName; + } + + public PackageInfo(DataInputStream in, int index) throws IOException { + super(index); + name = in.readUnsignedShort(); + } + + public int hashCode() { return name; } + + public boolean equals(Object obj) { + return obj instanceof PackageInfo && ((PackageInfo)obj).name == name; + } + + public int getTag() { return tag; } + + public String getPackageName(ConstPool cp) { + return cp.getUtf8Info(name); + } + + public int copy(ConstPool src, ConstPool dest, Map map) { + String packageName = src.getUtf8Info(name); + int newName = dest.addUtf8Info(packageName); + return dest.addModuleInfo(newName); + } + + public void write(DataOutputStream out) throws IOException { + out.writeByte(tag); + out.writeShort(name); + } + + public void print(PrintWriter out) { + out.print("Package #"); + out.println(name); + } +}