use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class NoOpGenerator method generate.
public void generate(ClassEmitter ce, Context context, List methods) {
for (Iterator it = methods.iterator(); it.hasNext(); ) {
MethodInfo method = (MethodInfo) it.next();
if (TypeUtils.isProtected(context.getOriginalModifiers(method)) && TypeUtils.isPublic(method.getModifiers())) {
CodeEmitter e = EmitUtils.begin_method(ce, method);
e.load_this();
e.load_args();
e.super_invoke();
e.return_value();
e.end_method();
}
}
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class FastClassEmitter method emitIndexBySignature.
// TODO: support constructor indices ("<init>")
private void emitIndexBySignature(List methods) {
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, SIGNATURE_GET_INDEX, null);
List signatures = CollectionUtils.transform(methods, new Transformer() {
public Object transform(Object obj) {
return ReflectUtils.getSignature((Method) obj).toString();
}
});
e.load_arg(0);
e.invoke_virtual(Constants.TYPE_OBJECT, TO_STRING);
signatureSwitchHelper(e, signatures);
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class FastClassEmitter method emitIndexByClassArray.
private void emitIndexByClassArray(List methods) {
CodeEmitter e = begin_method(Constants.ACC_PUBLIC, METHOD_GET_INDEX, null);
if (methods.size() > TOO_MANY_METHODS) {
// hack for big classes
List signatures = CollectionUtils.transform(methods, new Transformer() {
public Object transform(Object obj) {
String s = ReflectUtils.getSignature((Method) obj).toString();
return s.substring(0, s.lastIndexOf(')') + 1);
}
});
e.load_args();
e.invoke_static(FAST_CLASS, GET_SIGNATURE_WITHOUT_RETURN_TYPE);
signatureSwitchHelper(e, signatures);
} else {
e.load_args();
List info = CollectionUtils.transform(methods, MethodInfoTransformer.getInstance());
EmitUtils.method_switch(e, info, new GetIndexCallback(e, info));
}
e.end_method();
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class AddDelegateTransformer method begin_method.
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
final CodeEmitter e = super.begin_method(access, sig, exceptions);
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
return new CodeEmitter(e) {
private boolean transformInit = true;
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
super.visitMethodInsn(opcode, owner, name, desc);
if (transformInit && opcode == Constants.INVOKESPECIAL) {
load_this();
new_instance(delegateType);
dup();
load_this();
invoke_constructor(delegateType, CSTRUCT_OBJECT);
putfield(DELEGATE);
transformInit = false;
}
}
};
}
return e;
}
use of org.powermock.api.mockito.repackaged.cglib.core.CodeEmitter in project powermock by powermock.
the class AddInitTransformer method begin_method.
public CodeEmitter begin_method(int access, Signature sig, Type[] exceptions) {
final CodeEmitter emitter = super.begin_method(access, sig, exceptions);
if (sig.getName().equals(Constants.CONSTRUCTOR_NAME)) {
return new CodeEmitter(emitter) {
public void visitInsn(int opcode) {
if (opcode == Constants.RETURN) {
load_this();
invoke(info);
}
super.visitInsn(opcode);
}
};
}
return emitter;
}
Aggregations