@Test public void test() { LogService logService = new LogService(); CompilerBeanProxy beanProxy = new CompilerBeanProxy(); HelloService<?> obj = (HelloService<?>) beanProxy.proxy(HelloService.class, logService); obj.fun1(); }
@Override public <T> T proxy(Class<T> clazz, Object... args) { ClassMeta classMeta = new ClassMeta(); Class<?> actualClass = ClassUtils.getActualClass(clazz); classMeta.packageName = actualClass.getPackage().getName(); classMeta.className = actualClass.getSimpleName() + "$$EnhancerByOxygen"; classMeta.targetClass = ClassUtils.getClassName(actualClass); getTypeVars(actualClass, classMeta.typeVars); classMeta.generic = getGeneric(actualClass.getTypeParameters(), true); classMeta.targetGeneric = getGeneric(actualClass.getTypeParameters(), false); classMeta.constructors = getConstructorMeta(actualClass, classMeta); classMeta.methods = getMethodMeta(actualClass, classMeta); if (classMeta.methods.isEmpty()) { return super.proxy(clazz, args); } String code = Templates.render(CODE_TEMPLATE, MoreObjects.beanToMap(classMeta)); if (log.isTraceEnabled()) { log.trace("Generate proxy class {}.{}: \n{}", classMeta.packageName, classMeta.className, code); } Class<?> proxyClass = compiler.compile(classMeta.packageName, classMeta.className, code); @SuppressWarnings("unchecked") T bean = (T) super.proxy(proxyClass, args); ProxyStore.PROXIES.add(bean); return bean; }
CompilerBeanProxy extends SimpleBeanProxy { @Override public <T> T proxy(Class<T> clazz, Object... args) { ClassMeta classMeta = new ClassMeta(); Class<?> actualClass = ClassUtils.getActualClass(clazz); classMeta.packageName = actualClass.getPackage().getName(); classMeta.className = actualClass.getSimpleName() + "$$EnhancerByOxygen"; classMeta.targetClass = ClassUtils.getClassName(actualClass); getTypeVars(actualClass, classMeta.typeVars); classMeta.generic = getGeneric(actualClass.getTypeParameters(), true); classMeta.targetGeneric = getGeneric(actualClass.getTypeParameters(), false); classMeta.constructors = getConstructorMeta(actualClass, classMeta); classMeta.methods = getMethodMeta(actualClass, classMeta); if (classMeta.methods.isEmpty()) { return super.proxy(clazz, args); } String code = Templates.render(CODE_TEMPLATE, MoreObjects.beanToMap(classMeta)); if (log.isTraceEnabled()) { log.trace("Generate proxy class {}.{}: \n{}", classMeta.packageName, classMeta.className, code); } Class<?> proxyClass = compiler.compile(classMeta.packageName, classMeta.className, code); @SuppressWarnings("unchecked") T bean = (T) super.proxy(proxyClass, args); ProxyStore.PROXIES.add(bean); return bean; } }
CompilerBeanProxy extends SimpleBeanProxy { @Override public <T> T proxy(Class<T> clazz, Object... args) { ClassMeta classMeta = new ClassMeta(); Class<?> actualClass = ClassUtils.getActualClass(clazz); classMeta.packageName = actualClass.getPackage().getName(); classMeta.className = actualClass.getSimpleName() + "$$EnhancerByOxygen"; classMeta.targetClass = ClassUtils.getClassName(actualClass); getTypeVars(actualClass, classMeta.typeVars); classMeta.generic = getGeneric(actualClass.getTypeParameters(), true); classMeta.targetGeneric = getGeneric(actualClass.getTypeParameters(), false); classMeta.constructors = getConstructorMeta(actualClass, classMeta); classMeta.methods = getMethodMeta(actualClass, classMeta); if (classMeta.methods.isEmpty()) { return super.proxy(clazz, args); } String code = Templates.render(CODE_TEMPLATE, MoreObjects.beanToMap(classMeta)); if (log.isTraceEnabled()) { log.trace("Generate proxy class {}.{}: \n{}", classMeta.packageName, classMeta.className, code); } Class<?> proxyClass = compiler.compile(classMeta.packageName, classMeta.className, code); @SuppressWarnings("unchecked") T bean = (T) super.proxy(proxyClass, args); ProxyStore.PROXIES.add(bean); return bean; }  }
CompilerBeanProxy extends SimpleBeanProxy { @Override public <T> T proxy(Class<T> clazz, Object... args) { ClassMeta classMeta = new ClassMeta(); Class<?> actualClass = ClassUtils.getActualClass(clazz); classMeta.packageName = actualClass.getPackage().getName(); classMeta.className = actualClass.getSimpleName() + "$$EnhancerByOxygen"; classMeta.targetClass = ClassUtils.getClassName(actualClass); getTypeVars(actualClass, classMeta.typeVars); classMeta.generic = getGeneric(actualClass.getTypeParameters(), true); classMeta.targetGeneric = getGeneric(actualClass.getTypeParameters(), false); classMeta.constructors = getConstructorMeta(actualClass, classMeta); classMeta.methods = getMethodMeta(actualClass, classMeta); if (classMeta.methods.isEmpty()) { return super.proxy(clazz, args); } String code = Templates.render(CODE_TEMPLATE, MoreObjects.beanToMap(classMeta)); if (log.isTraceEnabled()) { log.trace("Generate proxy class {}.{}: \n{}", classMeta.packageName, classMeta.className, code); } Class<?> proxyClass = compiler.compile(classMeta.packageName, classMeta.className, code); @SuppressWarnings("unchecked") T bean = (T) super.proxy(proxyClass, args); ProxyStore.PROXIES.add(bean); return bean; }  static Method lookup(long key); @Override T proxy(Class<T> clazz, Object... args); }
CompilerBeanProxy extends SimpleBeanProxy { @Override public <T> T proxy(Class<T> clazz, Object... args) { ClassMeta classMeta = new ClassMeta(); Class<?> actualClass = ClassUtils.getActualClass(clazz); classMeta.packageName = actualClass.getPackage().getName(); classMeta.className = actualClass.getSimpleName() + "$$EnhancerByOxygen"; classMeta.targetClass = ClassUtils.getClassName(actualClass); getTypeVars(actualClass, classMeta.typeVars); classMeta.generic = getGeneric(actualClass.getTypeParameters(), true); classMeta.targetGeneric = getGeneric(actualClass.getTypeParameters(), false); classMeta.constructors = getConstructorMeta(actualClass, classMeta); classMeta.methods = getMethodMeta(actualClass, classMeta); if (classMeta.methods.isEmpty()) { return super.proxy(clazz, args); } String code = Templates.render(CODE_TEMPLATE, MoreObjects.beanToMap(classMeta)); if (log.isTraceEnabled()) { log.trace("Generate proxy class {}.{}: \n{}", classMeta.packageName, classMeta.className, code); } Class<?> proxyClass = compiler.compile(classMeta.packageName, classMeta.className, code); @SuppressWarnings("unchecked") T bean = (T) super.proxy(proxyClass, args); ProxyStore.PROXIES.add(bean); return bean; }  static Method lookup(long key); @Override T proxy(Class<T> clazz, Object... args);  }