author | sundar |
Tue, 20 Feb 2018 15:25:40 +0530 | |
changeset 48917 | 37beaca49e63 |
parent 47875 | 93bba74ed8a3 |
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.Annotation; |
15385 | 29 |
import com.sun.tools.classfile.TypeAnnotation; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
30 |
import com.sun.tools.classfile.Annotation.Annotation_element_value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
31 |
import com.sun.tools.classfile.Annotation.Array_element_value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
32 |
import com.sun.tools.classfile.Annotation.Class_element_value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.classfile.Annotation.Enum_element_value; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.Annotation.Primitive_element_value; |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
35 |
import com.sun.tools.classfile.ConstantPool; |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
36 |
import com.sun.tools.classfile.ConstantPoolException; |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
37 |
import com.sun.tools.classfile.Descriptor; |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
38 |
import com.sun.tools.classfile.Descriptor.InvalidDescriptor; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
39 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
40 |
/** |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
41 |
* A writer for writing annotations as text. |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
42 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
43 |
* <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
|
44 |
* 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
|
45 |
* 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
|
46 |
* deletion without notice.</b> |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
47 |
*/ |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
48 |
public class AnnotationWriter extends BasicWriter { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
49 |
static AnnotationWriter instance(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
50 |
AnnotationWriter instance = context.get(AnnotationWriter.class); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
51 |
if (instance == null) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
52 |
instance = new AnnotationWriter(context); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
53 |
return instance; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
54 |
} |
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 |
protected AnnotationWriter(Context context) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
57 |
super(context); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
58 |
classWriter = ClassWriter.instance(context); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
59 |
constantWriter = ConstantWriter.instance(context); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
60 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
61 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
62 |
public void write(Annotation annot) { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
63 |
write(annot, false); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
64 |
println(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
65 |
indent(+1); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
66 |
write(annot, true); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
67 |
indent(-1); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
68 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
69 |
|
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
70 |
public void write(Annotation annot, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
71 |
writeDescriptor(annot.type_index, resolveIndices); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
72 |
if (resolveIndices) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
73 |
boolean showParens = annot.num_element_value_pairs > 0; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
74 |
if (showParens) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
75 |
println("("); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
76 |
indent(+1); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
77 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
78 |
for (int i = 0; i < annot.num_element_value_pairs; i++) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
79 |
write(annot.element_value_pairs[i], true); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
80 |
println(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
81 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
82 |
if (showParens) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
83 |
indent(-1); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
84 |
print(")"); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
85 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
86 |
} else { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
87 |
print("("); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
88 |
for (int i = 0; i < annot.num_element_value_pairs; i++) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
89 |
if (i > 0) |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
90 |
print(","); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
91 |
write(annot.element_value_pairs[i], false); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
92 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
93 |
print(")"); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
94 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
95 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
96 |
|
15385 | 97 |
public void write(TypeAnnotation annot) { |
98 |
write(annot, true, false); |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
99 |
println(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
100 |
indent(+1); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
101 |
write(annot.annotation, true); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
102 |
indent(-1); |
15385 | 103 |
} |
104 |
||
105 |
public void write(TypeAnnotation annot, boolean showOffsets, boolean resolveIndices) { |
|
106 |
write(annot.annotation, resolveIndices); |
|
107 |
print(": "); |
|
108 |
write(annot.position, showOffsets); |
|
109 |
} |
|
110 |
||
111 |
public void write(TypeAnnotation.Position pos, boolean showOffsets) { |
|
112 |
print(pos.type); |
|
113 |
||
114 |
switch (pos.type) { |
|
115 |
// instanceof |
|
116 |
case INSTANCEOF: |
|
117 |
// new expression |
|
118 |
case NEW: |
|
15718 | 119 |
// constructor/method reference receiver |
120 |
case CONSTRUCTOR_REFERENCE: |
|
121 |
case METHOD_REFERENCE: |
|
15385 | 122 |
if (showOffsets) { |
123 |
print(", offset="); |
|
124 |
print(pos.offset); |
|
125 |
} |
|
126 |
break; |
|
127 |
// local variable |
|
128 |
case LOCAL_VARIABLE: |
|
129 |
// resource variable |
|
130 |
case RESOURCE_VARIABLE: |
|
131 |
if (pos.lvarOffset == null) { |
|
132 |
print(", lvarOffset is Null!"); |
|
133 |
break; |
|
134 |
} |
|
135 |
print(", {"); |
|
136 |
for (int i = 0; i < pos.lvarOffset.length; ++i) { |
|
137 |
if (i != 0) print("; "); |
|
138 |
if (showOffsets) { |
|
139 |
print("start_pc="); |
|
140 |
print(pos.lvarOffset[i]); |
|
141 |
} |
|
142 |
print(", length="); |
|
143 |
print(pos.lvarLength[i]); |
|
144 |
print(", index="); |
|
145 |
print(pos.lvarIndex[i]); |
|
146 |
} |
|
147 |
print("}"); |
|
148 |
break; |
|
149 |
// exception parameter |
|
150 |
case EXCEPTION_PARAMETER: |
|
151 |
print(", exception_index="); |
|
152 |
print(pos.exception_index); |
|
153 |
break; |
|
154 |
// method receiver |
|
155 |
case METHOD_RECEIVER: |
|
156 |
// Do nothing |
|
157 |
break; |
|
158 |
// type parameter |
|
159 |
case CLASS_TYPE_PARAMETER: |
|
160 |
case METHOD_TYPE_PARAMETER: |
|
161 |
print(", param_index="); |
|
162 |
print(pos.parameter_index); |
|
163 |
break; |
|
164 |
// type parameter bound |
|
165 |
case CLASS_TYPE_PARAMETER_BOUND: |
|
166 |
case METHOD_TYPE_PARAMETER_BOUND: |
|
167 |
print(", param_index="); |
|
168 |
print(pos.parameter_index); |
|
169 |
print(", bound_index="); |
|
170 |
print(pos.bound_index); |
|
171 |
break; |
|
172 |
// class extends or implements clause |
|
173 |
case CLASS_EXTENDS: |
|
174 |
print(", type_index="); |
|
175 |
print(pos.type_index); |
|
176 |
break; |
|
177 |
// throws |
|
178 |
case THROWS: |
|
179 |
print(", type_index="); |
|
180 |
print(pos.type_index); |
|
181 |
break; |
|
182 |
// method parameter |
|
183 |
case METHOD_FORMAL_PARAMETER: |
|
184 |
print(", param_index="); |
|
185 |
print(pos.parameter_index); |
|
186 |
break; |
|
15718 | 187 |
// type cast |
188 |
case CAST: |
|
15385 | 189 |
// method/constructor/reference type argument |
190 |
case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: |
|
191 |
case METHOD_INVOCATION_TYPE_ARGUMENT: |
|
15718 | 192 |
case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: |
15385 | 193 |
case METHOD_REFERENCE_TYPE_ARGUMENT: |
194 |
if (showOffsets) { |
|
195 |
print(", offset="); |
|
196 |
print(pos.offset); |
|
197 |
} |
|
198 |
print(", type_index="); |
|
199 |
print(pos.type_index); |
|
200 |
break; |
|
201 |
// We don't need to worry about these |
|
202 |
case METHOD_RETURN: |
|
203 |
case FIELD: |
|
204 |
break; |
|
205 |
case UNKNOWN: |
|
206 |
throw new AssertionError("AnnotationWriter: UNKNOWN target type should never occur!"); |
|
207 |
default: |
|
208 |
throw new AssertionError("AnnotationWriter: Unknown target type for position: " + pos); |
|
209 |
} |
|
210 |
||
211 |
// Append location data for generics/arrays. |
|
212 |
if (!pos.location.isEmpty()) { |
|
213 |
print(", location="); |
|
214 |
print(pos.location); |
|
215 |
} |
|
216 |
} |
|
217 |
||
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
218 |
public void write(Annotation.element_value_pair pair, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
219 |
writeIndex(pair.element_name_index, resolveIndices); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
220 |
print("="); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
221 |
write(pair.value, resolveIndices); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
222 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
223 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
224 |
public void write(Annotation.element_value value) { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
225 |
write(value, false); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
226 |
println(); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
227 |
indent(+1); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
228 |
write(value, true); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
229 |
indent(-1); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
230 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
231 |
|
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
232 |
public void write(Annotation.element_value value, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
233 |
ev_writer.write(value, resolveIndices); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
234 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
235 |
|
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
236 |
private void writeDescriptor(int index, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
237 |
if (resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
238 |
try { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
239 |
ConstantPool constant_pool = classWriter.getClassFile().constant_pool; |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
240 |
Descriptor d = new Descriptor(index); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
241 |
print(d.getFieldType(constant_pool)); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
242 |
return; |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
15718
diff
changeset
|
243 |
} catch (ConstantPoolException | InvalidDescriptor ignore) { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
244 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
245 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
246 |
|
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
247 |
print("#" + index); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
248 |
} |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
249 |
|
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
250 |
private void writeIndex(int index, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
251 |
if (resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
252 |
print(constantWriter.stringValue(index)); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
253 |
} else |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
254 |
print("#" + index); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
255 |
} |
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 |
element_value_Writer ev_writer = new element_value_Writer(); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
258 |
|
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
259 |
class element_value_Writer implements Annotation.element_value.Visitor<Void,Boolean> { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
260 |
public void write(Annotation.element_value value, boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
261 |
value.accept(this, resolveIndices); |
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 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
264 |
@Override |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
265 |
public Void visitPrimitive(Primitive_element_value ev, Boolean resolveIndices) { |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
266 |
if (resolveIndices) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
267 |
int index = ev.const_value_index; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
268 |
switch (ev.tag) { |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
269 |
case 'B': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
270 |
print("(byte) "); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
271 |
print(constantWriter.stringValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
272 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
273 |
case 'C': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
274 |
print("'"); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
275 |
print(constantWriter.charValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
276 |
print("'"); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
277 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
278 |
case 'D': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
279 |
case 'F': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
280 |
case 'I': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
281 |
case 'J': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
282 |
print(constantWriter.stringValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
283 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
284 |
case 'S': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
285 |
print("(short) "); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
286 |
print(constantWriter.stringValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
287 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
288 |
case 'Z': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
289 |
print(constantWriter.booleanValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
290 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
291 |
case 's': |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
292 |
print("\""); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
293 |
print(constantWriter.stringValue(index)); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
294 |
print("\""); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
295 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
296 |
default: |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
297 |
print(((char) ev.tag) + "#" + ev.const_value_index); |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
298 |
break; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
299 |
} |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
300 |
} else { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
301 |
print(((char) ev.tag) + "#" + ev.const_value_index); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
302 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
303 |
return null; |
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 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
306 |
@Override |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
307 |
public Void visitEnum(Enum_element_value ev, Boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
308 |
if (resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
309 |
writeIndex(ev.type_name_index, resolveIndices); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
310 |
print("."); |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
311 |
writeIndex(ev.const_name_index, resolveIndices); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
312 |
} else { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
313 |
print(((char) ev.tag) + "#" + ev.type_name_index + ".#" + ev.const_name_index); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
314 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
315 |
return null; |
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 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
318 |
@Override |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
319 |
public Void visitClass(Class_element_value ev, Boolean resolveIndices) { |
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
320 |
if (resolveIndices) { |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
321 |
print("class "); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
322 |
writeIndex(ev.class_info_index, resolveIndices); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
323 |
} else { |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
324 |
print(((char) ev.tag) + "#" + ev.class_info_index); |
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
325 |
} |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
326 |
return null; |
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 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
329 |
@Override |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
330 |
public Void visitAnnotation(Annotation_element_value ev, Boolean resolveIndices) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
331 |
print((char) ev.tag); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
332 |
AnnotationWriter.this.write(ev.annotation_value, resolveIndices); |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
333 |
return null; |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
334 |
} |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
335 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
336 |
@Override |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
337 |
public Void visitArray(Array_element_value ev, Boolean resolveIndices) { |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
338 |
print("["); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
339 |
for (int i = 0; i < ev.num_values; i++) { |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
340 |
if (i > 0) |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
341 |
print(","); |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
342 |
write(ev.values[i], resolveIndices); |
727
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 |
print("]"); |
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
345 |
return null; |
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 |
|
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
348 |
} |
3536
dee1b5833af7
6855990: javap InstructionDetailWriter should support new 308 annotations attribute
jjg
parents:
3149
diff
changeset
|
349 |
|
47875
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
350 |
private final ClassWriter classWriter; |
93bba74ed8a3
8156694: javap should render annotations in a friendly way
jjg
parents:
47216
diff
changeset
|
351 |
private final ConstantWriter constantWriter; |
727
cb50c1ae7bab
4075303: Use javap to enquire aboput a specific inner class
jjg
parents:
diff
changeset
|
352 |
} |