Search in sources :

Example 1 with ProcessSwitchCallback

use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback 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)

Example 2 with ProcessSwitchCallback

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

the class FieldProviderTransformer method getByIndex.

private void getByIndex(final String[] names, final int[] indexes) throws Exception {
    final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_GET_BY_INDEX, null);
    e.load_this();
    e.load_arg(0);
    e.process_switch(indexes, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) throws Exception {
            Type type = (Type) fields.get(names[key]);
            e.getfield(names[key]);
            e.box(type);
            e.return_value();
        }

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

Example 3 with ProcessSwitchCallback

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

the class FieldProviderTransformer method setByIndex.

private void setByIndex(final String[] names, final int[] indexes) throws Exception {
    final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_SET_BY_INDEX, null);
    e.load_this();
    e.load_arg(1);
    e.load_arg(0);
    e.process_switch(indexes, new ProcessSwitchCallback() {

        public void processCase(int key, Label end) throws Exception {
            Type type = (Type) fields.get(names[key]);
            e.unbox(type);
            e.putfield(names[key]);
            e.return_value();
        }

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

Example 4 with ProcessSwitchCallback

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

the class FastClassEmitter method invokeSwitchHelper.

private static void invokeSwitchHelper(final CodeEmitter e, List members, final int arg, final Type base) {
    final List info = CollectionUtils.transform(members, MethodInfoTransformer.getInstance());
    final Label illegalArg = e.make_label();
    Block block = e.begin_block();
    e.process_switch(getIntRange(info.size()), new ProcessSwitchCallback() {

        public void processCase(int key, Label end) {
            MethodInfo method = (MethodInfo) info.get(key);
            Type[] types = method.getSignature().getArgumentTypes();
            for (int i = 0; i < types.length; i++) {
                e.load_arg(arg);
                e.aaload(i);
                e.unbox(types[i]);
            }
            // TODO: change method lookup process so MethodInfo will already reference base
            // instead of superclass when superclass method is inaccessible
            e.invoke(method, base);
            if (!TypeUtils.isConstructor(method)) {
                e.box(method.getSignature().getReturnType());
            }
            e.return_value();
        }

        public void processDefault() {
            e.goTo(illegalArg);
        }
    });
    block.end();
    EmitUtils.wrap_throwable(block, INVOCATION_TARGET_EXCEPTION);
    e.mark(illegalArg);
    e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Cannot find matching method/constructor");
}
Also used : ProcessSwitchCallback(org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback) Label(org.powermock.api.mockito.repackaged.asm.Label) Block(org.powermock.api.mockito.repackaged.cglib.core.Block) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)

Example 5 with ProcessSwitchCallback

use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback 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

Label (org.powermock.api.mockito.repackaged.asm.Label)5 ProcessSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback)5 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)4 Type (org.powermock.api.mockito.repackaged.asm.Type)2 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Block (org.powermock.api.mockito.repackaged.cglib.core.Block)1 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)1