Search in sources :

Example 6 with ObjectSwitchCallback

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

the class MethodInterceptorGenerator method generateFindProxy.

public void generateFindProxy(ClassEmitter ce, final Map sigMap) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, FIND_PROXY, null);
    e.load_arg(0);
    e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
    ObjectSwitchCallback callback = new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            e.getfield((String) sigMap.get(key));
            e.return_value();
        }

        public void processDefault() {
            e.aconst_null();
            e.return_value();
        }
    };
    EmitUtils.string_switch(e, (String[]) sigMap.keySet().toArray(new String[0]), Constants.SWITCH_STYLE_HASH, callback);
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Label(org.powermock.api.mockito.repackaged.asm.Label) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 7 with ObjectSwitchCallback

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

the class BeanMapEmitter method generatePut.

private void generatePut(Class type, final Map setters) {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, BEAN_MAP_PUT, null);
    e.load_arg(0);
    e.checkcast(Type.getType(type));
    e.load_arg(1);
    e.checkcast(Constants.TYPE_STRING);
    EmitUtils.string_switch(e, getNames(setters), Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            PropertyDescriptor pd = (PropertyDescriptor) setters.get(key);
            if (pd.getReadMethod() == null) {
                e.aconst_null();
            } else {
                MethodInfo read = ReflectUtils.getMethodInfo(pd.getReadMethod());
                e.dup();
                e.invoke(read);
                e.box(read.getSignature().getReturnType());
            }
            // move old value behind bean
            e.swap();
            // new value
            e.load_arg(2);
            MethodInfo write = ReflectUtils.getMethodInfo(pd.getWriteMethod());
            e.unbox(write.getSignature().getArgumentTypes()[0]);
            e.invoke(write);
            e.return_value();
        }

        public void processDefault() {
        // fall-through
        }
    });
    e.aconst_null();
    e.return_value();
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) PropertyDescriptor(java.beans.PropertyDescriptor) Label(org.powermock.api.mockito.repackaged.asm.Label) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 8 with ObjectSwitchCallback

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

the class BeanMapEmitter method generateGet.

private void generateGet(Class type, final Map getters) {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, BEAN_MAP_GET, null);
    e.load_arg(0);
    e.checkcast(Type.getType(type));
    e.load_arg(1);
    e.checkcast(Constants.TYPE_STRING);
    EmitUtils.string_switch(e, getNames(getters), Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            PropertyDescriptor pd = (PropertyDescriptor) getters.get(key);
            MethodInfo method = ReflectUtils.getMethodInfo(pd.getReadMethod());
            e.invoke(method);
            e.box(method.getSignature().getReturnType());
            e.return_value();
        }

        public void processDefault() {
            e.aconst_null();
            e.return_value();
        }
    });
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) PropertyDescriptor(java.beans.PropertyDescriptor) Label(org.powermock.api.mockito.repackaged.asm.Label) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Aggregations

Label (org.powermock.api.mockito.repackaged.asm.Label)8 ObjectSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)8 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)7 PropertyDescriptor (java.beans.PropertyDescriptor)3 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)3 Type (org.powermock.api.mockito.repackaged.asm.Type)2