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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations