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.MethodVisitor; 37 38 45 public class Outer extends Generator { 46 47 public void generate(final String dir) throws IOException { 48 generate(dir, "pkg/Outer.class", dump()); 49 generate(dir, "pkg/Outer$1.class", dump1()); 50 generate(dir, "pkg/Outer$Inner.class", dumpInner()); 51 } 52 53 public byte[] dump() { 54 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 55 FieldVisitor fv; 56 MethodVisitor mv; 57 58 cw.visit(V1_4, 59 ACC_PUBLIC + ACC_SUPER + ACC_DEPRECATED, 60 "pkg/Outer", 61 null, 62 "java/lang/Object", 63 null); 64 65 cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0); 66 cw.visitInnerClass("pkg/Outer$1", null, null, 0); 67 68 fv = cw.visitField(ACC_PRIVATE + ACC_DEPRECATED, "i", "I", null, null); 69 fv.visitEnd(); 70 71 mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 72 mv.visitCode(); 73 mv.visitVarInsn(ALOAD, 0); 74 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 75 mv.visitInsn(RETURN); 76 mv.visitMaxs(0, 0); 77 mv.visitEnd(); 78 79 mv = cw.visitMethod(ACC_DEPRECATED, "m", "()V", null, null); 80 mv.visitCode(); 81 mv.visitTypeInsn(NEW, "pkg/Outer$1"); 82 mv.visitInsn(DUP); 83 mv.visitVarInsn(ALOAD, 0); 84 mv.visitMethodInsn(INVOKESPECIAL, 85 "pkg/Outer$1", 86 "<init>", 87 "(Lpkg/Outer;)V"); 88 mv.visitInsn(POP); 89 mv.visitInsn(RETURN); 90 mv.visitMaxs(0, 0); 91 mv.visitEnd(); 92 93 mv = cw.visitMethod(ACC_STATIC + ACC_SYNTHETIC, 94 "access$000", 95 "(Lpkg/Outer;)I", 96 null, 97 null); 98 mv.visitCode(); 99 mv.visitVarInsn(ALOAD, 0); 100 mv.visitFieldInsn(GETFIELD, "pkg/Outer", "i", "I"); 101 mv.visitInsn(IRETURN); 102 mv.visitMaxs(0, 0); 103 mv.visitEnd(); 104 105 cw.visitEnd(); 106 107 return cw.toByteArray(); 108 } 109 110 public static byte[] dump1() { 111 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 112 FieldVisitor fv; 113 MethodVisitor mv; 114 115 cw.visit(V1_4, ACC_SUPER, "pkg/Outer$1", null, "pkg/Outer", null); 116 117 cw.visitOuterClass("pkg/Outer", "m", "()V"); 118 cw.visitInnerClass("pkg/Outer$1", null, null, 0); 119 120 fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, 121 "this$0", 122 "Lpkg/Outer;", 123 null, 124 null); 125 fv.visitEnd(); 126 127 mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null); 128 mv.visitCode(); 129 mv.visitVarInsn(ALOAD, 0); 130 mv.visitVarInsn(ALOAD, 1); 131 mv.visitFieldInsn(PUTFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;"); 132 mv.visitVarInsn(ALOAD, 0); 133 mv.visitMethodInsn(INVOKESPECIAL, "pkg/Outer", "<init>", "()V"); 134 mv.visitInsn(RETURN); 135 mv.visitMaxs(0, 0); 136 mv.visitEnd(); 137 138 mv = cw.visitMethod(ACC_PUBLIC, 139 "toString", 140 "()Ljava/lang/String;", 141 null, 142 null); 143 mv.visitCode(); 144 mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); 145 mv.visitInsn(DUP); 146 mv.visitMethodInsn(INVOKESPECIAL, 147 "java/lang/StringBuilder", 148 "<init>", 149 "()V"); 150 mv.visitVarInsn(ALOAD, 0); 151 mv.visitFieldInsn(GETFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;"); 152 mv.visitMethodInsn(INVOKEVIRTUAL, 153 "java/lang/StringBuilder", 154 "append", 155 "(Ljava/lang/Object;)Ljava/lang/StringBuilder;"); 156 mv.visitLdcInsn(" "); 157 mv.visitMethodInsn(INVOKEVIRTUAL, 158 "java/lang/StringBuilder", 159 "append", 160 "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); 161 mv.visitVarInsn(ALOAD, 0); 162 mv.visitFieldInsn(GETFIELD, "pkg/Outer$1", "this$0", "Lpkg/Outer;"); 163 mv.visitMethodInsn(INVOKESTATIC, 164 "pkg/Outer", 165 "access$000", 166 "(Lpkg/Outer;)I"); 167 mv.visitMethodInsn(INVOKEVIRTUAL, 168 "java/lang/StringBuilder", 169 "append", 170 "(I)Ljava/lang/StringBuilder;"); 171 mv.visitMethodInsn(INVOKEVIRTUAL, 172 "java/lang/StringBuilder", 173 "toString", 174 "()Ljava/lang/String;"); 175 mv.visitInsn(ARETURN); 176 mv.visitMaxs(0, 0); 177 mv.visitEnd(); 178 179 cw.visitEnd(); 180 181 return cw.toByteArray(); 182 } 183 184 public static byte[] dumpInner() { 185 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); 186 FieldVisitor fv; 187 MethodVisitor mv; 188 189 cw.visit(V1_4, 190 ACC_SUPER, 191 "pkg/Outer$Inner", 192 null, 193 "java/lang/Object", 194 null); 195 196 cw.visitInnerClass("pkg/Outer$Inner", "pkg/Outer", "C", 0); 197 198 fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, 199 "this$0", 200 "Lpkg/Outer;", 201 null, 202 null); 203 fv.visitEnd(); 204 205 mv = cw.visitMethod(0, "<init>", "(Lpkg/Outer;)V", null, null); 206 mv.visitCode(); 207 mv.visitVarInsn(ALOAD, 0); 208 mv.visitVarInsn(ALOAD, 1); 209 mv.visitFieldInsn(PUTFIELD, "pkg/Outer$Inner", "this$0", "Lpkg/Outer;"); 210 mv.visitVarInsn(ALOAD, 0); 211 mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); 212 mv.visitInsn(RETURN); 213 mv.visitMaxs(0, 0); 214 mv.visitEnd(); 215 216 cw.visitEnd(); 217 218 return cw.toByteArray(); 219 } 220 } 221 | Popular Tags |