use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class InterceptFieldTransformer method addWriteMethod.
private void addWriteMethod(String name, Type type) {
CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, writeMethodSig(name, type.getDescriptor()), null);
e.load_this();
e.dup();
e.invoke_interface(ENABLED, ENABLED_GET);
Label skip = e.make_label();
e.ifnull(skip);
e.load_this();
e.invoke_interface(ENABLED, ENABLED_GET);
e.load_this();
e.push(name);
e.load_this();
e.getfield(name);
e.load_arg(0);
e.invoke_interface(CALLBACK, writeCallbackSig(type));
if (!TypeUtils.isPrimitive(type)) {
e.checkcast(type);
}
Label go = e.make_label();
e.goTo(go);
e.mark(skip);
e.load_arg(0);
e.mark(go);
e.putfield(name);
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter 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();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter 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.cglib.core.CodeEmitter in project powermock by powermock.
the class Enhancer method emitNewInstanceCallback.
private void emitNewInstanceCallback(ClassEmitter ce) {
CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SINGLE_NEW_INSTANCE, null);
switch(callbackTypes.length) {
case 0:
// TODO: make sure Callback is null
break;
case 1:
// for now just make a new array; TODO: optimize
e.push(1);
e.newarray(CALLBACK);
e.dup();
e.push(0);
e.load_arg(0);
e.aastore();
e.invoke_static_this(SET_THREAD_CALLBACKS);
break;
default:
e.throw_exception(ILLEGAL_STATE_EXCEPTION, "More than one callback object required");
}
emitCommonNewInstance(e);
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter 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();
}
Aggregations