src/share/classes/com/sun/tools/javap/ConstantWriter.java

changeset 300
ed989c347b3c
parent 267
e2722bd43f3a
child 348
743f17b55b44
equal deleted inserted replaced
299:22872b24d38c 300:ed989c347b3c
38 * you write code that depends on this, you do so at your own risk. 38 * you write code that depends on this, you do so at your own risk.
39 * This code and its internal interfaces are subject to change or 39 * This code and its internal interfaces are subject to change or
40 * deletion without notice.</b> 40 * deletion without notice.</b>
41 */ 41 */
42 public class ConstantWriter extends BasicWriter { 42 public class ConstantWriter extends BasicWriter {
43 static ConstantWriter instance(Context context) { 43 public static ConstantWriter instance(Context context) {
44 ConstantWriter instance = context.get(ConstantWriter.class); 44 ConstantWriter instance = context.get(ConstantWriter.class);
45 if (instance == null) 45 if (instance == null)
46 instance = new ConstantWriter(context); 46 instance = new ConstantWriter(context);
47 return instance; 47 return instance;
48 } 48 }
52 context.put(ConstantWriter.class, this); 52 context.put(ConstantWriter.class, this);
53 classWriter = ClassWriter.instance(context); 53 classWriter = ClassWriter.instance(context);
54 options = Options.instance(context); 54 options = Options.instance(context);
55 } 55 }
56 56
57 void writeConstantPool() { 57 protected void writeConstantPool() {
58 ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
59 writeConstantPool(constant_pool);
60 }
61
62 protected void writeConstantPool(ConstantPool constant_pool) {
58 ConstantPool.Visitor<Integer, Void> v = new ConstantPool.Visitor<Integer,Void>() { 63 ConstantPool.Visitor<Integer, Void> v = new ConstantPool.Visitor<Integer,Void>() {
59 public Integer visitClass(CONSTANT_Class_info info, Void p) { 64 public Integer visitClass(CONSTANT_Class_info info, Void p) {
60 println("#" + info.name_index + ";\t// " + stringValue(info)); 65 println("#" + info.name_index + ";\t// " + stringValue(info));
61 return 1; 66 return 1;
62 } 67 }
112 return 1; 117 return 1;
113 } 118 }
114 119
115 }; 120 };
116 println(" Constant pool:"); 121 println(" Constant pool:");
117 ConstantPool constant_pool = classWriter.getClassFile().constant_pool;
118 int cpx = 1; 122 int cpx = 1;
119 while (cpx < constant_pool.size()) { 123 while (cpx < constant_pool.size()) {
120 try { 124 try {
121 CPInfo cpInfo = constant_pool.get(cpx); 125 CPInfo cpInfo = constant_pool.get(cpx);
122 print("const #" + cpx + " = " + tagName(cpInfo.getTag()) + "\t"); 126 print("const #" + cpx + " = " + tagName(cpInfo.getTag()) + "\t");
125 print("const #" + cpx); // should not happen 129 print("const #" + cpx); // should not happen
126 } 130 }
127 } 131 }
128 } 132 }
129 133
130 void write(int cpx) { 134 protected void write(int cpx) {
131 ClassFile classFile = classWriter.getClassFile(); 135 ClassFile classFile = classWriter.getClassFile();
132 if (cpx == 0) { 136 if (cpx == 0) {
133 print("#0"); 137 print("#0");
134 return; 138 return;
135 } 139 }

mercurial