use of org.powermock.api.mockito.repackaged.cglib.core.ClassInfo in project powermock by powermock.
the class MethodInterceptorGenerator method generateStatic.
public void generateStatic(CodeEmitter e, Context context, List methods) throws Exception {
/* generates:
static {
Class thisClass = Class.forName("NameOfThisClass");
Class cls = Class.forName("java.lang.Object");
String[] sigs = new String[]{ "toString", "()Ljava/lang/String;", ... };
Method[] methods = cls.getDeclaredMethods();
methods = ReflectUtils.findMethods(sigs, methods);
METHOD_0 = methods[0];
CGLIB$ACCESS_0 = MethodProxy.create(cls, thisClass, "()Ljava/lang/String;", "toString", "CGLIB$ACCESS_0");
...
}
*/
e.push(0);
e.newarray();
e.putfield(EMPTY_ARGS_NAME);
Local thisclass = e.make_local();
Local declaringclass = e.make_local();
EmitUtils.load_class_this(e);
e.store_local(thisclass);
Map methodsByClass = CollectionUtils.bucket(methods, METHOD_TO_CLASS);
for (Iterator i = methodsByClass.keySet().iterator(); i.hasNext(); ) {
ClassInfo classInfo = (ClassInfo) i.next();
List classMethods = (List) methodsByClass.get(classInfo);
e.push(2 * classMethods.size());
e.newarray(Constants.TYPE_STRING);
for (int index = 0; index < classMethods.size(); index++) {
MethodInfo method = (MethodInfo) classMethods.get(index);
Signature sig = method.getSignature();
e.dup();
e.push(2 * index);
e.push(sig.getName());
e.aastore();
e.dup();
e.push(2 * index + 1);
e.push(sig.getDescriptor());
e.aastore();
}
EmitUtils.load_class(e, classInfo.getType());
e.dup();
e.store_local(declaringclass);
e.invoke_virtual(Constants.TYPE_CLASS, GET_DECLARED_METHODS);
e.invoke_static(REFLECT_UTILS, FIND_METHODS);
for (int index = 0; index < classMethods.size(); index++) {
MethodInfo method = (MethodInfo) classMethods.get(index);
Signature sig = method.getSignature();
Signature impl = context.getImplSignature(method);
e.dup();
e.push(index);
e.array_load(METHOD);
e.putfield(getMethodField(impl));
e.load_local(declaringclass);
e.load_local(thisclass);
e.push(sig.getDescriptor());
e.push(sig.getName());
e.push(impl.getName());
e.invoke_static(METHOD_PROXY, MAKE_PROXY);
e.putfield(getMethodProxyField(impl));
}
e.pop();
}
}
Aggregations