use of org.powermock.api.mockito.repackaged.asm.Label 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();
}
use of org.powermock.api.mockito.repackaged.asm.Label 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.asm.Label in project powermock by powermock.
the class EmitUtils method member_switch_helper.
private static void member_switch_helper(final CodeEmitter e, List members, final ObjectSwitchCallback callback, boolean useName) {
try {
final Map cache = new HashMap();
final ParameterTyper cached = new ParameterTyper() {
public Type[] getParameterTypes(MethodInfo member) {
Type[] types = (Type[]) cache.get(member);
if (types == null) {
cache.put(member, types = member.getSignature().getArgumentTypes());
}
return types;
}
};
final Label def = e.make_label();
final Label end = e.make_label();
if (useName) {
e.swap();
final Map buckets = CollectionUtils.bucket(members, new Transformer() {
public Object transform(Object value) {
return ((MethodInfo) value).getSignature().getName();
}
});
String[] names = (String[]) buckets.keySet().toArray(new String[buckets.size()]);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label dontUseEnd) throws Exception {
member_helper_size(e, (List) buckets.get(key), callback, cached, def, end);
}
public void processDefault() throws Exception {
e.goTo(def);
}
});
} else {
member_helper_size(e, members, callback, cached, def, end);
}
e.mark(def);
e.pop();
callback.processDefault();
e.mark(end);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new CodeGenerationException(ex);
}
}
use of org.powermock.api.mockito.repackaged.asm.Label in project powermock by powermock.
the class EmitUtils method string_switch_hash.
private static void string_switch_hash(final CodeEmitter e, final String[] strings, final ObjectSwitchCallback callback, final boolean skipEquals) throws Exception {
final Map buckets = CollectionUtils.bucket(Arrays.asList(strings), new Transformer() {
public Object transform(Object value) {
return new Integer(value.hashCode());
}
});
final Label def = e.make_label();
final Label end = e.make_label();
e.dup();
e.invoke_virtual(Constants.TYPE_OBJECT, HASH_CODE);
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));
Label next = null;
if (skipEquals && bucket.size() == 1) {
if (skipEquals)
e.pop();
callback.processCase(bucket.get(0), end);
} else {
for (Iterator it = bucket.iterator(); it.hasNext(); ) {
String string = (String) it.next();
if (next != null) {
e.mark(next);
}
if (it.hasNext()) {
e.dup();
}
e.push(string);
e.invoke_virtual(Constants.TYPE_OBJECT, EQUALS);
if (it.hasNext()) {
e.if_jump(e.EQ, next = e.make_label());
e.pop();
} else {
e.if_jump(e.EQ, def);
}
callback.processCase(string, end);
}
}
}
public void processDefault() {
e.pop();
}
});
e.mark(def);
callback.processDefault();
e.mark(end);
}
use of org.powermock.api.mockito.repackaged.asm.Label 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();
}
Aggregations