use of org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback in project powermock by powermock.
the class FieldProviderTransformer method setField.
private void setField(String[] names) throws Exception {
final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_SET, null);
e.load_this();
e.load_arg(1);
e.load_arg(0);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
Type type = (Type) fields.get(key);
e.unbox(type);
e.putfield((String) key);
e.return_value();
}
public void processDefault() {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
}
});
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback in project powermock by powermock.
the class FastClassEmitter method signatureSwitchHelper.
private void signatureSwitchHelper(final CodeEmitter e, final List signatures) {
ObjectSwitchCallback callback = new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
// TODO: remove linear indexOf
e.push(signatures.indexOf(key));
e.return_value();
}
public void processDefault() {
e.push(-1);
e.return_value();
}
};
EmitUtils.string_switch(e, (String[]) signatures.toArray(new String[signatures.size()]), Constants.SWITCH_STYLE_HASH, callback);
}
use of org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback in project powermock by powermock.
the class BeanMapEmitter method generateGetPropertyType.
private void generateGetPropertyType(final Map allProps, String[] allNames) {
final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, GET_PROPERTY_TYPE, null);
e.load_arg(0);
EmitUtils.string_switch(e, allNames, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
PropertyDescriptor pd = (PropertyDescriptor) allProps.get(key);
EmitUtils.load_class(e, Type.getType(pd.getPropertyType()));
e.return_value();
}
public void processDefault() {
e.aconst_null();
e.return_value();
}
});
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback in project powermock by powermock.
the class Enhancer method emitNewInstanceMultiarg.
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null);
e.load_arg(2);
e.invoke_static_this(SET_THREAD_CALLBACKS);
e.new_instance_this();
e.dup();
e.load_arg(0);
EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
MethodInfo constructor = (MethodInfo) key;
Type[] types = constructor.getSignature().getArgumentTypes();
for (int i = 0; i < types.length; i++) {
e.load_arg(1);
e.push(i);
e.aaload();
e.unbox(types[i]);
}
e.invoke_constructor_this(constructor.getSignature());
e.goTo(end);
}
public void processDefault() {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
}
});
e.aconst_null();
e.invoke_static_this(SET_THREAD_CALLBACKS);
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.ObjectSwitchCallback in project powermock by powermock.
the class FieldProviderTransformer method getField.
// TODO: if this is used to enhance class files SWITCH_STYLE_TRIE should be used
// to avoid JVM hashcode implementation incompatibilities
private void getField(String[] names) throws Exception {
final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, PROVIDER_GET, null);
e.load_this();
e.load_arg(0);
EmitUtils.string_switch(e, names, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
public void processCase(Object key, Label end) {
Type type = (Type) fields.get(key);
e.getfield((String) key);
e.box(type);
e.return_value();
}
public void processDefault() {
e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Unknown field name");
}
});
e.end_method();
}
Aggregations