author | duke |
Wed, 05 Jul 2017 20:46:50 +0200 | |
changeset 32264 | 58af228a68fa |
parent 30846 | 2b3f379840f0 |
child 39104 | 61c5b5f8fd8c |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
2 |
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
4 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
10 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
16 |
* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
24 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
25 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
26 |
package com.sun.tools.javap; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
27 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
28 |
import com.sun.tools.classfile.ClassFile; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
29 |
import com.sun.tools.classfile.ConstantPool; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
30 |
import com.sun.tools.classfile.ConstantPoolException; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
31 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
import static com.sun.tools.classfile.ConstantPool.*; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
33 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
34 |
/* |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
35 |
* Write a constant pool entry. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
36 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
37 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
38 |
* If you write code that depends on this, you do so at your own risk. |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
39 |
* This code and its internal interfaces are subject to change or |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
* deletion without notice.</b> |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
41 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
public class ConstantWriter extends BasicWriter { |
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
43 |
public static ConstantWriter instance(Context context) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
44 |
ConstantWriter instance = context.get(ConstantWriter.class); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
45 |
if (instance == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
46 |
instance = new ConstantWriter(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
47 |
return instance; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
48 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
49 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
50 |
protected ConstantWriter(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
51 |
super(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
52 |
context.put(ConstantWriter.class, this); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
53 |
classWriter = ClassWriter.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
54 |
options = Options.instance(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
55 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
56 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
57 |
protected void writeConstantPool() { |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
58 |
ConstantPool constant_pool = classWriter.getClassFile().constant_pool; |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
59 |
writeConstantPool(constant_pool); |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
60 |
} |
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
61 |
|
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
62 |
protected void writeConstantPool(ConstantPool constant_pool) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
63 |
ConstantPool.Visitor<Integer, Void> v = new ConstantPool.Visitor<Integer,Void>() { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
64 |
public Integer visitClass(CONSTANT_Class_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
65 |
print("#" + info.name_index); |
3546 | 66 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
67 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
68 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
69 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
70 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
71 |
public Integer visitDouble(CONSTANT_Double_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
72 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
73 |
return 2; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
74 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
75 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
76 |
public Integer visitFieldref(CONSTANT_Fieldref_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
77 |
print("#" + info.class_index + ".#" + info.name_and_type_index); |
3546 | 78 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
79 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
80 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
81 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
82 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
83 |
public Integer visitFloat(CONSTANT_Float_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
84 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
85 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
86 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
87 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
88 |
public Integer visitInteger(CONSTANT_Integer_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
89 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
90 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
91 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
92 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
93 |
public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
94 |
print("#" + info.class_index + ".#" + info.name_and_type_index); |
3546 | 95 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
96 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
97 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
98 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
99 |
|
8042 | 100 |
public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { |
101 |
print("#" + info.bootstrap_method_attr_index + ":#" + info.name_and_type_index); |
|
102 |
tab(); |
|
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
103 |
println("// " + stringValue(info)); |
8042 | 104 |
return 1; |
105 |
} |
|
106 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
107 |
public Integer visitLong(CONSTANT_Long_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
108 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
109 |
return 2; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
110 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
111 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
112 |
public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
113 |
print("#" + info.name_index + ":#" + info.type_index); |
3546 | 114 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
115 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
116 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
117 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
118 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
119 |
public Integer visitMethodref(CONSTANT_Methodref_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
120 |
print("#" + info.class_index + ".#" + info.name_and_type_index); |
3546 | 121 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
122 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
123 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
124 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
125 |
|
8042 | 126 |
public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { |
127 |
print("#" + info.reference_kind.tag + ":#" + info.reference_index); |
|
128 |
tab(); |
|
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
129 |
println("// " + stringValue(info)); |
8042 | 130 |
return 1; |
131 |
} |
|
132 |
||
133 |
public Integer visitMethodType(CONSTANT_MethodType_info info, Void p) { |
|
134 |
print("#" + info.descriptor_index); |
|
135 |
tab(); |
|
136 |
println("// " + stringValue(info)); |
|
137 |
return 1; |
|
138 |
} |
|
139 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
140 |
public Integer visitString(CONSTANT_String_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
141 |
print("#" + info.string_index); |
3546 | 142 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
143 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
144 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
145 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
146 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
147 |
public Integer visitUtf8(CONSTANT_Utf8_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
148 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
149 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
150 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
151 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
152 |
}; |
3546 | 153 |
println("Constant pool:"); |
154 |
indent(+1); |
|
155 |
int width = String.valueOf(constant_pool.size()).length() + 1; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
156 |
int cpx = 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
157 |
while (cpx < constant_pool.size()) { |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
158 |
print(String.format("%" + width + "s", ("#" + cpx))); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
159 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
160 |
CPInfo cpInfo = constant_pool.get(cpx); |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
161 |
print(String.format(" = %-18s ", cpTagName(cpInfo))); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
162 |
cpx += cpInfo.accept(v, null); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
163 |
} catch (ConstantPool.InvalidIndex ex) { |
3546 | 164 |
// should not happen |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
165 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
166 |
} |
3546 | 167 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
168 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
169 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
170 |
protected void write(int cpx) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
171 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
172 |
if (cpx == 0) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
173 |
print("#0"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
174 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
175 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
176 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
177 |
CPInfo cpInfo; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
178 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
179 |
cpInfo = classFile.constant_pool.get(cpx); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
180 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
181 |
print("#" + cpx); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
182 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
183 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
184 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
185 |
int tag = cpInfo.getTag(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
186 |
switch (tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
187 |
case CONSTANT_Methodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
188 |
case CONSTANT_InterfaceMethodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
189 |
case CONSTANT_Fieldref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
190 |
// simplify references within this class |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
191 |
CPRefInfo ref = (CPRefInfo) cpInfo; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
192 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
193 |
if (ref.class_index == classFile.this_class) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
194 |
cpInfo = classFile.constant_pool.get(ref.name_and_type_index); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
195 |
} catch (ConstantPool.InvalidIndex e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
196 |
// ignore, for now |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
197 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
198 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
199 |
print(tagName(tag) + " " + stringValue(cpInfo)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
200 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
201 |
|
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
202 |
String cpTagName(CPInfo cpInfo) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
203 |
String n = cpInfo.getClass().getSimpleName(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
204 |
return n.replace("CONSTANT_", "").replace("_info", ""); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
205 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
206 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
207 |
String tagName(int tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
208 |
switch (tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
209 |
case CONSTANT_Utf8: |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
210 |
return "Utf8"; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
211 |
case CONSTANT_Integer: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
212 |
return "int"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
213 |
case CONSTANT_Float: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
214 |
return "float"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
215 |
case CONSTANT_Long: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
216 |
return "long"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
217 |
case CONSTANT_Double: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
218 |
return "double"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
219 |
case CONSTANT_Class: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
220 |
return "class"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
221 |
case CONSTANT_String: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
222 |
return "String"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
223 |
case CONSTANT_Fieldref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
224 |
return "Field"; |
8042 | 225 |
case CONSTANT_MethodHandle: |
226 |
return "MethodHandle"; |
|
227 |
case CONSTANT_MethodType: |
|
228 |
return "MethodType"; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
229 |
case CONSTANT_Methodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
230 |
return "Method"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
231 |
case CONSTANT_InterfaceMethodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
232 |
return "InterfaceMethod"; |
8042 | 233 |
case CONSTANT_InvokeDynamic: |
234 |
return "InvokeDynamic"; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
235 |
case CONSTANT_NameAndType: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
236 |
return "NameAndType"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
237 |
default: |
8042 | 238 |
return "(unknown tag " + tag + ")"; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
239 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
240 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
241 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
242 |
String stringValue(int constant_pool_index) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
243 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
244 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
245 |
return stringValue(classFile.constant_pool.get(constant_pool_index)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
246 |
} catch (ConstantPool.InvalidIndex e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
247 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
248 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
249 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
250 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
251 |
String stringValue(CPInfo cpInfo) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
252 |
return stringValueVisitor.visit(cpInfo); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
253 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
254 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
255 |
StringValueVisitor stringValueVisitor = new StringValueVisitor(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
256 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
257 |
private class StringValueVisitor implements ConstantPool.Visitor<String, Void> { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
258 |
public String visit(CPInfo info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
259 |
return info.accept(this, null); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
260 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
261 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
262 |
public String visitClass(CONSTANT_Class_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
263 |
return getCheckedName(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
264 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
265 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
266 |
String getCheckedName(CONSTANT_Class_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
267 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
268 |
return checkName(info.getName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
269 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
270 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
271 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
272 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
273 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
274 |
public String visitDouble(CONSTANT_Double_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
275 |
return info.value + "d"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
276 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
277 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
278 |
public String visitFieldref(CONSTANT_Fieldref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
279 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
280 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
281 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
282 |
public String visitFloat(CONSTANT_Float_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
283 |
return info.value + "f"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
284 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
285 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
286 |
public String visitInteger(CONSTANT_Integer_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
287 |
return String.valueOf(info.value); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
288 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
289 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
290 |
public String visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
291 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
292 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
293 |
|
8042 | 294 |
public String visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { |
295 |
try { |
|
296 |
String callee = stringValue(info.getNameAndTypeInfo()); |
|
297 |
return "#" + info.bootstrap_method_attr_index + ":" + callee; |
|
298 |
} catch (ConstantPoolException e) { |
|
299 |
return report(e); |
|
300 |
} |
|
301 |
} |
|
302 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
303 |
public String visitLong(CONSTANT_Long_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
304 |
return info.value + "l"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
305 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
306 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
307 |
public String visitNameAndType(CONSTANT_NameAndType_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
308 |
return getCheckedName(info) + ":" + getType(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
309 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
310 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
311 |
String getCheckedName(CONSTANT_NameAndType_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
312 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
313 |
return checkName(info.getName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
314 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
315 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
316 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
317 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
318 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
319 |
String getType(CONSTANT_NameAndType_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
320 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
321 |
return info.getType(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
322 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
323 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
324 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
325 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
326 |
|
8042 | 327 |
public String visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { |
328 |
try { |
|
329 |
return info.reference_kind.name + " " + stringValue(info.getCPRefInfo()); |
|
330 |
} catch (ConstantPoolException e) { |
|
331 |
return report(e); |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
public String visitMethodType(CONSTANT_MethodType_info info, Void p) { |
|
336 |
try { |
|
337 |
return info.getType(); |
|
338 |
} catch (ConstantPoolException e) { |
|
339 |
return report(e); |
|
340 |
} |
|
341 |
} |
|
342 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
343 |
public String visitMethodref(CONSTANT_Methodref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
344 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
345 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
346 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
347 |
public String visitString(CONSTANT_String_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
348 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
349 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
350 |
int string_index = info.string_index; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
351 |
return stringValue(classFile.constant_pool.getUTF8Info(string_index)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
352 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
353 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
354 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
355 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
356 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
357 |
public String visitUtf8(CONSTANT_Utf8_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
358 |
String s = info.value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
359 |
StringBuilder sb = new StringBuilder(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
360 |
for (int i = 0; i < s.length(); i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
361 |
char c = s.charAt(i); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
362 |
switch (c) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
363 |
case '\t': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
364 |
sb.append('\\').append('t'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
365 |
break; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
366 |
case '\n': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
367 |
sb.append('\\').append('n'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
368 |
break; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
369 |
case '\r': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
370 |
sb.append('\\').append('r'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
371 |
break; |
26390
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
372 |
case '\b': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
373 |
sb.append('\\').append('b'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
374 |
break; |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
375 |
case '\f': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
376 |
sb.append('\\').append('f'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
377 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
378 |
case '\"': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
379 |
sb.append('\\').append('\"'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
380 |
break; |
26390
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
381 |
case '\'': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
382 |
sb.append('\\').append('\''); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
383 |
break; |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
384 |
case '\\': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
385 |
sb.append('\\').append('\\'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
386 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
387 |
default: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
388 |
sb.append(c); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
389 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
390 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
391 |
return sb.toString(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
392 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
393 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
394 |
String visitRef(CPRefInfo info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
395 |
String cn = getCheckedClassName(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
396 |
String nat; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
397 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
398 |
nat = stringValue(info.getNameAndTypeInfo()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
399 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
400 |
nat = report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
401 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
402 |
return cn + "." + nat; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
403 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
404 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
405 |
String getCheckedClassName(CPRefInfo info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
406 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
407 |
return checkName(info.getClassName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
408 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
409 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
410 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
411 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
412 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
413 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
414 |
/* If name is a valid binary name, return it; otherwise quote it. */ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
415 |
private static String checkName(String name) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
416 |
if (name == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
417 |
return "null"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
418 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
419 |
int len = name.length(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
420 |
if (len == 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
421 |
return "\"\""; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
422 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
423 |
int cc = '/'; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
424 |
int cp; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
425 |
for (int k = 0; k < len; k += Character.charCount(cp)) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
426 |
cp = name.codePointAt(k); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
427 |
if ((cc == '/' && !Character.isJavaIdentifierStart(cp)) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
428 |
|| (cp != '/' && !Character.isJavaIdentifierPart(cp))) { |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
429 |
return "\"" + addEscapes(name) + "\""; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
430 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
431 |
cc = cp; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
432 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
433 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
434 |
return name; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
435 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
436 |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
437 |
/* If name requires escapes, put them in, so it can be a string body. */ |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
438 |
private static String addEscapes(String name) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
439 |
String esc = "\\\"\n\t"; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
440 |
String rep = "\\\"nt"; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
441 |
StringBuilder buf = null; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
442 |
int nextk = 0; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
443 |
int len = name.length(); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
444 |
for (int k = 0; k < len; k++) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
445 |
char cp = name.charAt(k); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
446 |
int n = esc.indexOf(cp); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
447 |
if (n >= 0) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
448 |
if (buf == null) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
449 |
buf = new StringBuilder(len * 2); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
450 |
if (nextk < k) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
451 |
buf.append(name, nextk, k); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
452 |
buf.append('\\'); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
453 |
buf.append(rep.charAt(n)); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
454 |
nextk = k+1; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
455 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
456 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
457 |
if (buf == null) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
458 |
return name; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
459 |
if (nextk < len) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
460 |
buf.append(name, nextk, len); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
461 |
return buf.toString(); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
462 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
463 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
464 |
private ClassWriter classWriter; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
465 |
private Options options; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
466 |
} |