use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback in project powermock by powermock.
the class Enhancer method emitSetCallback.
private void emitSetCallback(ClassEmitter ce, int[] keys) {
final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
e.load_arg(0);
e.process_switch(keys, new ProcessSwitchCallback() {
public void processCase(int key, Label end) {
e.load_this();
e.load_arg(1);
e.checkcast(callbackTypes[key]);
e.putfield(getCallbackField(key));
e.goTo(end);
}
public void processDefault() {
// TODO: error?
}
});
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback in project powermock by powermock.
the class FieldProviderTransformer method getByIndex.
private void getByIndex(final String[] names, final int[] indexes) throws Exception {
final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_GET_BY_INDEX, null);
e.load_this();
e.load_arg(0);
e.process_switch(indexes, new ProcessSwitchCallback() {
public void processCase(int key, Label end) throws Exception {
Type type = (Type) fields.get(names[key]);
e.getfield(names[key]);
e.box(type);
e.return_value();
}
public void processDefault() throws Exception {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
}
});
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback in project powermock by powermock.
the class FieldProviderTransformer method setByIndex.
private void setByIndex(final String[] names, final int[] indexes) throws Exception {
final CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, PROVIDER_SET_BY_INDEX, null);
e.load_this();
e.load_arg(1);
e.load_arg(0);
e.process_switch(indexes, new ProcessSwitchCallback() {
public void processCase(int key, Label end) throws Exception {
Type type = (Type) fields.get(names[key]);
e.unbox(type);
e.putfield(names[key]);
e.return_value();
}
public void processDefault() throws Exception {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field index");
}
});
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback in project powermock by powermock.
the class FastClassEmitter method invokeSwitchHelper.
private static void invokeSwitchHelper(final CodeEmitter e, List members, final int arg, final Type base) {
final List info = CollectionUtils.transform(members, MethodInfoTransformer.getInstance());
final Label illegalArg = e.make_label();
Block block = e.begin_block();
e.process_switch(getIntRange(info.size()), new ProcessSwitchCallback() {
public void processCase(int key, Label end) {
MethodInfo method = (MethodInfo) info.get(key);
Type[] types = method.getSignature().getArgumentTypes();
for (int i = 0; i < types.length; i++) {
e.load_arg(arg);
e.aaload(i);
e.unbox(types[i]);
}
// TODO: change method lookup process so MethodInfo will already reference base
// instead of superclass when superclass method is inaccessible
e.invoke(method, base);
if (!TypeUtils.isConstructor(method)) {
e.box(method.getSignature().getReturnType());
}
e.return_value();
}
public void processDefault() {
e.goTo(illegalArg);
}
});
block.end();
EmitUtils.wrap_throwable(block, INVOCATION_TARGET_EXCEPTION);
e.mark(illegalArg);
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Cannot find matching method/constructor");
}
use of org.powermock.api.mockito.repackaged.cglib.core.ProcessSwitchCallback 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