use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter 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.CodeEmitter in project powermock by powermock.
the class BulkBeanEmitter method generateSet.
private void generateSet(final Class target, final Method[] setters) {
// setPropertyValues
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SET_PROPERTY_VALUES, null);
if (setters.length > 0) {
Local index = e.make_local(Type.INT_TYPE);
e.push(0);
e.store_local(index);
e.load_arg(0);
e.checkcast(Type.getType(target));
e.load_arg(1);
Block handler = e.begin_block();
int lastIndex = 0;
for (int i = 0; i < setters.length; i++) {
if (setters[i] != null) {
MethodInfo setter = ReflectUtils.getMethodInfo(setters[i]);
int diff = i - lastIndex;
if (diff > 0) {
e.iinc(index, diff);
lastIndex = i;
}
e.dup2();
e.aaload(i);
e.unbox(setter.getSignature().getArgumentTypes()[0]);
e.invoke(setter);
}
}
handler.end();
e.return_value();
e.catch_exception(handler, Constants.TYPE_THROWABLE);
e.new_instance(BULK_BEAN_EXCEPTION);
e.dup_x1();
e.swap();
e.load_local(index);
e.invoke_constructor(BULK_BEAN_EXCEPTION, CSTRUCT_EXCEPTION);
e.athrow();
} else {
e.return_value();
}
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class AccessFieldTransformer method declare_field.
public void declare_field(int access, final String name, Type type, Object value) {
super.declare_field(access, name, type, value);
String property = TypeUtils.upperFirst(callback.getPropertyName(getClassType(), name));
if (property != null) {
CodeEmitter e;
e = begin_method(Constants.ACC_PUBLIC, new Signature("get" + property, type, Constants.TYPES_EMPTY), null);
e.load_this();
e.getfield(name);
e.return_value();
e.end_method();
e = begin_method(Constants.ACC_PUBLIC, new Signature("set" + property, Type.VOID_TYPE, new Type[] { type }), null);
e.load_this();
e.load_arg(0);
e.putfield(name);
e.return_value();
e.end_method();
}
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class AddDelegateTransformer method addDelegate.
private void addDelegate(Method m) {
Method delegate;
try {
delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes());
if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())) {
throw new IllegalArgumentException("Invalid delegate signature " + delegate);
}
} catch (NoSuchMethodException e) {
throw new CodeGenerationException(e);
}
final Signature sig = ReflectUtils.getSignature(m);
Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes());
CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions);
e.load_this();
e.getfield(DELEGATE);
e.load_args();
e.invoke_virtual(delegateType, sig);
e.return_value();
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class AddStaticInitTransformer method init.
protected void init() {
if (!TypeUtils.isInterface(getAccess())) {
CodeEmitter e = getStaticHook();
EmitUtils.load_class_this(e);
e.invoke(info);
}
}
Aggregations