93 * used only in ASMifierMethodVisitor.
94 */
95 protected Map<Label, String> labelNames;
96
97 /**
98 * Pseudo access flag used to distinguish class access flags.
99 */
100 private static final int ACCESS_CLASS = 262144;
101
102 /**
103 * Pseudo access flag used to distinguish field access flags.
104 */
105 private static final int ACCESS_FIELD = 524288;
106
107 /**
108 * Pseudo access flag used to distinguish inner class flags.
109 */
110 private static final int ACCESS_INNER = 1048576;
111
112 /**
113 * Constructs a new {@link ASMifier}. <i>Subclasses must not use this
114 * constructor</i>. Instead, they must use the
115 * {@link #ASMifier(int, String, int)} version.
116 *
117 * @throws IllegalStateException
118 * If a subclass calls this constructor.
119 */
120 public ASMifier() {
121 this(Opcodes.ASM5, "cw", 0);
122 if (getClass() != ASMifier.class) {
123 throw new IllegalStateException();
124 }
125 }
126
127 /**
128 * Constructs a new {@link ASMifier}.
129 *
130 * @param api
131 * the ASM API version implemented by this class. Must be one of
132 * {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
133 * @param name
134 * the name of the visitor variable in the produced code.
135 * @param id
136 * identifier of the annotation visitor variable in the produced
137 * code.
138 */
139 protected ASMifier(final int api, final String name, final int id) {
140 super(api);
141 this.name = name;
142 this.id = id;
143 }
144
145 /**
146 * Prints the ASM source code to generate the given class to the standard
147 * output.
148 * <p>
149 * Usage: ASMifier [-debug] <binary class name or class file name>
150 *
151 * @param args
152 * the command line arguments.
179 ClassReader cr;
180 if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
181 || args[i].indexOf('/') > -1) {
182 cr = new ClassReader(new FileInputStream(args[i]));
183 } else {
184 cr = new ClassReader(args[i]);
185 }
186 cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
187 System.out)), flags);
188 }
189
190 // ------------------------------------------------------------------------
191 // Classes
192 // ------------------------------------------------------------------------
193
194 @Override
195 public void visit(final int version, final int access, final String name,
196 final String signature, final String superName,
197 final String[] interfaces) {
198 String simpleName;
199 int n = name.lastIndexOf('/');
200 if (n == -1) {
201 simpleName = name;
202 } else {
203 text.add("package asm." + name.substring(0, n).replace('/', '.')
204 + ";\n");
205 simpleName = name.substring(n + 1);
206 }
207 text.add("import java.util.*;\n");
208 text.add("import jdk.internal.org.objectweb.asm.*;\n");
209 text.add("public class " + simpleName + "Dump implements Opcodes {\n\n");
210 text.add("public static byte[] dump () throws Exception {\n\n");
211 text.add("ClassWriter cw = new ClassWriter(0);\n");
212 text.add("FieldVisitor fv;\n");
213 text.add("MethodVisitor mv;\n");
214 text.add("AnnotationVisitor av0;\n\n");
215
216 buf.setLength(0);
217 buf.append("cw.visit(");
218 switch (version) {
219 case Opcodes.V1_1:
220 buf.append("V1_1");
221 break;
222 case Opcodes.V1_2:
223 buf.append("V1_2");
224 break;
225 case Opcodes.V1_3:
226 buf.append("V1_3");
227 break;
228 case Opcodes.V1_4:
229 buf.append("V1_4");
230 break;
231 case Opcodes.V1_5:
232 buf.append("V1_5");
233 break;
234 case Opcodes.V1_6:
235 buf.append("V1_6");
236 break;
237 case Opcodes.V1_7:
238 buf.append("V1_7");
239 break;
240 default:
241 buf.append(version);
242 break;
243 }
244 buf.append(", ");
245 appendAccess(access | ACCESS_CLASS);
246 buf.append(", ");
247 appendConstant(name);
248 buf.append(", ");
249 appendConstant(signature);
250 buf.append(", ");
251 appendConstant(superName);
252 buf.append(", ");
253 if (interfaces != null && interfaces.length > 0) {
254 buf.append("new String[] {");
255 for (int i = 0; i < interfaces.length; ++i) {
256 buf.append(i == 0 ? " " : ", ");
257 appendConstant(interfaces[i]);
258 }
259 buf.append(" }");
260 } else {
261 buf.append("null");
262 }
263 buf.append(");\n\n");
264 text.add(buf.toString());
265 }
266
267 @Override
268 public void visitSource(final String file, final String debug) {
269 buf.setLength(0);
270 buf.append("cw.visitSource(");
271 appendConstant(file);
272 buf.append(", ");
273 appendConstant(debug);
274 buf.append(");\n\n");
275 text.add(buf.toString());
276 }
277
278 @Override
279 public void visitOuterClass(final String owner, final String name,
280 final String desc) {
281 buf.setLength(0);
282 buf.append("cw.visitOuterClass(");
283 appendConstant(owner);
284 buf.append(", ");
285 appendConstant(name);
286 buf.append(", ");
287 appendConstant(desc);
288 buf.append(");\n\n");
289 text.add(buf.toString());
290 }
291
292 @Override
293 public ASMifier visitClassAnnotation(final String desc,
294 final boolean visible) {
295 return visitAnnotation(desc, visible);
296 }
297
298 @Override
369 } else {
370 buf.append("null");
371 }
372 buf.append(");\n");
373 text.add(buf.toString());
374 ASMifier a = createASMifier("mv", 0);
375 text.add(a.getText());
376 text.add("}\n");
377 return a;
378 }
379
380 @Override
381 public void visitClassEnd() {
382 text.add("cw.visitEnd();\n\n");
383 text.add("return cw.toByteArray();\n");
384 text.add("}\n");
385 text.add("}\n");
386 }
387
388 // ------------------------------------------------------------------------
389 // Annotations
390 // ------------------------------------------------------------------------
391
392 @Override
393 public void visit(final String name, final Object value) {
394 buf.setLength(0);
395 buf.append("av").append(id).append(".visit(");
396 appendConstant(buf, name);
397 buf.append(", ");
398 appendConstant(buf, value);
399 buf.append(");\n");
400 text.add(buf.toString());
401 }
402
403 @Override
404 public void visitEnum(final String name, final String desc,
405 final String value) {
406 buf.setLength(0);
407 buf.append("av").append(id).append(".visitEnum(");
408 appendConstant(buf, name);
955 public void visitAttribute(final Attribute attr) {
956 buf.setLength(0);
957 buf.append("// ATTRIBUTE ").append(attr.type).append('\n');
958 if (attr instanceof ASMifiable) {
959 if (labelNames == null) {
960 labelNames = new HashMap<Label, String>();
961 }
962 buf.append("{\n");
963 ((ASMifiable) attr).asmify(buf, "attr", labelNames);
964 buf.append(name).append(".visitAttribute(attr);\n");
965 buf.append("}\n");
966 }
967 text.add(buf.toString());
968 }
969
970 // ------------------------------------------------------------------------
971 // Utility methods
972 // ------------------------------------------------------------------------
973
974 protected ASMifier createASMifier(final String name, final int id) {
975 return new ASMifier(Opcodes.ASM5, name, id);
976 }
977
978 /**
979 * Appends a string representation of the given access modifiers to
980 * {@link #buf buf}.
981 *
982 * @param access
983 * some access modifiers.
984 */
985 void appendAccess(final int access) {
986 boolean first = true;
987 if ((access & Opcodes.ACC_PUBLIC) != 0) {
988 buf.append("ACC_PUBLIC");
989 first = false;
990 }
991 if ((access & Opcodes.ACC_PRIVATE) != 0) {
992 buf.append("ACC_PRIVATE");
993 first = false;
994 }
995 if ((access & Opcodes.ACC_PROTECTED) != 0) {
996 buf.append("ACC_PROTECTED");
997 first = false;
998 }
999 if ((access & Opcodes.ACC_FINAL) != 0) {
1000 if (!first) {
1001 buf.append(" + ");
1002 }
1003 buf.append("ACC_FINAL");
1004 first = false;
1005 }
1006 if ((access & Opcodes.ACC_STATIC) != 0) {
1007 if (!first) {
1008 buf.append(" + ");
1009 }
1010 buf.append("ACC_STATIC");
1011 first = false;
1012 }
1013 if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
1014 if (!first) {
1015 buf.append(" + ");
1016 }
1017 if ((access & ACCESS_CLASS) == 0) {
1018 buf.append("ACC_SYNCHRONIZED");
1019 } else {
1020 buf.append("ACC_SUPER");
1021 }
1022 first = false;
1023 }
1024 if ((access & Opcodes.ACC_VOLATILE) != 0
1025 && (access & ACCESS_FIELD) != 0) {
1026 if (!first) {
1027 buf.append(" + ");
1028 }
1029 buf.append("ACC_VOLATILE");
1030 first = false;
1031 }
1032 if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0
1033 && (access & ACCESS_FIELD) == 0) {
1034 if (!first) {
1035 buf.append(" + ");
1036 }
1037 buf.append("ACC_BRIDGE");
1038 first = false;
1039 }
1040 if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0
1041 && (access & ACCESS_FIELD) == 0) {
1042 if (!first) {
1043 buf.append(" + ");
1044 }
1045 buf.append("ACC_VARARGS");
1046 first = false;
1047 }
1048 if ((access & Opcodes.ACC_TRANSIENT) != 0
1049 && (access & ACCESS_FIELD) != 0) {
1050 if (!first) {
1051 buf.append(" + ");
1052 }
1053 buf.append("ACC_TRANSIENT");
1054 first = false;
1055 }
1056 if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0
1057 && (access & ACCESS_FIELD) == 0) {
1096 if (!first) {
1097 buf.append(" + ");
1098 }
1099 buf.append("ACC_STRICT");
1100 first = false;
1101 }
1102 if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
1103 if (!first) {
1104 buf.append(" + ");
1105 }
1106 buf.append("ACC_SYNTHETIC");
1107 first = false;
1108 }
1109 if ((access & Opcodes.ACC_DEPRECATED) != 0) {
1110 if (!first) {
1111 buf.append(" + ");
1112 }
1113 buf.append("ACC_DEPRECATED");
1114 first = false;
1115 }
1116 if ((access & Opcodes.ACC_MANDATED) != 0) {
1117 if (!first) {
1118 buf.append(" + ");
1119 }
1120 buf.append("ACC_MANDATED");
1121 first = false;
1122 }
1123 if (first) {
1124 buf.append('0');
1125 }
1126 }
1127
1128 /**
1129 * Appends a string representation of the given constant to the given
1130 * buffer.
1131 *
1132 * @param cst
1133 * an {@link Integer}, {@link Float}, {@link Long},
1134 * {@link Double} or {@link String} object. May be <tt>null</tt>.
1135 */
1136 protected void appendConstant(final Object cst) {
1137 appendConstant(buf, cst);
1138 }
1139
1140 /**
1146 * @param cst
1147 * an {@link Integer}, {@link Float}, {@link Long},
1148 * {@link Double} or {@link String} object. May be <tt>null</tt>.
1149 */
1150 static void appendConstant(final StringBuffer buf, final Object cst) {
1151 if (cst == null) {
1152 buf.append("null");
1153 } else if (cst instanceof String) {
1154 appendString(buf, (String) cst);
1155 } else if (cst instanceof Type) {
1156 buf.append("Type.getType(\"");
1157 buf.append(((Type) cst).getDescriptor());
1158 buf.append("\")");
1159 } else if (cst instanceof Handle) {
1160 buf.append("new Handle(");
1161 Handle h = (Handle) cst;
1162 buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()])
1163 .append(", \"");
1164 buf.append(h.getOwner()).append("\", \"");
1165 buf.append(h.getName()).append("\", \"");
1166 buf.append(h.getDesc()).append("\")");
1167 } else if (cst instanceof Byte) {
1168 buf.append("new Byte((byte)").append(cst).append(')');
1169 } else if (cst instanceof Boolean) {
1170 buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE"
1171 : "Boolean.FALSE");
1172 } else if (cst instanceof Short) {
1173 buf.append("new Short((short)").append(cst).append(')');
1174 } else if (cst instanceof Character) {
1175 int c = ((Character) cst).charValue();
1176 buf.append("new Character((char)").append(c).append(')');
1177 } else if (cst instanceof Integer) {
1178 buf.append("new Integer(").append(cst).append(')');
1179 } else if (cst instanceof Float) {
1180 buf.append("new Float(\"").append(cst).append("\")");
1181 } else if (cst instanceof Long) {
1182 buf.append("new Long(").append(cst).append("L)");
1183 } else if (cst instanceof Double) {
1184 buf.append("new Double(\"").append(cst).append("\")");
1185 } else if (cst instanceof byte[]) {
1186 byte[] v = (byte[]) cst;
|
93 * used only in ASMifierMethodVisitor.
94 */
95 protected Map<Label, String> labelNames;
96
97 /**
98 * Pseudo access flag used to distinguish class access flags.
99 */
100 private static final int ACCESS_CLASS = 262144;
101
102 /**
103 * Pseudo access flag used to distinguish field access flags.
104 */
105 private static final int ACCESS_FIELD = 524288;
106
107 /**
108 * Pseudo access flag used to distinguish inner class flags.
109 */
110 private static final int ACCESS_INNER = 1048576;
111
112 /**
113 * Pseudo access flag used to distinguish module requires/exports flags.
114 */
115 private static final int ACCESS_MODULE = 2097152;
116
117 /**
118 * Constructs a new {@link ASMifier}. <i>Subclasses must not use this
119 * constructor</i>. Instead, they must use the
120 * {@link #ASMifier(int, String, int)} version.
121 *
122 * @throws IllegalStateException
123 * If a subclass calls this constructor.
124 */
125 public ASMifier() {
126 this(Opcodes.ASM6, "cw", 0);
127 if (getClass() != ASMifier.class) {
128 throw new IllegalStateException();
129 }
130 }
131
132 /**
133 * Constructs a new {@link ASMifier}.
134 *
135 * @param api
136 * the ASM API version implemented by this class. Must be one of
137 * {@link Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link Opcodes#ASM6}.
138 * @param name
139 * the name of the visitor variable in the produced code.
140 * @param id
141 * identifier of the annotation visitor variable in the produced
142 * code.
143 */
144 protected ASMifier(final int api, final String name, final int id) {
145 super(api);
146 this.name = name;
147 this.id = id;
148 }
149
150 /**
151 * Prints the ASM source code to generate the given class to the standard
152 * output.
153 * <p>
154 * Usage: ASMifier [-debug] <binary class name or class file name>
155 *
156 * @param args
157 * the command line arguments.
184 ClassReader cr;
185 if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
186 || args[i].indexOf('/') > -1) {
187 cr = new ClassReader(new FileInputStream(args[i]));
188 } else {
189 cr = new ClassReader(args[i]);
190 }
191 cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
192 System.out)), flags);
193 }
194
195 // ------------------------------------------------------------------------
196 // Classes
197 // ------------------------------------------------------------------------
198
199 @Override
200 public void visit(final int version, final int access, final String name,
201 final String signature, final String superName,
202 final String[] interfaces) {
203 String simpleName;
204 if (name == null) {
205 simpleName = "module-info";
206 } else {
207 int n = name.lastIndexOf('/');
208 if (n == -1) {
209 simpleName = name;
210 } else {
211 text.add("package asm." + name.substring(0, n).replace('/', '.')
212 + ";\n");
213 simpleName = name.substring(n + 1).replace('-', '_');
214 }
215 }
216 text.add("import java.util.*;\n");
217 text.add("import jdk.internal.org.objectweb.asm.*;\n");
218 text.add("public class " + simpleName + "Dump implements Opcodes {\n\n");
219 text.add("public static byte[] dump () throws Exception {\n\n");
220 text.add("ClassWriter cw = new ClassWriter(0);\n");
221 text.add("FieldVisitor fv;\n");
222 text.add("MethodVisitor mv;\n");
223 text.add("AnnotationVisitor av0;\n\n");
224
225 buf.setLength(0);
226 buf.append("cw.visit(");
227 switch (version) {
228 case Opcodes.V1_1:
229 buf.append("V1_1");
230 break;
231 case Opcodes.V1_2:
232 buf.append("V1_2");
233 break;
234 case Opcodes.V1_3:
235 buf.append("V1_3");
236 break;
237 case Opcodes.V1_4:
238 buf.append("V1_4");
239 break;
240 case Opcodes.V1_5:
241 buf.append("V1_5");
242 break;
243 case Opcodes.V1_6:
244 buf.append("V1_6");
245 break;
246 case Opcodes.V1_7:
247 buf.append("V1_7");
248 break;
249 case Opcodes.V1_8:
250 buf.append("V1_8");
251 break;
252 case Opcodes.V9:
253 buf.append("V9");
254 break;
255 default:
256 buf.append(version);
257 break;
258 }
259 buf.append(", ");
260 appendAccess(access | ACCESS_CLASS);
261 buf.append(", ");
262 appendConstant(name);
263 buf.append(", ");
264 appendConstant(signature);
265 buf.append(", ");
266 appendConstant(superName);
267 buf.append(", ");
268 if (interfaces != null && interfaces.length > 0) {
269 buf.append("new String[] {");
270 for (int i = 0; i < interfaces.length; ++i) {
271 buf.append(i == 0 ? " " : ", ");
272 appendConstant(interfaces[i]);
273 }
274 buf.append(" }");
275 } else {
276 buf.append("null");
277 }
278 buf.append(");\n\n");
279 text.add(buf.toString());
280 }
281
282 @Override
283 public void visitSource(final String file, final String debug) {
284 buf.setLength(0);
285 buf.append("cw.visitSource(");
286 appendConstant(file);
287 buf.append(", ");
288 appendConstant(debug);
289 buf.append(");\n\n");
290 text.add(buf.toString());
291 }
292
293 @Override
294 public Printer visitModule(final String name, final int flags,
295 final String version) {
296 buf.setLength(0);
297 buf.append("ModuleVisitor mdv = cw.visitModule(");
298 appendConstant(name);
299 buf.append(", ");
300 appendAccess(flags | ACCESS_MODULE);
301 buf.append(", ");
302 appendConstant(version);
303 buf.append(");\n\n");
304 text.add(buf.toString());
305 ASMifier a = createASMifier("mdv", 0);
306 text.add(a.getText());
307 text.add("}\n");
308 return a;
309 }
310
311 @Override
312 public void visitOuterClass(final String owner, final String name,
313 final String desc) {
314 buf.setLength(0);
315 buf.append("cw.visitOuterClass(");
316 appendConstant(owner);
317 buf.append(", ");
318 appendConstant(name);
319 buf.append(", ");
320 appendConstant(desc);
321 buf.append(");\n\n");
322 text.add(buf.toString());
323 }
324
325 @Override
326 public ASMifier visitClassAnnotation(final String desc,
327 final boolean visible) {
328 return visitAnnotation(desc, visible);
329 }
330
331 @Override
402 } else {
403 buf.append("null");
404 }
405 buf.append(");\n");
406 text.add(buf.toString());
407 ASMifier a = createASMifier("mv", 0);
408 text.add(a.getText());
409 text.add("}\n");
410 return a;
411 }
412
413 @Override
414 public void visitClassEnd() {
415 text.add("cw.visitEnd();\n\n");
416 text.add("return cw.toByteArray();\n");
417 text.add("}\n");
418 text.add("}\n");
419 }
420
421 // ------------------------------------------------------------------------
422 // Module
423 // ------------------------------------------------------------------------
424
425 @Override
426 public void visitMainClass(String mainClass) {
427 buf.setLength(0);
428 buf.append("mdv.visitMainClass(");
429 appendConstant(buf, mainClass);
430 buf.append(");\n");
431 text.add(buf.toString());
432 }
433
434 @Override
435 public void visitPackage(String packaze) {
436 buf.setLength(0);
437 buf.append("mdv.visitPackage(");
438 appendConstant(buf, packaze);
439 buf.append(");\n");
440 text.add(buf.toString());
441 }
442
443 @Override
444 public void visitRequire(String module, int access, String version) {
445 buf.setLength(0);
446 buf.append("mdv.visitRequire(");
447 appendConstant(buf, module);
448 buf.append(", ");
449 appendAccess(access | ACCESS_MODULE);
450 buf.append(", ");
451 appendConstant(buf, version);
452 buf.append(");\n");
453 text.add(buf.toString());
454 }
455
456 @Override
457 public void visitExport(String packaze, int access, String... modules) {
458 buf.setLength(0);
459 buf.append("mdv.visitExport(");
460 appendConstant(buf, packaze);
461 buf.append(", ");
462 appendAccess(access | ACCESS_MODULE);
463 if (modules != null && modules.length > 0) {
464 buf.append(", new String[] {");
465 for (int i = 0; i < modules.length; ++i) {
466 buf.append(i == 0 ? " " : ", ");
467 appendConstant(modules[i]);
468 }
469 buf.append(" }");
470 }
471 buf.append(");\n");
472 text.add(buf.toString());
473 }
474
475 @Override
476 public void visitOpen(String packaze, int access, String... modules) {
477 buf.setLength(0);
478 buf.append("mdv.visitOpen(");
479 appendConstant(buf, packaze);
480 buf.append(", ");
481 appendAccess(access | ACCESS_MODULE);
482 if (modules != null && modules.length > 0) {
483 buf.append(", new String[] {");
484 for (int i = 0; i < modules.length; ++i) {
485 buf.append(i == 0 ? " " : ", ");
486 appendConstant(modules[i]);
487 }
488 buf.append(" }");
489 }
490 buf.append(");\n");
491 text.add(buf.toString());
492 }
493
494 @Override
495 public void visitUse(String service) {
496 buf.setLength(0);
497 buf.append("mdv.visitUse(");
498 appendConstant(buf, service);
499 buf.append(");\n");
500 text.add(buf.toString());
501 }
502
503 @Override
504 public void visitProvide(String service, String... providers) {
505 buf.setLength(0);
506 buf.append("mdv.visitProvide(");
507 appendConstant(buf, service);
508 buf.append(", new String[] {");
509 for (int i = 0; i < providers.length; ++i) {
510 buf.append(i == 0 ? " " : ", ");
511 appendConstant(providers[i]);
512 }
513 buf.append(" });\n");
514 text.add(buf.toString());
515 }
516
517 @Override
518 public void visitModuleEnd() {
519 text.add("mdv.visitEnd();\n");
520 }
521
522
523 // ------------------------------------------------------------------------
524 // Annotations
525 // ------------------------------------------------------------------------
526
527 @Override
528 public void visit(final String name, final Object value) {
529 buf.setLength(0);
530 buf.append("av").append(id).append(".visit(");
531 appendConstant(buf, name);
532 buf.append(", ");
533 appendConstant(buf, value);
534 buf.append(");\n");
535 text.add(buf.toString());
536 }
537
538 @Override
539 public void visitEnum(final String name, final String desc,
540 final String value) {
541 buf.setLength(0);
542 buf.append("av").append(id).append(".visitEnum(");
543 appendConstant(buf, name);
1090 public void visitAttribute(final Attribute attr) {
1091 buf.setLength(0);
1092 buf.append("// ATTRIBUTE ").append(attr.type).append('\n');
1093 if (attr instanceof ASMifiable) {
1094 if (labelNames == null) {
1095 labelNames = new HashMap<Label, String>();
1096 }
1097 buf.append("{\n");
1098 ((ASMifiable) attr).asmify(buf, "attr", labelNames);
1099 buf.append(name).append(".visitAttribute(attr);\n");
1100 buf.append("}\n");
1101 }
1102 text.add(buf.toString());
1103 }
1104
1105 // ------------------------------------------------------------------------
1106 // Utility methods
1107 // ------------------------------------------------------------------------
1108
1109 protected ASMifier createASMifier(final String name, final int id) {
1110 return new ASMifier(Opcodes.ASM6, name, id);
1111 }
1112
1113 /**
1114 * Appends a string representation of the given access modifiers to
1115 * {@link #buf buf}.
1116 *
1117 * @param access
1118 * some access modifiers.
1119 */
1120 void appendAccess(final int access) {
1121 boolean first = true;
1122 if ((access & Opcodes.ACC_PUBLIC) != 0) {
1123 buf.append("ACC_PUBLIC");
1124 first = false;
1125 }
1126 if ((access & Opcodes.ACC_PRIVATE) != 0) {
1127 buf.append("ACC_PRIVATE");
1128 first = false;
1129 }
1130 if ((access & Opcodes.ACC_PROTECTED) != 0) {
1131 buf.append("ACC_PROTECTED");
1132 first = false;
1133 }
1134 if ((access & Opcodes.ACC_FINAL) != 0) {
1135 if (!first) {
1136 buf.append(" + ");
1137 }
1138 if ((access & ACCESS_MODULE) == 0) {
1139 buf.append("ACC_FINAL");
1140 } else {
1141 buf.append("ACC_TRANSITIVE");
1142 }
1143 first = false;
1144 }
1145 if ((access & Opcodes.ACC_STATIC) != 0) {
1146 if (!first) {
1147 buf.append(" + ");
1148 }
1149 buf.append("ACC_STATIC");
1150 first = false;
1151 }
1152 if ((access & (Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_SUPER | Opcodes.ACC_TRANSITIVE)) != 0) {
1153 if (!first) {
1154 buf.append(" + ");
1155 }
1156 if ((access & ACCESS_CLASS) == 0) {
1157 if ((access & ACCESS_MODULE) == 0) {
1158 buf.append("ACC_SYNCHRONIZED");
1159 } else {
1160 buf.append("ACC_TRANSITIVE");
1161 }
1162 } else {
1163 buf.append("ACC_SUPER");
1164 }
1165 first = false;
1166 }
1167 if ((access & (Opcodes.ACC_VOLATILE | Opcodes.ACC_BRIDGE | Opcodes.ACC_STATIC_PHASE)) != 0) {
1168 if (!first) {
1169 buf.append(" + ");
1170 }
1171 if ((access & ACCESS_FIELD) == 0) {
1172 if ((access & ACCESS_MODULE) == 0) {
1173 buf.append("ACC_BRIDGE");
1174 } else {
1175 buf.append("ACC_STATIC_PHASE");
1176 }
1177 } else {
1178 buf.append("ACC_VOLATILE");
1179 }
1180
1181 first = false;
1182 }
1183 if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0
1184 && (access & ACCESS_FIELD) == 0) {
1185 if (!first) {
1186 buf.append(" + ");
1187 }
1188 buf.append("ACC_VARARGS");
1189 first = false;
1190 }
1191 if ((access & Opcodes.ACC_TRANSIENT) != 0
1192 && (access & ACCESS_FIELD) != 0) {
1193 if (!first) {
1194 buf.append(" + ");
1195 }
1196 buf.append("ACC_TRANSIENT");
1197 first = false;
1198 }
1199 if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0
1200 && (access & ACCESS_FIELD) == 0) {
1239 if (!first) {
1240 buf.append(" + ");
1241 }
1242 buf.append("ACC_STRICT");
1243 first = false;
1244 }
1245 if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
1246 if (!first) {
1247 buf.append(" + ");
1248 }
1249 buf.append("ACC_SYNTHETIC");
1250 first = false;
1251 }
1252 if ((access & Opcodes.ACC_DEPRECATED) != 0) {
1253 if (!first) {
1254 buf.append(" + ");
1255 }
1256 buf.append("ACC_DEPRECATED");
1257 first = false;
1258 }
1259 if ((access & (Opcodes.ACC_MANDATED | Opcodes.ACC_MODULE)) != 0) {
1260 if (!first) {
1261 buf.append(" + ");
1262 }
1263 if ((access & ACCESS_CLASS) == 0) {
1264 buf.append("ACC_MANDATED");
1265 } else {
1266 buf.append("ACC_MODULE");
1267 }
1268 first = false;
1269 }
1270 if (first) {
1271 buf.append('0');
1272 }
1273 }
1274
1275 /**
1276 * Appends a string representation of the given constant to the given
1277 * buffer.
1278 *
1279 * @param cst
1280 * an {@link Integer}, {@link Float}, {@link Long},
1281 * {@link Double} or {@link String} object. May be <tt>null</tt>.
1282 */
1283 protected void appendConstant(final Object cst) {
1284 appendConstant(buf, cst);
1285 }
1286
1287 /**
1293 * @param cst
1294 * an {@link Integer}, {@link Float}, {@link Long},
1295 * {@link Double} or {@link String} object. May be <tt>null</tt>.
1296 */
1297 static void appendConstant(final StringBuffer buf, final Object cst) {
1298 if (cst == null) {
1299 buf.append("null");
1300 } else if (cst instanceof String) {
1301 appendString(buf, (String) cst);
1302 } else if (cst instanceof Type) {
1303 buf.append("Type.getType(\"");
1304 buf.append(((Type) cst).getDescriptor());
1305 buf.append("\")");
1306 } else if (cst instanceof Handle) {
1307 buf.append("new Handle(");
1308 Handle h = (Handle) cst;
1309 buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()])
1310 .append(", \"");
1311 buf.append(h.getOwner()).append("\", \"");
1312 buf.append(h.getName()).append("\", \"");
1313 buf.append(h.getDesc()).append("\", ");
1314 buf.append(h.isInterface()).append(")");
1315 } else if (cst instanceof Byte) {
1316 buf.append("new Byte((byte)").append(cst).append(')');
1317 } else if (cst instanceof Boolean) {
1318 buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE"
1319 : "Boolean.FALSE");
1320 } else if (cst instanceof Short) {
1321 buf.append("new Short((short)").append(cst).append(')');
1322 } else if (cst instanceof Character) {
1323 int c = ((Character) cst).charValue();
1324 buf.append("new Character((char)").append(c).append(')');
1325 } else if (cst instanceof Integer) {
1326 buf.append("new Integer(").append(cst).append(')');
1327 } else if (cst instanceof Float) {
1328 buf.append("new Float(\"").append(cst).append("\")");
1329 } else if (cst instanceof Long) {
1330 buf.append("new Long(").append(cst).append("L)");
1331 } else if (cst instanceof Double) {
1332 buf.append("new Double(\"").append(cst).append("\")");
1333 } else if (cst instanceof byte[]) {
1334 byte[] v = (byte[]) cst;
|