diff options
author | chibash <chiba@javassist.org> | 2017-09-12 01:17:19 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2017-09-12 01:17:19 +0900 |
commit | 78223965e57c53959383fe4124f324c00f5545bd (patch) | |
tree | 0bbb44c3bd4ced26f62523a533a88555bc8e5aaa /src/main | |
parent | dfd0733e1f73853453ff76086481ebec2e88a624 (diff) | |
download | javassist-78223965e57c53959383fe4124f324c00f5545bd.tar.gz javassist-78223965e57c53959383fe4124f324c00f5545bd.zip |
updates ConstPool to support Module and Package
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/javassist/bytecode/AccessFlag.java | 5 | ||||
-rw-r--r-- | src/main/javassist/bytecode/ConstPool.java | 147 |
2 files changed, 150 insertions, 2 deletions
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 @@ -109,6 +109,16 @@ public final class ConstPool { public static final int CONST_InvokeDynamic = InvokeDynamicInfo.tag; /** + * <code>CONSTANT_Module</code> + */ + public static final int CONST_Module = ModuleInfo.tag; + + /** + * <code>CONSTANT_Package</code> + */ + public static final int CONST_Package = PackageInfo.tag; + + /** * Represents the class using this constant pool table. */ public static final CtClass THIS = null; @@ -738,6 +748,31 @@ public final class ConstPool { } /** + * Reads the <code>name_index</code> field of the + * <code>CONSTANT_Module_info</code> structure at the given index. + * + * @return the module name at <code>name_index</code>. + * @since 3.22 + */ + public String getModuleInfo(int index) { + ModuleInfo mi = (ModuleInfo)getItem(index); + return getUtf8Info(mi.name); + } + + /** + * Reads the <code>name_index</code> field of the + * <code>CONSTANT_Package_info</code> structure at the given index. + * + * @return the package name at <code>name_index</code>. 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 <code>CONSTANT_Methodref_info</code> * structure at the given index represents the constructor * of the given class. @@ -1118,6 +1153,26 @@ public final class ConstPool { } /** + * Adds a new <code>CONSTANT_Module_info</code> + * @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 <code>CONSTANT_Package_info</code> + * @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. * * @return a set of class names (<code>String</code> objects). @@ -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); + } +} |