1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jci.classes;
19
20 import org.objectweb.asm.ClassWriter;
21 import org.objectweb.asm.Label;
22 import org.objectweb.asm.MethodVisitor;
23 import org.objectweb.asm.Opcodes;
24
25 public class SimpleDump implements Opcodes {
26
27 public static byte[] dump( final String to ) throws Exception {
28
29 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
30 MethodVisitor mv;
31
32 cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null, "java/lang/Object", null);
33
34 cw.visitSource("Simple.java", null);
35
36 {
37 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
38 mv.visitCode();
39 Label l0 = new Label();
40 mv.visitLabel(l0);
41 mv.visitLineNumber(3, l0);
42 mv.visitVarInsn(ALOAD, 0);
43 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
44 mv.visitInsn(RETURN);
45 Label l1 = new Label();
46 mv.visitLabel(l1);
47 mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
48 mv.visitMaxs(1, 1);
49 mv.visitEnd();
50 }
51 {
52 mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
53 mv.visitCode();
54 Label l0 = new Label();
55 mv.visitLabel(l0);
56 mv.visitLineNumber(6, l0);
57 mv.visitLdcInsn(to);
58 mv.visitInsn(ARETURN);
59 Label l1 = new Label();
60 mv.visitLabel(l1);
61 mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
62 mv.visitMaxs(1, 1);
63 mv.visitEnd();
64 }
65 cw.visitEnd();
66
67 return cw.toByteArray();
68 }
69 }