1 19 20 package asm2; 21 22 import org.objectweb.asm.*; 23 import org.objectweb.asm.attrs.*; 24 import java.util.*; 25 26 27 public class Calculator2Dump implements Constants { 28 29 public static byte[] dump () throws Exception { 30 31 ClassWriter cw = new ClassWriter(false); 32 CodeVisitor cv; 33 34 cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, 35 "Calculator2", "java/lang/Object", null, 36 "Calculator2.java"); 37 38 RuntimeInvisibleAnnotations fAtt1 = 40 new RuntimeInvisibleAnnotations(); 41 Annotation fAtt1ann0 = new Annotation("LMarker;"); 42 fAtt1ann0.add( "value", "Field"); 43 fAtt1.annotations.add( fAtt1ann0); 44 cw.visitField(ACC_PRIVATE, "result", "I", 45 null, fAtt1); 46 47 { 48 cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", 49 null, null); 50 cv.visitVarInsn(ALOAD, 0); 51 cv.visitMethodInsn(INVOKESPECIAL, 52 "java/lang/Object", "<init>", "()V"); 53 cv.visitInsn(RETURN); 54 cv.visitMaxs(1, 1); 55 } 56 { 57 RuntimeInvisibleParameterAnnotations mAtt1 = 59 new RuntimeInvisibleParameterAnnotations(); 60 List mAtt1p0 = new ArrayList(); 61 mAtt1.parameters.add( mAtt1p0); 62 63 List mAtt1p1 = new ArrayList(); 64 Annotation mAtt1p1a0 = new Annotation("LMarker;"); 65 mAtt1p1a0.add( "value", "Parameter"); 66 mAtt1p1.add( mAtt1p1a0); 67 68 mAtt1.parameters.add( mAtt1p1); 69 70 RuntimeInvisibleAnnotations mAtt2 = 71 new RuntimeInvisibleAnnotations(); 72 Annotation mAtt2a0 = new Annotation("LMarker;"); 73 mAtt2a0.add( "value", "Method"); 74 mAtt2.annotations.add( mAtt2a0); 75 76 mAtt1.next = mAtt2; 77 78 cv = cw.visitMethod(ACC_PRIVATE, "sum", "(II)V", 79 null, mAtt1); 80 81 cv.visitVarInsn(ALOAD, 0); 82 cv.visitVarInsn(ILOAD, 1); 83 cv.visitVarInsn(ILOAD, 2); 84 cv.visitInsn(IADD); 85 cv.visitFieldInsn(PUTFIELD, "Calculator2", 86 "result", "I"); 87 cv.visitInsn(RETURN); 88 cv.visitMaxs(3, 3); 89 } 90 { 91 RuntimeInvisibleAnnotations attr = 93 new RuntimeInvisibleAnnotations(); 94 Annotation attrann0 = new Annotation("LMarker;"); 95 attrann0.add( "value", "Class"); 96 attr.annotations.add( attrann0); 97 cw.visitAttribute(attr); 98 } 99 cw.visitEnd(); 100 101 return cw.toByteArray(); 102 } 103 } 104 | Popular Tags |