Search in sources :

Example 36 with CodeEmitter

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

the class InterceptFieldTransformer method addWriteMethod.

private void addWriteMethod(String name, Type type) {
    CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, writeMethodSig(name, type.getDescriptor()), null);
    e.load_this();
    e.dup();
    e.invoke_interface(ENABLED, ENABLED_GET);
    Label skip = e.make_label();
    e.ifnull(skip);
    e.load_this();
    e.invoke_interface(ENABLED, ENABLED_GET);
    e.load_this();
    e.push(name);
    e.load_this();
    e.getfield(name);
    e.load_arg(0);
    e.invoke_interface(CALLBACK, writeCallbackSig(type));
    if (!TypeUtils.isPrimitive(type)) {
        e.checkcast(type);
    }
    Label go = e.make_label();
    e.goTo(go);
    e.mark(skip);
    e.load_arg(0);
    e.mark(go);
    e.putfield(name);
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 37 with CodeEmitter

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

the class InterceptFieldTransformer method addReadMethod.

private void addReadMethod(String name, Type type) {
    CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, readMethodSig(name, type.getDescriptor()), null);
    e.load_this();
    e.getfield(name);
    e.load_this();
    e.invoke_interface(ENABLED, ENABLED_GET);
    Label intercept = e.make_label();
    e.ifnonnull(intercept);
    e.return_value();
    e.mark(intercept);
    Local result = e.make_local(type);
    e.store_local(result);
    e.load_this();
    e.invoke_interface(ENABLED, ENABLED_GET);
    e.load_this();
    e.push(name);
    e.load_local(result);
    e.invoke_interface(CALLBACK, readCallbackSig(type));
    if (!TypeUtils.isPrimitive(type)) {
        e.checkcast(type);
    }
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Label(org.powermock.api.mockito.repackaged.asm.Label) Local(org.powermock.api.mockito.repackaged.cglib.core.Local)

Example 38 with CodeEmitter

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

the class ParallelSorterEmitter method generateConstructor.

private void generateConstructor(Object[] arrays) {
    CodeEmitter e = begin_method(Constants.ACC_PUBLIC, CSTRUCT_OBJECT_ARRAY, null);
    e.load_this();
    e.super_invoke_constructor();
    e.load_this();
    e.load_arg(0);
    e.super_putfield("a", Constants.TYPE_OBJECT_ARRAY);
    for (int i = 0; i < arrays.length; i++) {
        Type type = Type.getType(arrays[i].getClass());
        declare_field(Constants.ACC_PRIVATE, getFieldName(i), type, null);
        e.load_this();
        e.load_arg(0);
        e.push(i);
        e.aaload();
        e.checkcast(type);
        e.putfield(getFieldName(i));
    }
    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)

Example 39 with CodeEmitter

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

the class Enhancer method emitNewInstanceCallback.

private void emitNewInstanceCallback(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SINGLE_NEW_INSTANCE, null);
    switch(callbackTypes.length) {
        case 0:
            // TODO: make sure Callback is null
            break;
        case 1:
            // for now just make a new array; TODO: optimize
            e.push(1);
            e.newarray(CALLBACK);
            e.dup();
            e.push(0);
            e.load_arg(0);
            e.aastore();
            e.invoke_static_this(SET_THREAD_CALLBACKS);
            break;
        default:
            e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
    }
    emitCommonNewInstance(e);
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)

Example 40 with CodeEmitter

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

the class Enhancer method emitGetCallback.

private void emitGetCallback(ClassEmitter ce, int[] keys) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
    e.load_this();
    e.invoke_static_this(BIND_CALLBACKS);
    e.load_this();
    e.load_arg(0);
    e.process_switch(keys, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) {
            e.getfield(getCallbackField(key));
            e.goTo(end);
        }

        public void processDefault() {
            // stack height
            e.pop();
            e.aconst_null();
        }
    });
    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