use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class InterceptFieldTransformer method begin_method.
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
return new CodeEmitter(super.begin_method(access, sig, exceptions)) {
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
Type towner = TypeUtils.fromInternalName(owner);
switch(opcode) {
case Constants.GETFIELD:
if (filter.acceptRead(towner, name)) {
helper(towner, readMethodSig(name, desc));
return;
}
break;
case Constants.PUTFIELD:
if (filter.acceptWrite(towner, name)) {
helper(towner, writeMethodSig(name, desc));
return;
}
break;
}
super.visitFieldInsn(opcode, owner, name, desc);
}
private void helper(Type owner, Signature sig) {
invoke_virtual(owner, sig);
}
};
}
use of org.powermock.api.mockito.repackaged.asm.Type in project powermock by powermock.
the class ParallelSorterEmitter method generateConstructor.
private void generateConstructor(Object[] arrays) {
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, CSTRUCT_OBJECT_ARRAY, null);
e.load_this();
e.super_invoke_constructor();
e.load_this();
e.load_arg(0);
e.super_putfield("a", Constants.TYPE_OBJECT_ARRAY);
for (int i = 0; i < arrays.length; i++) {
Type type = Type.getType(arrays[i].getClass());
declare_field(Constants.ACC_PRIVATE, getFieldName(i), type, null);
e.load_this();
e.load_arg(0);
e.push(i);
e.aaload();
e.checkcast(type);
e.putfield(getFieldName(i));
}
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.asm.Type 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.Type 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.Type in project powermock by powermock.
the class InterfaceMaker method generateClass.
public void generateClass(ClassVisitor v) throws Exception {
ClassEmitter ce = new ClassEmitter(v);
ce.begin_class(Constants.V1_2, Constants.ACC_PUBLIC | Constants.ACC_INTERFACE, getClassName(), null, null, Constants.SOURCE_FILE);
for (Iterator it = signatures.keySet().iterator(); it.hasNext(); ) {
Signature sig = (Signature) it.next();
Type[] exceptions = (Type[]) signatures.get(sig);
ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_ABSTRACT, sig, exceptions).end_method();
}
ce.end_class();
}
Aggregations