Search in sources :

Example 6 with CodeEmitter

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

the class Enhancer method emitNewInstanceCallbacks.

private void emitNewInstanceCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, NEW_INSTANCE, null);
    e.load_arg(0);
    e.invoke_static_this(SET_THREAD_CALLBACKS);
    emitCommonNewInstance(e);
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Example 7 with CodeEmitter

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

the class Enhancer method emitConstructors.

private void emitConstructors(ClassEmitter ce, List constructors) {
    boolean seenNull = false;
    for (Iterator it = constructors.iterator(); it.hasNext(); ) {
        MethodInfo constructor = (MethodInfo) it.next();
        CodeEmitter e = EmitUtils.begin_method(ce, constructor, Constants.ACC_PUBLIC);
        e.load_this();
        e.dup();
        e.load_args();
        Signature sig = constructor.getSignature();
        seenNull = seenNull || sig.getDescriptor().equals("()V");
        e.super_invoke_constructor(sig);
        e.invoke_static_this(BIND_CALLBACKS);
        if (!interceptDuringConstruction) {
            e.load_this();
            e.push(1);
            e.putfield(CONSTRUCTED_FIELD);
        }
        e.return_value();
        e.end_method();
    }
    if (!classOnly && !seenNull && arguments == null)
        throw new IllegalArgumentException("Superclass has no null constructors but no arguments were given");
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Signature(org.powermock.api.mockito.repackaged.cglib.core.Signature) Iterator(java.util.Iterator) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)

Example 8 with CodeEmitter

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

the class Enhancer method emitSetThreadCallbacks.

private void emitSetThreadCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, SET_THREAD_CALLBACKS, null);
    e.getfield(THREAD_CALLBACKS_FIELD);
    e.load_arg(0);
    e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_SET);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Example 9 with CodeEmitter

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

the class Enhancer method emitSetStaticCallbacks.

private void emitSetStaticCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, SET_STATIC_CALLBACKS, null);
    e.load_arg(0);
    e.putfield(STATIC_CALLBACKS_FIELD);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Example 10 with CodeEmitter

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

the class Enhancer method emitSetCallback.

private void emitSetCallback(ClassEmitter ce, int[] keys) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
    e.load_arg(0);
    e.process_switch(keys, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) {
            e.load_this();
            e.load_arg(1);
            e.checkcast(callbackTypes[key]);
            e.putfield(getCallbackField(key));
            e.goTo(end);
        }

        public void processDefault() {
        // TODO: error?
        }
    });
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) ProcessSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback) Label(org.powermock.api.mockito.repackaged.asm.Label)

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