1 30 package org.objectweb.asm.test.cases; 31 32 import java.io.IOException ; 33 34 import org.objectweb.asm.ClassWriter; 35 import org.objectweb.asm.FieldVisitor; 36 import org.objectweb.asm.Label; 37 import org.objectweb.asm.MethodVisitor; 38 39 46 public class Debug extends Generator { 47 48 public void generate(final String dir) throws IOException { 49 generate(dir, "pkg/Debug.class", dump()); 50 } 51 52 public byte[] dump() { 53 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 54 55 cw.visit(V1_5, 56 ACC_PUBLIC + ACC_SUPER, 57 "pkg/Debug", 58 null, 59 "java/lang/Object", 60 new String [] { "java/io/Serializable" }); 61 62 cw.visitSource("Debug.java", "source-debug"); 63 64 FieldVisitor fv = cw.visitField(ACC_FINAL + ACC_STATIC, 65 "serialVersionUID", 66 "J", 67 null, 68 new Long (1L)); 69 fv.visitEnd(); 70 71 MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, 72 "<init>", 73 "()V", 74 null, 75 null); 76 mv.visitCode(); 77 Label l0 = new Label(); 78 Label l1 = new Label(); 79 Label l2 = new Label(); 80 mv.visitLabel(l0); 81 mv.visitLineNumber(3, l0); 82 mv.visitVarInsn(ALOAD, 0); 83 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 84 mv.visitInsn(ICONST_0); 85 mv.visitJumpInsn(IFEQ, l1); 86 mv.visitJumpInsn(GOTO, l1); 87 mv.visitLabel(l1); 88 mv.visitLineNumber(3, l1); 89 mv.visitInsn(RETURN); 90 mv.visitLabel(l2); 91 mv.visitLocalVariable("this", "Lpkg/Debug;", "Lpkg/Debug;", l0, l2, 0); 92 mv.visitMaxs(0, 0); 93 mv.visitEnd(); 94 95 cw.visitEnd(); 96 97 return cw.toByteArray(); 98 } 99 } 100 | Popular Tags |