author | sundar |
Tue, 20 Feb 2018 15:25:40 +0530 | |
changeset 48917 | 37beaca49e63 |
parent 48826 | c4d9d1b08e2e |
permissions | -rw-r--r-- |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
1 |
/* |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2007, 2017, 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 |
||
48826 | 107 |
public Integer visitDynamicConstant(CONSTANT_Dynamic_info info, Void p) { |
108 |
print("#" + info.bootstrap_method_attr_index + ":#" + info.name_and_type_index); |
|
109 |
tab(); |
|
110 |
println("// " + stringValue(info)); |
|
111 |
return 1; |
|
112 |
} |
|
113 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
114 |
public Integer visitLong(CONSTANT_Long_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
115 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
116 |
return 2; |
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) { |
39104
61c5b5f8fd8c
8059631: Use of '#' to represent MethodHandle kind is confusing
jjg
parents:
30846
diff
changeset
|
127 |
print(info.reference_kind.tag + ":#" + info.reference_index); |
8042 | 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 |
||
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
140 |
public Integer visitModule(CONSTANT_Module_info info, Void p) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
141 |
print("#" + info.name_index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
142 |
tab(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
143 |
println("// " + stringValue(info)); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
144 |
return 1; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
145 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
146 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
147 |
public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
148 |
print("#" + info.name_index + ":#" + info.type_index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
149 |
tab(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
150 |
println("// " + stringValue(info)); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
151 |
return 1; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
152 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
153 |
|
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
154 |
public Integer visitPackage(CONSTANT_Package_info info, Void p) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
155 |
print("#" + info.name_index); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
156 |
tab(); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
157 |
println("// " + stringValue(info)); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
158 |
return 1; |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
159 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
160 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
161 |
public Integer visitString(CONSTANT_String_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
162 |
print("#" + info.string_index); |
3546 | 163 |
tab(); |
23120
6e12870d6652
8035364: An extra space in the comments of constant pool entries
jjg
parents:
8042
diff
changeset
|
164 |
println("// " + stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
165 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
166 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
167 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
168 |
public Integer visitUtf8(CONSTANT_Utf8_info info, Void p) { |
3552
a4b8b89bdc9c
6868548: remove spurious ';' from after constant pool entries
jjg
parents:
3546
diff
changeset
|
169 |
println(stringValue(info)); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
170 |
return 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
171 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
172 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
173 |
}; |
3546 | 174 |
println("Constant pool:"); |
175 |
indent(+1); |
|
176 |
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
|
177 |
int cpx = 1; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
178 |
while (cpx < constant_pool.size()) { |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
179 |
print(String.format("%" + width + "s", ("#" + cpx))); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
180 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
181 |
CPInfo cpInfo = constant_pool.get(cpx); |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
182 |
print(String.format(" = %-18s ", cpTagName(cpInfo))); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
183 |
cpx += cpInfo.accept(v, null); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
184 |
} catch (ConstantPool.InvalidIndex ex) { |
3546 | 185 |
// should not happen |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
186 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
187 |
} |
3546 | 188 |
indent(-1); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
189 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
190 |
|
3141
79c119fae7fb
6852856: javap changes to facilitate subclassing javap for variants
jjg
parents:
2723
diff
changeset
|
191 |
protected void write(int cpx) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
192 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
193 |
if (cpx == 0) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
194 |
print("#0"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
195 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
196 |
} |
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 |
CPInfo cpInfo; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
199 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
200 |
cpInfo = classFile.constant_pool.get(cpx); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
201 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
202 |
print("#" + cpx); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
203 |
return; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
204 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
205 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
206 |
int tag = cpInfo.getTag(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
207 |
switch (tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
208 |
case CONSTANT_Methodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
209 |
case CONSTANT_InterfaceMethodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
210 |
case CONSTANT_Fieldref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
211 |
// simplify references within this class |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
212 |
CPRefInfo ref = (CPRefInfo) cpInfo; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
213 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
214 |
if (ref.class_index == classFile.this_class) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
215 |
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
|
216 |
} catch (ConstantPool.InvalidIndex e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
217 |
// ignore, for now |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
218 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
219 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
220 |
print(tagName(tag) + " " + stringValue(cpInfo)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
221 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
222 |
|
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
223 |
String cpTagName(CPInfo cpInfo) { |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
224 |
String n = cpInfo.getClass().getSimpleName(); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
225 |
return n.replace("CONSTANT_", "").replace("_info", ""); |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
226 |
} |
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
227 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
228 |
String tagName(int tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
229 |
switch (tag) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
230 |
case CONSTANT_Utf8: |
3553
5daeeb71ee78
6868539: javap should use current names for constant pool tags
jjg
parents:
3552
diff
changeset
|
231 |
return "Utf8"; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
232 |
case CONSTANT_Integer: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
233 |
return "int"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
234 |
case CONSTANT_Float: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
235 |
return "float"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
236 |
case CONSTANT_Long: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
237 |
return "long"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
238 |
case CONSTANT_Double: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
239 |
return "double"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
240 |
case CONSTANT_Class: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
241 |
return "class"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
242 |
case CONSTANT_String: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
243 |
return "String"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
244 |
case CONSTANT_Fieldref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
245 |
return "Field"; |
8042 | 246 |
case CONSTANT_MethodHandle: |
247 |
return "MethodHandle"; |
|
248 |
case CONSTANT_MethodType: |
|
249 |
return "MethodType"; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
250 |
case CONSTANT_Methodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
251 |
return "Method"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
252 |
case CONSTANT_InterfaceMethodref: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
253 |
return "InterfaceMethod"; |
8042 | 254 |
case CONSTANT_InvokeDynamic: |
255 |
return "InvokeDynamic"; |
|
48826 | 256 |
case CONSTANT_Dynamic: |
257 |
return "Dynamic"; |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
258 |
case CONSTANT_NameAndType: |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
259 |
return "NameAndType"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
260 |
default: |
8042 | 261 |
return "(unknown tag " + tag + ")"; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
262 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
263 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
264 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
265 |
String booleanValue(int constant_pool_index) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
266 |
ClassFile classFile = classWriter.getClassFile(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
267 |
try { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
268 |
CPInfo info = classFile.constant_pool.get(constant_pool_index); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
269 |
if (info instanceof CONSTANT_Integer_info) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
270 |
int value = ((CONSTANT_Integer_info) info).value; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
271 |
switch (value) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
272 |
case 0: return "false"; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
273 |
case 1: return "true"; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
274 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
275 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
276 |
return "#" + constant_pool_index; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
277 |
} catch (ConstantPool.InvalidIndex e) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
278 |
return report(e); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
279 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
280 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
281 |
|
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
282 |
String charValue(int constant_pool_index) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
283 |
ClassFile classFile = classWriter.getClassFile(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
284 |
try { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
285 |
CPInfo info = classFile.constant_pool.get(constant_pool_index); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
286 |
if (info instanceof CONSTANT_Integer_info) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
287 |
int value = ((CONSTANT_Integer_info) info).value; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
288 |
return String.valueOf((char) value); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
289 |
} else { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
290 |
return "#" + constant_pool_index; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
291 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
292 |
} catch (ConstantPool.InvalidIndex e) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
293 |
return report(e); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
294 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
295 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
296 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
297 |
String stringValue(int constant_pool_index) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
298 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
299 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
300 |
return stringValue(classFile.constant_pool.get(constant_pool_index)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
301 |
} catch (ConstantPool.InvalidIndex e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
302 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
303 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
304 |
} |
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 |
String stringValue(CPInfo cpInfo) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
307 |
return stringValueVisitor.visit(cpInfo); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
308 |
} |
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 |
StringValueVisitor stringValueVisitor = new StringValueVisitor(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
311 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
312 |
private class StringValueVisitor implements ConstantPool.Visitor<String, Void> { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
313 |
public String visit(CPInfo info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
314 |
return info.accept(this, null); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
315 |
} |
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 |
public String visitClass(CONSTANT_Class_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
318 |
return getCheckedName(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
319 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
320 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
321 |
String getCheckedName(CONSTANT_Class_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
322 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
323 |
return checkName(info.getName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
324 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
325 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
326 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
327 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
328 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
329 |
public String visitDouble(CONSTANT_Double_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
330 |
return info.value + "d"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
331 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
332 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
333 |
public String visitFieldref(CONSTANT_Fieldref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
334 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
335 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
336 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
337 |
public String visitFloat(CONSTANT_Float_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
338 |
return info.value + "f"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
339 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
340 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
341 |
public String visitInteger(CONSTANT_Integer_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
342 |
return String.valueOf(info.value); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
343 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
344 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
345 |
public String visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
346 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
347 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
348 |
|
8042 | 349 |
public String visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { |
350 |
try { |
|
351 |
String callee = stringValue(info.getNameAndTypeInfo()); |
|
352 |
return "#" + info.bootstrap_method_attr_index + ":" + callee; |
|
353 |
} catch (ConstantPoolException e) { |
|
354 |
return report(e); |
|
355 |
} |
|
356 |
} |
|
357 |
||
48826 | 358 |
public String visitDynamicConstant(CONSTANT_Dynamic_info info, Void p) { |
359 |
try { |
|
360 |
String callee = stringValue(info.getNameAndTypeInfo()); |
|
361 |
return "#" + info.bootstrap_method_attr_index + ":" + callee; |
|
362 |
} catch (ConstantPoolException e) { |
|
363 |
return report(e); |
|
364 |
} |
|
365 |
} |
|
366 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
367 |
public String visitLong(CONSTANT_Long_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
368 |
return info.value + "l"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
369 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
370 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
371 |
public String visitModule(CONSTANT_Module_info info, Void p) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
372 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
373 |
return checkName(info.getName()); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
374 |
} catch (ConstantPoolException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
375 |
return report(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
376 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
377 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
378 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
379 |
public String visitNameAndType(CONSTANT_NameAndType_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
380 |
return getCheckedName(info) + ":" + getType(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
381 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
382 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
383 |
String getCheckedName(CONSTANT_NameAndType_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
384 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
385 |
return checkName(info.getName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
386 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
387 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
388 |
} |
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 |
|
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
391 |
public String visitPackage(CONSTANT_Package_info info, Void p) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
392 |
try { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
393 |
return checkName(info.getName()); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
394 |
} catch (ConstantPoolException e) { |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
395 |
return report(e); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
396 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
397 |
} |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
39919
diff
changeset
|
398 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
399 |
String getType(CONSTANT_NameAndType_info info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
400 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
401 |
return info.getType(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
402 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
403 |
return report(e); |
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 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
406 |
|
8042 | 407 |
public String visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { |
408 |
try { |
|
39104
61c5b5f8fd8c
8059631: Use of '#' to represent MethodHandle kind is confusing
jjg
parents:
30846
diff
changeset
|
409 |
return info.reference_kind + " " + stringValue(info.getCPRefInfo()); |
8042 | 410 |
} catch (ConstantPoolException e) { |
411 |
return report(e); |
|
412 |
} |
|
413 |
} |
|
414 |
||
415 |
public String visitMethodType(CONSTANT_MethodType_info info, Void p) { |
|
416 |
try { |
|
417 |
return info.getType(); |
|
418 |
} catch (ConstantPoolException e) { |
|
419 |
return report(e); |
|
420 |
} |
|
421 |
} |
|
422 |
||
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
423 |
public String visitMethodref(CONSTANT_Methodref_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
424 |
return visitRef(info, p); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
425 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
426 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
427 |
public String visitString(CONSTANT_String_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
428 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
429 |
ClassFile classFile = classWriter.getClassFile(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
430 |
int string_index = info.string_index; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
431 |
return stringValue(classFile.constant_pool.getUTF8Info(string_index)); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
432 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
433 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
434 |
} |
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 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
437 |
public String visitUtf8(CONSTANT_Utf8_info info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
438 |
String s = info.value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
439 |
StringBuilder sb = new StringBuilder(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
440 |
for (int i = 0; i < s.length(); i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
441 |
char c = s.charAt(i); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
442 |
switch (c) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
443 |
case '\t': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
444 |
sb.append('\\').append('t'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
445 |
break; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
446 |
case '\n': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
447 |
sb.append('\\').append('n'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
448 |
break; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
449 |
case '\r': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
450 |
sb.append('\\').append('r'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
451 |
break; |
26390
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
452 |
case '\b': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
453 |
sb.append('\\').append('b'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
454 |
break; |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
455 |
case '\f': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
456 |
sb.append('\\').append('f'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
457 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
458 |
case '\"': |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
459 |
sb.append('\\').append('\"'); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
460 |
break; |
26390
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
461 |
case '\'': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
462 |
sb.append('\\').append('\''); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
463 |
break; |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
464 |
case '\\': |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
465 |
sb.append('\\').append('\\'); |
1d0902fe3ca0
8038414: Constant pool's strings are not escaped properly
jjg
parents:
25874
diff
changeset
|
466 |
break; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
467 |
default: |
39919
3d3573afc062
8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents:
39104
diff
changeset
|
468 |
if (Character.isISOControl(c)) { |
3d3573afc062
8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents:
39104
diff
changeset
|
469 |
sb.append(String.format("\\u%04x", (int) c)); |
3d3573afc062
8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents:
39104
diff
changeset
|
470 |
break; |
3d3573afc062
8143366: Control characters in constant pool strings are not escaped properly
sdrach
parents:
39104
diff
changeset
|
471 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
472 |
sb.append(c); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
473 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
474 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
475 |
return sb.toString(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
476 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
477 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
478 |
String visitRef(CPRefInfo info, Void p) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
479 |
String cn = getCheckedClassName(info); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
480 |
String nat; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
481 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
482 |
nat = stringValue(info.getNameAndTypeInfo()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
483 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
484 |
nat = report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
485 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
486 |
return cn + "." + nat; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
487 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
488 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
489 |
String getCheckedClassName(CPRefInfo info) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
490 |
try { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
491 |
return checkName(info.getClassName()); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
492 |
} catch (ConstantPoolException e) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
493 |
return report(e); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
494 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
495 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
496 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
497 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
498 |
/* 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
|
499 |
private static String checkName(String name) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
500 |
if (name == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
501 |
return "null"; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
502 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
503 |
int len = name.length(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
504 |
if (len == 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
505 |
return "\"\""; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
506 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
507 |
int cc = '/'; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
508 |
int cp; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
509 |
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
|
510 |
cp = name.codePointAt(k); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
511 |
if ((cc == '/' && !Character.isJavaIdentifierStart(cp)) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
512 |
|| (cp != '/' && !Character.isJavaIdentifierPart(cp))) { |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
513 |
return "\"" + addEscapes(name) + "\""; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
514 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
515 |
cc = cp; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
516 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
517 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
518 |
return name; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
519 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
520 |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
521 |
/* 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
|
522 |
private static String addEscapes(String name) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
523 |
String esc = "\\\"\n\t"; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
524 |
String rep = "\\\"nt"; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
525 |
StringBuilder buf = null; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
526 |
int nextk = 0; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
527 |
int len = name.length(); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
528 |
for (int k = 0; k < len; k++) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
529 |
char cp = name.charAt(k); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
530 |
int n = esc.indexOf(cp); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
531 |
if (n >= 0) { |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
532 |
if (buf == null) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
533 |
buf = new StringBuilder(len * 2); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
534 |
if (nextk < k) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
535 |
buf.append(name, nextk, k); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
536 |
buf.append('\\'); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
537 |
buf.append(rep.charAt(n)); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
538 |
nextk = k+1; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
539 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
540 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
541 |
if (buf == null) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
542 |
return name; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
543 |
if (nextk < len) |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
544 |
buf.append(name, nextk, len); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
545 |
return buf.toString(); |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
546 |
} |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
735
diff
changeset
|
547 |
|
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
548 |
private ClassWriter classWriter; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
549 |
private Options options; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
550 |
} |