Search in sources :

Example 21 with Label

use of org.powermock.api.mockito.repackaged.asm.Label 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 22 with Label

use of org.powermock.api.mockito.repackaged.asm.Label 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 23 with Label

use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.

the class EmitUtils method not_equals_helper.

private static void not_equals_helper(CodeEmitter e, Type type, Label notEquals, Customizer customizer, ProcessArrayCallback callback) {
    if (TypeUtils.isPrimitive(type)) {
        e.if_cmp(type, e.NE, notEquals);
    } else {
        Label end = e.make_label();
        nullcmp(e, notEquals, end);
        if (TypeUtils.isArray(type)) {
            Label checkContents = e.make_label();
            e.dup2();
            e.arraylength();
            e.swap();
            e.arraylength();
            e.if_icmp(e.EQ, checkContents);
            e.pop2();
            e.goTo(notEquals);
            e.mark(checkContents);
            EmitUtils.process_arrays(e, type, callback);
        } else {
            if (customizer != null) {
                customizer.customize(e, type);
                e.swap();
                customizer.customize(e, type);
            }
            e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
            e.if_jump(e.EQ, notEquals);
        }
        e.mark(end);
    }
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 24 with Label

use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.

the class EmitUtils method member_helper_size.

private static void member_helper_size(final CodeEmitter e, List members, final ObjectSwitchCallback callback, final ParameterTyper typer, final Label def, final Label end) throws Exception {
    final Map buckets = CollectionUtils.bucket(members, new Transformer() {

        public Object transform(Object value) {
            return new Integer(typer.getParameterTypes((MethodInfo) value).length);
        }
    });
    e.dup();
    e.arraylength();
    e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() {

        public void processCase(int key, Label dontUseEnd) throws Exception {
            List bucket = (List) buckets.get(new Integer(key));
            member_helper_type(e, bucket, callback, typer, def, end, new BitSet());
        }

        public void processDefault() throws Exception {
            e.goTo(def);
        }
    });
}
Also used : BigInteger(java.math.BigInteger) Label(org.powermock.api.mockito.repackaged.asm.Label) BitSet(java.util.BitSet) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Label

use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.

the class EmitUtils method stringSwitchHelper.

private static void stringSwitchHelper(final CodeEmitter e, List strings, final ObjectSwitchCallback callback, final Label def, final Label end, final int index) throws Exception {
    final int len = ((String) strings.get(0)).length();
    final Map buckets = CollectionUtils.bucket(strings, new Transformer() {

        public Object transform(Object value) {
            return new Integer(((String) value).charAt(index));
        }
    });
    e.dup();
    e.push(index);
    e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT);
    e.process_switch(getSwitchKeys(buckets), new ProcessSwitchCallback() {

        public void processCase(int key, Label ignore_end) throws Exception {
            List bucket = (List) buckets.get(new Integer(key));
            if (index + 1 == len) {
                e.pop();
                callback.processCase(bucket.get(0), end);
            } else {
                stringSwitchHelper(e, bucket, callback, def, end, index + 1);
            }
        }

        public void processDefault() {
            e.goTo(def);
        }
    });
}
Also used : BigInteger(java.math.BigInteger) Label(org.powermock.api.mockito.repackaged.asm.Label) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Label (org.powermock.api.mockito.repackaged.asm.Label)36 CodeEmitter (org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter)17 Type (org.powermock.api.mockito.repackaged.asm.Type)9 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 ObjectSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback)8 MethodInfo (org.powermock.api.mockito.repackaged.cglib.core.MethodInfo)7 ProcessSwitchCallback (org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback)5 BigInteger (java.math.BigInteger)4 Iterator (java.util.Iterator)4 PropertyDescriptor (java.beans.PropertyDescriptor)3 CodeGenerationException (org.powermock.api.mockito.repackaged.cglib.core.CodeGenerationException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Local (org.powermock.api.mockito.repackaged.cglib.core.Local)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 BitSet (java.util.BitSet)1