private JavaProxyClass generate(ClassDefiningClassLoader loader, String targetClassName, Class superClass, Class[] interfaces, Map<MethodKey, MethodData> methods, Type selfType) { ClassWriter cw = beginProxyClass(targetClassName, superClass, interfaces, loader); GeneratorAdapter clazzInit = createClassInitializer(selfType, cw); generateConstructors(superClass, selfType, cw); generate___getProxyClass(selfType, cw); generate___getInvocationHandler(selfType, cw); generateProxyMethods(superClass, methods, selfType, cw, clazzInit); // finish class initializer clazzInit.returnValue(); clazzInit.endMethod(); // end class cw.visitEnd(); Class clazz = loader.defineClass(selfType.getClassName(), cw.toByteArray()); // trigger class initialization for the class try { Field proxy_class = clazz.getDeclaredField(PROXY_CLASS_FIELD_NAME); // proxy_class.setAccessible(true); // field is public return (JavaProxyClass) proxy_class.get(clazz); } catch (NoSuchFieldException|IllegalAccessException ex) { Helpers.throwException(ex); return null; // re-throws (although unexpected) } }
private JavaProxyClass generate(ClassDefiningClassLoader loader, String targetClassName, Class superClass, Class[] interfaces, Map<MethodKey, MethodData> methods, Type selfType) { ClassWriter cw = beginProxyClass(targetClassName, superClass, interfaces, loader); GeneratorAdapter clazzInit = createClassInitializer(selfType, cw); generateConstructors(superClass, selfType, cw); generate___getProxyClass(selfType, cw); generate___getInvocationHandler(selfType, cw); generateProxyMethods(superClass, methods, selfType, cw, clazzInit); // finish class initializer clazzInit.returnValue(); clazzInit.endMethod(); // end class cw.visitEnd(); Class clazz = loader.defineClass(selfType.getClassName(), cw.toByteArray()); // trigger class initialization for the class try { Field proxy_class = clazz.getDeclaredField(PROXY_CLASS_FIELD_NAME); // proxy_class.setAccessible(true); // field is public return (JavaProxyClass) proxy_class.get(clazz); } catch (NoSuchFieldException|IllegalAccessException ex) { Helpers.throwException(ex); return null; // re-throws (although unexpected) } }