1 16 package net.sf.cglib.transform.impl; 17 18 import java.lang.reflect.Constructor ; 19 import net.sf.cglib.core.*; 20 import net.sf.cglib.transform.*; 21 import org.objectweb.asm.Attribute; 22 import org.objectweb.asm.Type; 23 import org.objectweb.asm.ClassVisitor; 24 25 public class UndeclaredThrowableTransformer extends ClassEmitterTransformer { 26 private Type wrapper; 27 28 public UndeclaredThrowableTransformer(Class wrapper) { 29 this.wrapper = Type.getType(wrapper); 30 boolean found = false; 31 Constructor [] cstructs = wrapper.getConstructors(); 32 for (int i = 0; i < cstructs.length; i++) { 33 Class [] types = cstructs[i].getParameterTypes(); 34 if (types.length == 1 && types[0].equals(Throwable .class)) { 35 found = true; 36 break; 37 } 38 } 39 if (!found) 40 throw new IllegalArgumentException (wrapper + " does not have a single-arg constructor that takes a Throwable"); 41 } 42 43 public CodeEmitter begin_method(int access, final Signature sig, final Type[] exceptions) { 44 CodeEmitter e = super.begin_method(access, sig, exceptions); 45 if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) { 46 return e; 47 } 48 return new CodeEmitter(e) { 49 private Block handler; 50 { 51 handler = begin_block(); 52 } 53 public void visitMaxs(int maxStack, int maxLocals) { 54 handler.end(); 55 EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper); 56 super.visitMaxs(maxStack, maxLocals); 57 } 58 }; 59 } 60 } 61 | Popular Tags |