1 /* |
1 /* |
2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javap; |
26 package com.sun.tools.javap; |
27 |
27 |
28 import com.sun.tools.classfile.Annotation; |
28 import com.sun.tools.classfile.Annotation; |
29 import com.sun.tools.classfile.ExtendedAnnotation; |
|
30 import com.sun.tools.classfile.Annotation.Annotation_element_value; |
29 import com.sun.tools.classfile.Annotation.Annotation_element_value; |
31 import com.sun.tools.classfile.Annotation.Array_element_value; |
30 import com.sun.tools.classfile.Annotation.Array_element_value; |
32 import com.sun.tools.classfile.Annotation.Class_element_value; |
31 import com.sun.tools.classfile.Annotation.Class_element_value; |
33 import com.sun.tools.classfile.Annotation.Enum_element_value; |
32 import com.sun.tools.classfile.Annotation.Enum_element_value; |
34 import com.sun.tools.classfile.Annotation.Primitive_element_value; |
33 import com.sun.tools.classfile.Annotation.Primitive_element_value; |
73 print(","); |
72 print(","); |
74 write(annot.element_value_pairs[i], resolveIndices); |
73 write(annot.element_value_pairs[i], resolveIndices); |
75 } |
74 } |
76 if (showParens) |
75 if (showParens) |
77 print(")"); |
76 print(")"); |
78 } |
|
79 |
|
80 public void write(ExtendedAnnotation annot) { |
|
81 write(annot, true, false); |
|
82 } |
|
83 |
|
84 public void write(ExtendedAnnotation annot, boolean showOffsets, boolean resolveIndices) { |
|
85 write(annot.annotation, resolveIndices); |
|
86 print(": "); |
|
87 write(annot.position, showOffsets); |
|
88 } |
|
89 |
|
90 public void write(ExtendedAnnotation.Position pos, boolean showOffsets) { |
|
91 print(pos.type); |
|
92 |
|
93 switch (pos.type) { |
|
94 // type case |
|
95 case TYPECAST: |
|
96 case TYPECAST_GENERIC_OR_ARRAY: |
|
97 // object creation |
|
98 case INSTANCEOF: |
|
99 case INSTANCEOF_GENERIC_OR_ARRAY: |
|
100 // new expression |
|
101 case NEW: |
|
102 case NEW_GENERIC_OR_ARRAY: |
|
103 case NEW_TYPE_ARGUMENT: |
|
104 case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
105 if (showOffsets) { |
|
106 print(", offset="); |
|
107 print(pos.offset); |
|
108 } |
|
109 break; |
|
110 // local variable |
|
111 case LOCAL_VARIABLE: |
|
112 case LOCAL_VARIABLE_GENERIC_OR_ARRAY: |
|
113 print(", {"); |
|
114 for (int i = 0; i < pos.lvarOffset.length; ++i) { |
|
115 if (i != 0) print("; "); |
|
116 if (showOffsets) { |
|
117 print(", start_pc="); |
|
118 print(pos.lvarOffset[i]); |
|
119 } |
|
120 print(", length="); |
|
121 print(pos.lvarLength[i]); |
|
122 print(", index="); |
|
123 print(pos.lvarIndex[i]); |
|
124 } |
|
125 print("}"); |
|
126 break; |
|
127 // method receiver |
|
128 case METHOD_RECEIVER: |
|
129 // Do nothing |
|
130 break; |
|
131 // type parameters |
|
132 case CLASS_TYPE_PARAMETER: |
|
133 case METHOD_TYPE_PARAMETER: |
|
134 print(", param_index="); |
|
135 print(pos.parameter_index); |
|
136 break; |
|
137 // type parameters bound |
|
138 case CLASS_TYPE_PARAMETER_BOUND: |
|
139 case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
140 case METHOD_TYPE_PARAMETER_BOUND: |
|
141 case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
142 print(", param_index="); |
|
143 print(pos.parameter_index); |
|
144 print(", bound_index="); |
|
145 print(pos.bound_index); |
|
146 break; |
|
147 // wildcard |
|
148 case WILDCARD_BOUND: |
|
149 case WILDCARD_BOUND_GENERIC_OR_ARRAY: |
|
150 print(", wild_card="); |
|
151 print(pos.wildcard_position); |
|
152 break; |
|
153 // Class extends and implements clauses |
|
154 case CLASS_EXTENDS: |
|
155 case CLASS_EXTENDS_GENERIC_OR_ARRAY: |
|
156 print(", type_index="); |
|
157 print(pos.type_index); |
|
158 break; |
|
159 // throws |
|
160 case THROWS: |
|
161 print(", type_index="); |
|
162 print(pos.type_index); |
|
163 break; |
|
164 case CLASS_LITERAL: |
|
165 case CLASS_LITERAL_GENERIC_OR_ARRAY: |
|
166 if (showOffsets) { |
|
167 print(", offset="); |
|
168 print(pos.offset); |
|
169 } |
|
170 break; |
|
171 // method parameter: not specified |
|
172 case METHOD_PARAMETER_GENERIC_OR_ARRAY: |
|
173 print(", param_index="); |
|
174 print(pos.parameter_index); |
|
175 break; |
|
176 // method type argument: wasn't specified |
|
177 case METHOD_TYPE_ARGUMENT: |
|
178 case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
179 if (showOffsets) { |
|
180 print(", offset="); |
|
181 print(pos.offset); |
|
182 } |
|
183 print(", type_index="); |
|
184 print(pos.type_index); |
|
185 break; |
|
186 // We don't need to worry abut these |
|
187 case METHOD_RETURN_GENERIC_OR_ARRAY: |
|
188 case FIELD_GENERIC_OR_ARRAY: |
|
189 break; |
|
190 case UNKNOWN: |
|
191 break; |
|
192 default: |
|
193 throw new AssertionError("unknown type: " + pos.type); |
|
194 } |
|
195 |
|
196 // Append location data for generics/arrays. |
|
197 if (pos.type.hasLocation()) { |
|
198 print(", location="); |
|
199 print(pos.location); |
|
200 } |
|
201 } |
77 } |
202 |
78 |
203 public void write(Annotation.element_value_pair pair) { |
79 public void write(Annotation.element_value_pair pair) { |
204 write(pair, false); |
80 write(pair, false); |
205 } |
81 } |