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 import org.objectweb.asm.attrs.CodeComment; 39 import org.objectweb.asm.attrs.Comment; 40 41 48 public class Attribute extends Generator { 49 50 public void generate(final String dir) throws IOException { 51 generate(dir, "pkg/Attribute.class", dump()); 52 } 53 54 public byte[] dump() { 55 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 56 FieldVisitor fv; 57 MethodVisitor mv; 58 59 cw.visit(V1_3, 60 ACC_PUBLIC + ACC_SYNTHETIC, 61 "pkg/Attribute", 62 null, 63 "java/lang/Object", 64 null); 65 66 cw.visitAttribute(new Comment()); 67 68 fv = cw.visitField(ACC_PUBLIC, "f", "I", null, null); 69 fv.visitAttribute(new Comment()); 70 fv.visitEnd(); 71 72 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 73 mv.visitAttribute(new Comment()); 74 mv.visitCode(); 75 mv.visitVarInsn(ALOAD, 0); 76 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 77 78 84 Label l0 = new Label(); 85 mv.visitInsn(ICONST_0); 86 mv.visitJumpInsn(IFEQ, l0); 87 mv.visitJumpInsn(GOTO, l0); 89 mv.visitLabel(l0); 90 91 mv.visitInsn(RETURN); 92 mv.visitMaxs(0, 0); 93 mv.visitAttribute(new CodeComment()); 94 mv.visitEnd(); 95 96 cw.visitEnd(); 97 return cw.toByteArray(); 98 } 99 } 100 | Popular Tags |