Search in sources :

Example 16 with CodeEmitter

use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.

the class NoOpGenerator method generate.

public void generate(ClassEmitter ce, Context context, List methods) {
    for (Iterator it = methods.iterator(); it.hasNext(); ) {
        MethodInfo method = (MethodInfo) it.next();
        if (TypeUtils.isProtected(context.getOriginalModifiers(method)) && TypeUtils.isPublic(method.getModifiers())) {
            CodeEmitter e = EmitUtils.begin_method(ce, method);
            e.load_this();
            e.load_args();
            e.super_invoke();
            e.return_value();
            e.end_method();
        }
    }
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Iterator(java.util.Iterator) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)

Example 17 with CodeEmitter

use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.

the class FastClassEmitter method emitIndexBySignature.

// TODO: support constructor indices ("<init>")
private void emitIndexBySignature(List methods) {
    CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SIGNATURE_GET_INDEX, null);
    List signatures = CollectionUtils.transform(methods, new Transformer() {

        public Object transform(Object obj) {
            return ReflectUtils.getSignature((Method) obj).toString();
        }
    });
    e.load_arg(0);
    e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
    signatureSwitchHelper(e, signatures);
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) MethodInfoTransformer(org.powermock.api.mockito.repackaged.cglib.core.MethodInfoTransformer) Transformer(org.powermock.api.mockito.repackaged.cglib.core.Transformer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with CodeEmitter

use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.

the class FastClassEmitter method emitIndexByClassArray.

private void emitIndexByClassArray(List methods) {
    CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null);
    if (methods.size() > TOO_MANY_METHODS) {
        // hack for big classes
        List signatures = CollectionUtils.transform(methods, new Transformer() {

            public Object transform(Object obj) {
                String s = ReflectUtils.getSignature((Method) obj).toString();
                return s.substring(0, s.lastIndexOf(')') + 1);
            }
        });
        e.load_args();
        e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE);
        signatureSwitchHelper(e, signatures);
    } else {
        e.load_args();
        List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance());
        EmitUtils.method_switch(e, info, new GetIndexCallback(e, info));
    }
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) MethodInfoTransformer(org.powermock.api.mockito.repackaged.cglib.core.MethodInfoTransformer) Transformer(org.powermock.api.mockito.repackaged.cglib.core.Transformer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with CodeEmitter

use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.

the class AddDelegateTransformer method begin_method.

public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
    final CodeEmitter e = super.begin_method(access, sig, exceptions);
    if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
        return new CodeEmitter(e) {

            private boolean transformInit = true;

            public void visitMethodInsn(int opcode, String owner, String name, String desc) {
                super.visitMethodInsn(opcode, owner, name, desc);
                if (transformInit && opcode == Constants.INVOKESPECIAL) {
                    load_this();
                    new_instance(delegateType);
                    dup();
                    load_this();
                    invoke_constructor(delegateType, CSTRUCT_OBJECT);
                    putfield(DELEGATE);
                    transformInit = false;
                }
            }
        };
    }
    return e;
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Example 20 with CodeEmitter

use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.

the class AddInitTransformer method begin_method.

public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
    final CodeEmitter emitter = super.begin_method(access, sig, exceptions);
    if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
        return new CodeEmitter(emitter) {

            public void visitInsn(int opcode) {
                if (opcode == Constants.RETURN) {
                    load_this();
                    invoke(info);
                }
                super.visitInsn(opcode);
            }
        };
    }
    return emitter;
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Aggregations

CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)47 Label (org.powermock.api.mockito.repackaged.asm.Label)17 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)13 Type (org.powermock.api.mockito.repackaged.asm.Type)9 Iterator (java.util.Iterator)8 ObjectSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)7 Signature (org.powermock.api.mockito.repackaged.cglib.core.Signature)6 Local (org.powermock.api.mockito.repackaged.cglib.core.Local)5 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)4 ProcessSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback)4 PropertyDescriptor (java.beans.PropertyDescriptor)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Block (org.powermock.api.mockito.repackaged.cglib.core.Block)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 MethodInfoTransformer (org.powermock.api.mockito.repackaged.cglib.core.MethodInfoTransformer)2