1 16 package net.sf.cglib.transform.impl; 17 18 import java.lang.reflect.Method ; 19 20 import net.sf.cglib.core.CodeEmitter; 21 import net.sf.cglib.core.Constants; 22 import net.sf.cglib.core.MethodInfo; 23 import net.sf.cglib.core.ReflectUtils; 24 import net.sf.cglib.core.Signature; 25 import net.sf.cglib.transform.ClassEmitterTransformer; 26 27 import org.objectweb.asm.Attribute; 28 import org.objectweb.asm.Type; 29 30 33 public class AddInitTransformer extends ClassEmitterTransformer { 34 private MethodInfo info; 35 36 public AddInitTransformer(Method method) { 37 info = ReflectUtils.getMethodInfo(method); 38 39 Type[] types = info.getSignature().getArgumentTypes(); 40 if (types.length != 1 || 41 !types[0].equals(Constants.TYPE_OBJECT) || 42 !info.getSignature().getReturnType().equals(Type.VOID_TYPE)) { 43 throw new IllegalArgumentException (method + " illegal signature"); 44 } 45 } 46 47 public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) { 48 final CodeEmitter emitter = super.begin_method(access, sig, exceptions); 49 if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) { 50 return new CodeEmitter(emitter) { 51 public void visitInsn(int opcode) { 52 if (opcode == Constants.RETURN) { 53 load_this(); 54 invoke(info); 55 } 56 super.visitInsn(opcode); 57 } 58 }; 59 } 60 return emitter; 61 } 62 } 63 64
| Popular Tags
|