@Test public void basicSubclassWorks() throws NotFoundException, CannotCompileException, IllegalAccessException, InstantiationException { CtClass superClass = pool.get(TestClassAlpha.class.getName()); CtClass subClass = pool.makeClass(makeNewName()); subClass.setSuperclass(superClass); CtMethod toStringMethod = superClass.getDeclaredMethod("toString"); CtMethod override = CtNewMethod.copy(toStringMethod, "toString", subClass, null); override.setBody("return ($r) super.toString().concat(\"Beta!\");"); subClass.addMethod(override); Class<TestClassAlpha> betaClass = ClassLoadingUtil.toClass(subClass); TestClassAlpha beta = betaClass.newInstance(); assertEquals("AlphaBeta!", beta.toString()); }
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);  }