Main { (@ static public void main(String args[]) throws Exception { A a = A.parse(System.in); A newa = a.g_copy(); int a_count = a.count_C(); int newa_count = newa.count_C(); System.out.println(a_count); System.out.println(newa_count); if(a_count == newa_count) { System.out.println("SUCCESS"); } else { System.out.println("FAILURE"); } System.out.println(" done "); } @) } CountingVisitor { before C (@ total = new Integer(total.intValue() + 1); @) } A { traversal all(CopyVisitor cV) { to *; } traversal allC(CountingVisitor cV) { to C; } (@ int count_C() throws Exception { CountingVisitor countV = CountingVisitor.parse("0"); this.allC(countV); return countV.get_total().intValue(); } @) (@ A g_copy() { CopyVisitor cv = new CopyVisitor(); cv.Init("A"); this.all(cv); return (A) cv.GetResult(); } @) } CopyVisitor { (@ Stack history; void Init(String firstClass) { this.history = new Stack(); try { this.history.push(Class.forName(firstClass).newInstance()); } catch(Exception e) { e.printStackTrace(); } } Object GetResult() { return history.peek(); } @) before -> A,b,B (@ A containingObject = (A)history.peek(); Class theClass = dest.getClass(); Object newPartObject = null; try { newPartObject = theClass.newInstance(); } catch(Exception e) { e.printStackTrace(); } containingObject.set_b((B)newPartObject); this.history.push(newPartObject); @) after -> A,b,B (@ this.history.pop(); @) before -> A,c,C (@ A containingObject = (A)history.peek(); Class theClass = dest.getClass(); Object newPartObject = null; try { newPartObject = theClass.newInstance(); } catch(Exception e) { e.printStackTrace(); } containingObject.set_c((C)newPartObject); this.history.push(newPartObject); @) after -> A,c,C (@ this.history.pop(); @) before C (@ C theObject = (C)history.peek(); theObject.set_i(host.get_i()); @) before -> D,a,A (@ D containingObject = (D)history.peek(); Class theClass = dest.getClass(); Object newPartObject = null; try { newPartObject = theClass.newInstance(); } catch(Exception e) { e.printStackTrace(); } containingObject.set_a((A)newPartObject); this.history.push(newPartObject); @) after -> D,a,A (@ this.history.pop(); @) before D (@ D theObject = (D)history.peek(); theObject.set_s(host.get_s()); @) before CountingVisitor (@ CountingVisitor theObject = (CountingVisitor)history.peek(); theObject.set_total(host.get_total()); @) }