Cd_graph { traversal allInh(CountingVisitor c) { to Vertex; // is incorrect; should be: // *from* Cd_graph *via* Alternat *to* Vertex } int countInhRels2() = allInh(CountingVisitor); int countInhRels() {{ CountingVisitor count = new CountingVisitor(); this.allInh(count); return count.get_return_val(); }} } CountingVisitor { init {{ total = 0; }} before Vertex {{ total = total +1; }} after {Cd_graph,Adj} {{ System.out.println("CountingVisitor is leaving " +host.getClass().toString() + " total = " + total); }} return int {{ total }} } Main { {{ static public void main(String args[]) throws Exception { Cd_graph graph = Cd_graph.parse(System.in); System.out.println("result = " + graph.countInhRels() + " , " + graph.countInhRels2()); ClassGraph cg = Main.buildClassGraph(); TraversalGraph tg1 = new TraversalGraph( "from Cd_graph via Alternat to Vertex", cg); ObjectGraphSlice sl = new ObjectGraphSlice(graph,tg1); Integer result = graph.countInhRelsDJ (sl); System.out.println("result from DJ = " + result); } }} }