View Javadoc
1 package net.sf.cglib.transform.impl; 2 3 import java.lang.reflect.Constructor; 4 import net.sf.cglib.core.*; 5 import net.sf.cglib.transform.*; 6 import org.objectweb.asm.Attribute; 7 import org.objectweb.asm.Type; 8 import org.objectweb.asm.ClassVisitor; 9 10 public class UndeclaredThrowableTransformer extends ClassEmitterTransformer { 11 private Type wrapper; 12 13 public UndeclaredThrowableTransformer(Class wrapper) { 14 this.wrapper = Type.getType(wrapper); 15 boolean found = false; 16 Constructor[] cstructs = wrapper.getConstructors(); 17 for (int i = 0; i < cstructs.length; i++) { 18 Class[] types = cstructs[i].getParameterTypes(); 19 if (types.length == 1 && types[0].equals(Throwable.class)) { 20 found = true; 21 break; 22 } 23 } 24 if (!found) 25 throw new IllegalArgumentException(wrapper + " does not have a single-arg constructor that takes a Throwable"); 26 } 27 28 public CodeEmitter begin_method(int access, final Signature sig, final Type[] exceptions, Attribute attrs) { 29 CodeEmitter e = super.begin_method(access, sig, exceptions, attrs); 30 if (TypeUtils.isAbstract(access) || sig.equals(Constants.SIG_STATIC)) { 31 return e; 32 } 33 return new CodeEmitter(e) { 34 private Block handler; 35 /* init */ { 36 handler = begin_block(); 37 } 38 public void visitMaxs(int maxStack, int maxLocals) { 39 handler.end(); 40 EmitUtils.wrap_undeclared_throwable(this, handler, exceptions, wrapper); 41 super.visitMaxs(maxStack, maxLocals); 42 } 43 }; 44 } 45 }

This page was automatically generated by Maven