use of org.powermock.api.mockito.repackaged.asm.Label 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.asm.Label 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.asm.Label in project powermock by powermock.
the class EmitUtils method not_equals_helper.
private static void not_equals_helper(CodeEmitter e, Type type, Label notEquals, Customizer customizer, ProcessArrayCallback callback) {
if (TypeUtils.isPrimitive(type)) {
e.if_cmp(type, e.NE, notEquals);
} else {
Label end = e.make_label();
nullcmp(e, notEquals, end);
if (TypeUtils.isArray(type)) {
Label checkContents = e.make_label();
e.dup2();
e.arraylength();
e.swap();
e.arraylength();
e.if_icmp(e.EQ, checkContents);
e.pop2();
e.goTo(notEquals);
e.mark(checkContents);
EmitUtils.process_arrays(e, type, callback);
} else {
if (customizer != null) {
customizer.customize(e, type);
e.swap();
customizer.customize(e, type);
}
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
e.if_jump(e.EQ, notEquals);
}
e.mark(end);
}
}
use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.
the class EmitUtils method member_helper_size.
private static void member_helper_size(final CodeEmitter e, List members, final ObjectSwitchCallback callback, final ParameterTyper typer, final Label def, final Label end) throws Exception {
final Map buckets = CollectionUtils.bucket(members, new Transformer() {
public Object transform(Object value) {
return new Integer(typer.getParameterTypes((MethodInfo) value).length);
}
});
e.dup();
e.arraylength();
e.process_switch(EmitUtils.getSwitchKeys(buckets), new ProcessSwitchCallback() {
public void processCase(int key, Label dontUseEnd) throws Exception {
List bucket = (List) buckets.get(new Integer(key));
member_helper_type(e, bucket, callback, typer, def, end, new BitSet());
}
public void processDefault() throws Exception {
e.goTo(def);
}
});
}
use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.
the class EmitUtils method stringSwitchHelper.
private static void stringSwitchHelper(final CodeEmitter e, List strings, final ObjectSwitchCallback callback, final Label def, final Label end, final int index) throws Exception {
final int len = ((String) strings.get(0)).length();
final Map buckets = CollectionUtils.bucket(strings, new Transformer() {
public Object transform(Object value) {
return new Integer(((String) value).charAt(index));
}
});
e.dup();
e.push(index);
e.invoke_virtual(Constants.TYPE_STRING, STRING_CHAR_AT);
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));
if (index + 1 == len) {
e.pop();
callback.processCase(bucket.get(0), end);
} else {
stringSwitchHelper(e, bucket, callback, def, end, index + 1);
}
}
public void processDefault() {
e.goTo(def);
}
});
}
Aggregations