use of org.powermock.api.mockito.repackaged.cglib.core.Signature in project powermock by powermock.
the class AddDelegateTransformer method addDelegate.
private void addDelegate(Method m) {
Method delegate;
try {
delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes());
if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())) {
throw new IllegalArgumentException("Invalid delegate signature " + delegate);
}
} catch (NoSuchMethodException e) {
throw new CodeGenerationException(e);
}
final Signature sig = ReflectUtils.getSignature(m);
Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes());
CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions);
e.load_this();
e.getfield(DELEGATE);
e.load_args();
e.invoke_virtual(delegateType, sig);
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.Signature in project powermock by powermock.
the class InterceptFieldTransformer method begin_method.
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
return new CodeEmitter(super.begin_method(access, sig, exceptions)) {
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
Type towner = TypeUtils.fromInternalName(owner);
switch(opcode) {
case Constants.GETFIELD:
if (filter.acceptRead(towner, name)) {
helper(towner, readMethodSig(name, desc));
return;
}
break;
case Constants.PUTFIELD:
if (filter.acceptWrite(towner, name)) {
helper(towner, writeMethodSig(name, desc));
return;
}
break;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
private void helper(Type owner, Signature sig) {
invoke_virtual(owner, sig);
}
};
}
use of org.powermock.api.mockito.repackaged.cglib.core.Signature in project powermock by powermock.
the class InterfaceMaker method generateClass.
public void generateClass(ClassVisitor v) throws Exception {
ClassEmitter ce = new ClassEmitter(v);
ce.begin_class(Constants.V1_2, Constants.ACC_PUBLIC | Constants.ACC_INTERFACE, getClassName(), null, null, Constants.SOURCE_FILE);
for (Iterator it = signatures.keySet().iterator(); it.hasNext(); ) {
Signature sig = (Signature) it.next();
Type[] exceptions = (Type[]) signatures.get(sig);
ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_ABSTRACT, sig, exceptions).end_method();
}
ce.end_class();
}
use of org.powermock.api.mockito.repackaged.cglib.core.Signature in project powermock by powermock.
the class InvocationHandlerGenerator method generate.
public void generate(ClassEmitter ce, Context context, List methods) {
for (Iterator it = methods.iterator(); it.hasNext(); ) {
MethodInfo method = (MethodInfo) it.next();
Signature impl = context.getImplSignature(method);
ce.declare_field(Constants.PRIVATE_FINAL_STATIC, impl.getName(), METHOD, null);
CodeEmitter e = context.beginMethod(ce, method);
Block handler = e.begin_block();
context.emitCallback(e, context.getIndex(method));
e.load_this();
e.getfield(impl.getName());
e.create_arg_array();
e.invoke_interface(INVOCATION_HANDLER, INVOKE);
e.unbox(method.getSignature().getReturnType());
e.return_value();
handler.end();
EmitUtils.wrap_undeclared_throwable(e, handler, method.getExceptionTypes(), UNDECLARED_THROWABLE_EXCEPTION);
e.end_method();
}
}
Aggregations