public void testPrune() throws Exception { CtClass cc = sloader.get("test2.Prune"); cc.stopPruning(false); System.out.println(cc); cc.addField(new CtField(CtClass.intType, "f", cc)); cc.toBytecode(); try { cc.defrost(); fail("can call defrost()"); } catch (RuntimeException e) { assertTrue(e.getMessage().indexOf("prune") >= 0); } System.out.println(cc); }
public void testMakeNestedClass() throws Exception { CtClass outer = sloader.get("test2.Nested4"); try { CtClass inner = outer.makeNestedClass("Inner", false); fail(); } catch (RuntimeException e) { print(e.getMessage()); } CtClass nested = outer.makeNestedClass("Inner", true); outer.stopPruning(true); outer.writeFile(); outer.defrost(); String src = "public int f() { return test2.Nested4.value; }"; CtMethod m = CtNewMethod.make(src, nested); nested.addMethod(m); nested.writeFile(); outer.writeFile(); Object iobj = make(nested.getName()); assertEquals(6, invoke(iobj, "f")); }