Search in sources :

Example 6 with Signature

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();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) CodeGenerationException(org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature) Method(java.lang.reflect.Method)

Example 7 with Signature

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);
        }
    };
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature)

Example 8 with Signature

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();
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature) ClassEmitter(org.powermock.api.mockito.repackaged.cglib.core.ClassEmitter) Iterator(java.util.Iterator)

Example 9 with Signature

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();
    }
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature) Iterator(java.util.Iterator) Block(org.powermock.api.mockito.repackaged.cglib.core.Block) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)

Aggregations

Signature (org.powermock.api.mockito.repackaged.cglib.core.Signature)9 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)6 Iterator (java.util.Iterator)5 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)4 Type (org.powermock.api.mockito.repackaged.asm.Type)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 Label (org.powermock.api.mockito.repackaged.asm.Label)1 Block (org.powermock.api.mockito.repackaged.cglib.core.Block)1 ClassEmitter (org.powermock.api.mockito.repackaged.cglib.core.ClassEmitter)1 ClassInfo (org.powermock.api.mockito.repackaged.cglib.core.ClassInfo)1 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)1 Local (org.powermock.api.mockito.repackaged.cglib.core.Local)1