Search in sources :

Example 26 with Label

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

the class EmitUtils method process_array.

/**
     * Process an array on the stack. Assumes the top item on the stack
     * is an array of the specified type. For each element in the array,
     * puts the element on the stack and triggers the callback.
     * @param type the type of the array (type.isArray() must be true)
     * @param callback the callback triggered for each element
     */
public static void process_array(CodeEmitter e, Type type, ProcessArrayCallback callback) {
    Type componentType = TypeUtils.getComponentType(type);
    Local array = e.make_local();
    Local loopvar = e.make_local(Type.INT_TYPE);
    Label loopbody = e.make_label();
    Label checkloop = e.make_label();
    e.store_local(array);
    e.push(0);
    e.store_local(loopvar);
    e.goTo(checkloop);
    e.mark(loopbody);
    e.load_local(array);
    e.load_local(loopvar);
    e.array_load(componentType);
    callback.processElement(componentType);
    e.iinc(loopvar, 1);
    e.mark(checkloop);
    e.load_local(loopvar);
    e.load_local(array);
    e.arraylength();
    e.if_icmp(e.LT, loopbody);
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type) Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 27 with Label

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

the class EmitUtils method hash_object.

private static void hash_object(CodeEmitter e, Type type, Customizer customizer) {
    // (f == null) ? 0 : f.hashCode();
    Label skip = e.make_label();
    Label end = e.make_label();
    e.dup();
    e.ifnull(skip);
    if (customizer != null) {
        customizer.customize(e, type);
    }
    e.invoke_virtual(Constants.TYPE_OBJECT, HASH_CODE);
    e.goTo(end);
    e.mark(skip);
    e.pop();
    e.push(0);
    e.mark(end);
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 28 with Label

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

the class EmitUtils method string_switch_trie.

private static void string_switch_trie(final CodeEmitter e, String[] strings, final ObjectSwitchCallback callback) throws Exception {
    final Label def = e.make_label();
    final Label end = e.make_label();
    final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {

        public Object transform(Object value) {
            return new Integer(((String) value).length());
        }
    });
    e.dup();
    e.invoke_virtual(Constants.TYPE_STRING, STRING_LENGTH);
    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));
            stringSwitchHelper(e, bucket, callback, def, end, 0);
        }

        public void processDefault() {
            e.goTo(def);
        }
    });
    e.mark(def);
    e.pop();
    callback.processDefault();
    e.mark(end);
}
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)

Example 29 with Label

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

the class EmitUtils method process_arrays.

/**
     * Process two arrays on the stack in parallel. Assumes the top two items on the stack
     * are arrays of the specified class. The arrays must be the same length. For each pair
     * of elements in the arrays, puts the pair on the stack and triggers the callback.
     * @param type the type of the arrays (type.isArray() must be true)
     * @param callback the callback triggered for each pair of elements
     */
public static void process_arrays(CodeEmitter e, Type type, ProcessArrayCallback callback) {
    Type componentType = TypeUtils.getComponentType(type);
    Local array1 = e.make_local();
    Local array2 = e.make_local();
    Local loopvar = e.make_local(Type.INT_TYPE);
    Label loopbody = e.make_label();
    Label checkloop = e.make_label();
    e.store_local(array1);
    e.store_local(array2);
    e.push(0);
    e.store_local(loopvar);
    e.goTo(checkloop);
    e.mark(loopbody);
    e.load_local(array1);
    e.load_local(loopvar);
    e.array_load(componentType);
    e.load_local(array2);
    e.load_local(loopvar);
    e.array_load(componentType);
    callback.processElement(componentType);
    e.iinc(loopvar, 1);
    e.mark(checkloop);
    e.load_local(loopvar);
    e.load_local(array1);
    e.arraylength();
    e.if_icmp(e.LT, loopbody);
}
Also used : Type(org.powermock.api.mockito.repackaged.asm.Type) Label(org.powermock.api.mockito.repackaged.asm.Label)

Example 30 with Label

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

the class Enhancer method emitCurrentCallback.

private void emitCurrentCallback(CodeEmitter e, int index) {
    e.load_this();
    e.getfield(getCallbackField(index));
    e.dup();
    Label end = e.make_label();
    e.ifnonnull(end);
    // stack height
    e.pop();
    e.load_this();
    e.invoke_static_this(BIND_CALLBACKS);
    e.load_this();
    e.getfield(getCallbackField(index));
    e.mark(end);
}
Also used : Label(org.powermock.api.mockito.repackaged.asm.Label)

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