Search in sources :

Example 1 with ObjectSwitchCallback

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

the class FieldProviderTransformer method setField.

private void setField(String[] names) throws Exception {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_SET, null);
    e.load_this();
    e.load_arg(1);
    e.load_arg(0);
    EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            Type type = (Type) fields.get(key);
            e.unbox(type);
            e.putfield((String) key);
            e.return_value();
        }

        public void processDefault() {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
        }
    });
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) Label(org.powermock.api.mockito.repackaged.asm.Label) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 2 with ObjectSwitchCallback

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

the class FastClassEmitter method signatureSwitchHelper.

private void signatureSwitchHelper(final CodeEmitter e, final List signatures) {
    ObjectSwitchCallback callback = new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            // TODO: remove linear indexOf
            e.push(signatures.indexOf(key));
            e.return_value();
        }

        public void processDefault() {
            e.push(-1);
            e.return_value();
        }
    };
    EmitUtils.string_switch(e, (String[]) signatures.toArray(new String[signatures.size()]), Constants.SWITCH_STYLE_HASH, callback);
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 3 with ObjectSwitchCallback

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

the class BeanMapEmitter method generateGetPropertyType.

private void generateGetPropertyType(final Map allProps, String[] allNames) {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, GET_PROPERTY_TYPE, null);
    e.load_arg(0);
    EmitUtils.string_switch(e, allNames, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            PropertyDescriptor pd = (PropertyDescriptor) allProps.get(key);
            EmitUtils.load_class(e, Type.getType(pd.getPropertyType()));
            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) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 4 with ObjectSwitchCallback

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

the class Enhancer method emitNewInstanceMultiarg.

private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
    final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null);
    e.load_arg(2);
    e.invoke_static_this(SET_THREAD_CALLBACKS);
    e.new_instance_this();
    e.dup();
    e.load_arg(0);
    EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            MethodInfo constructor = (MethodInfo) key;
            Type[] types = constructor.getSignature().getArgumentTypes();
            for (int i = 0; i < types.length; i++) {
                e.load_arg(1);
                e.push(i);
                e.aaload();
                e.unbox(types[i]);
            }
            e.invoke_constructor_this(constructor.getSignature());
            e.goTo(end);
        }

        public void processDefault() {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
        }
    });
    e.aconst_null();
    e.invoke_static_this(SET_THREAD_CALLBACKS);
    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) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo) ObjectSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)

Example 5 with ObjectSwitchCallback

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

the class FieldProviderTransformer method getField.

// TODO: if this is used to enhance class files SWITCH_STYLE_TRIE should be used
// to avoid JVM hashcode implementation incompatibilities
private void getField(String[] names) throws Exception {
    final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_GET, null);
    e.load_this();
    e.load_arg(0);
    EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {

        public void processCase(Object key, Label end) {
            Type type = (Type) fields.get(key);
            e.getfield((String) key);
            e.box(type);
            e.return_value();
        }

        public void processDefault() {
            e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
        }
    });
    e.end_method();
}
Also used : CodeEmitter(org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter) Type(org.powermock.api.mockito.repackaged.asm.Type) Label(org.powermock.api.mockito.repackaged.asm.Label) 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