use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class Enhancer method emitSetCallbacks.
private void emitSetCallbacks(ClassEmitter ce) {
CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACKS, null);
e.load_this();
e.load_arg(0);
for (int i = 0; i < callbackTypes.length; i++) {
e.dup2();
e.aaload(i);
e.checkcast(callbackTypes[i]);
e.putfield(getCallbackField(i));
}
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class InvocationHandlerGenerator method generate.
public void generate(ClassEmitter ce, Context context, List methods) {
for (Iterator it = methods.iterator(); it.hasNext(); ) {
MethodInfo method = (MethodInfo) it.next();
Signature impl = context.getImplSignature(method);
ce.declare_field(Constants.PRIVATE_FINAL_STATIC, impl.getName(), METHOD, null);
CodeEmitter e = context.beginMethod(ce, method);
Block handler = e.begin_block();
context.emitCallback(e, context.getIndex(method));
e.load_this();
e.getfield(impl.getName());
e.create_arg_array();
e.invoke_interface(INVOCATION_HANDLER, INVOKE);
e.unbox(method.getSignature().getReturnType());
e.return_value();
handler.end();
EmitUtils.wrap_undeclared_throwable(e, handler, method.getExceptionTypes(), UNDECLARED_THROWABLE_EXCEPTION);
e.end_method();
}
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class MethodInterceptorGenerator method generateFindProxy.
public void generateFindProxy(ClassEmitter ce, final Map sigMap) {
final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC | Constants.ACC_STATIC, FIND_PROXY, null);
e.load_arg(0);
e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
ObjectSwitchCallback callback = new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
e.getfield((String) sigMap.get(key));
e.return_value();
}
public void processDefault() {
e.aconst_null();
e.return_value();
}
};
EmitUtils.string_switch(e, (String[]) sigMap.keySet().toArray(new String[0]), Constants.SWITCH_STYLE_HASH, callback);
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class BeanMapEmitter method generatePut.
private void generatePut(Class type, final Map setters) {
final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, BEAN_MAP_PUT, null);
e.load_arg(0);
e.checkcast(Type.getType(type));
e.load_arg(1);
e.checkcast(Constants.TYPE_STRING);
EmitUtils.string_switch(e, getNames(setters), Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
PropertyDescriptor pd = (PropertyDescriptor) setters.get(key);
if (pd.getReadMethod() == null) {
e.aconst_null();
} else {
MethodInfo read = ReflectUtils.getMethodInfo(pd.getReadMethod());
e.dup();
e.invoke(read);
e.box(read.getSignature().getReturnType());
}
// move old value behind bean
e.swap();
// new value
e.load_arg(2);
MethodInfo write = ReflectUtils.getMethodInfo(pd.getWriteMethod());
e.unbox(write.getSignature().getArgumentTypes()[0]);
e.invoke(write);
e.return_value();
}
public void processDefault() {
// fall-through
}
});
e.aconst_null();
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class BeanMapEmitter method generateKeySet.
private void generateKeySet(String[] allNames) {
// static initializer
declare_field(Constants.ACC_STATIC | Constants.ACC_PRIVATE, "keys", FIXED_KEY_SET, null);
CodeEmitter e = begin_static();
e.new_instance(FIXED_KEY_SET);
e.dup();
EmitUtils.push_array(e, allNames);
e.invoke_constructor(FIXED_KEY_SET, CSTRUCT_STRING_ARRAY);
e.putfield("keys");
e.return_value();
e.end_method();
// keySet
e = begin_method(Constants.ACC_PUBLIC, KEY_SET, null);
e.load_this();
e.getfield("keys");
e.return_value();
e.end_method();
}
Aggregations