@Test public void enhanceGamma() throws Exception { CtClass gamma = pool.get(TestClassGamma.class.getName()); CtClass dirtyInterface = pool.get(Persistent.class.getName()); CtClass enhanced = pool.makeClass(makeNewName()); enhanced.setSuperclass(gamma); enhanced.addInterface(dirtyInterface); CtMethod isDirtyMethod = CtNewMethod.make("public boolean isDirty() { return getFoo() != null || getBars() != null; }", enhanced); enhanced.addMethod(isDirtyMethod); Class<TestClassGamma> cls = ClassLoadingUtil.toClass(enhanced); TestClassGamma instance = cls.newInstance(); assertNotNull(instance); assertNull(instance.getBars()); assertNull(instance.getFoo()); assertDirty(instance, false); instance.setFoo(toString()); instance.setBars(Collections.singletonList("bar")); assertDirty(instance, true); assertEquals(toString(), instance.getFoo()); assertEquals(Collections.singletonList("bar"), instance.getBars()); instance.setFoo(null); instance.setBars(null); assertNull(instance.getBars()); assertNull(instance.getFoo()); assertDirty(instance, false); }
public static <T> Class<T> toClass(CtClass ctClass) throws CannotCompileException { return toClass(ctClass, ClassLoadingUtil.class.getClassLoader(), null); }
ClassLoadingUtil { public static <T> Class<T> toClass(CtClass ctClass) throws CannotCompileException { return toClass(ctClass, ClassLoadingUtil.class.getClassLoader(), null); } }
ClassLoadingUtil { public static <T> Class<T> toClass(CtClass ctClass) throws CannotCompileException { return toClass(ctClass, ClassLoadingUtil.class.getClassLoader(), null); } private  ClassLoadingUtil(); }
ClassLoadingUtil { public static <T> Class<T> toClass(CtClass ctClass) throws CannotCompileException { return toClass(ctClass, ClassLoadingUtil.class.getClassLoader(), null); } private  ClassLoadingUtil(); static Class<T> toClass(CtClass ctClass); static Class<T> toClass(CtClass ctClass, ClassLoader loader, ProtectionDomain domain); }
ClassLoadingUtil { public static <T> Class<T> toClass(CtClass ctClass) throws CannotCompileException { return toClass(ctClass, ClassLoadingUtil.class.getClassLoader(), null); } private  ClassLoadingUtil(); static Class<T> toClass(CtClass ctClass); static Class<T> toClass(CtClass ctClass, ClassLoader loader, ProtectionDomain domain);  }