// // Flatten Class Graphs // Cd_graph { /* * Algorithm for Class Graph flattening: * 1. Find concrete class * 2. Get the SuperClass's contents (recursively) * 3. Add (2) to concrete class * 4. Repeat 2-3 for every concrete class * 5. Remove contents from abstract classes */ void flatten() {{ this.collectParts(); this.removeCommons(); }} /* * Steps 1-4 */ void collectParts() to Adjacency { {{ Cd_graph cdg; }} before Cd_graph {{ cdg = host; }} before Adjacency {{ if (host.num_subs() == 0) { Iterator i = host.gatherParts(cdg).iterator(); Any_vertex_List l = host.get_construct_list(); l.set_first(null); while (i.hasNext()) { //System.out.println("adding stuff"); Any_vertex a = (Any_vertex)i.next(); //a.display(); l.addElement(a); //l.display(); } //host.display(); } }} } /* * Step 5 */ void removeCommons() to Adjacency { before Adjacency {{ if (host.num_subs() != 0) { Any_vertex_List l = host.get_construct_list(); l.set_first(null); } }} } } Adjacency { /* * Recursively gather all the contents of a class and it's superclasses */ Set gatherParts(Cd_graph cdg) {{ Iterator sIter = this.super_iter(); Set parts = new HashSet(); //System.out.println("test"+this.get_source_name()); while (sIter.hasNext()) { SuperClass s = (SuperClass) sIter.next(); //System.out.println("test"); Adjacency adj = cdg.get_class(s.get_super_name().toString()); //System.out.println("recurse"+adj.get_source_name()); parts.addAll(adj.gatherParts(cdg)); } //System.out.println("testing"); parts.addAll(this.constructs()); return parts; }} }