// backlinks.beh -- set the back-links in the class graph. // $Id: backlinks.beh,v 1.4 2002/09/26 06:02:29 dougo Exp $ ClassGraph { /** Set the back-links so that associations are two-way. */ void setBackLinks() to { Part, Superclass, Subclass, Interface } { {{ ClassGraph cg; }} before ClassGraph {{ cg = host; }} {{ ClassDef def; String node; }} before ClassDef {{ def = host; node = host.get_classname().toString(); cg.addNode(node); host.set_cg(cg); }} before { Part, Superclass, Subclass, Interface } {{ host.set_def(def); cg.addOutgoingEdge(node, host); String target = host.get_classname().toString(); cg.addNode(target); cg.addIncomingEdge(target, host); }} } } ClassDef { {{ ClassGraph cg; }} ClassGraph get_cg() {{ return cg; }} void set_cg(ClassGraph cg) {{ this.cg = cg; }} } { Part, Superclass, Subclass, Interface } { {{ // The source of the edge. ClassDef def; }} ClassDef get_def() {{ return def; }} void set_def(ClassDef d) {{ def = d; }} } ClassGraph { {{ // nodes Set nodes = new LinkedHashSet(); // incident edges Map incoming = new HashMap(), outgoing = new HashMap(); }} Set getNodeSet() {{ return nodes; }} void addNode(String node) {{ getNodeSet().add(node); }} Set getIncomingEdgeSet(String node) {{ if (!incoming.containsKey(node)) incoming.put(node, new LinkedHashSet()); return (Set) incoming.get(node); }} void addIncomingEdge(String node, EdgeI edge) {{ getIncomingEdgeSet(node).add(edge); }} Set getOutgoingEdgeSet(String node) {{ if (!outgoing.containsKey(node)) outgoing.put(node, new LinkedHashSet()); return (Set) outgoing.get(node); }} void addOutgoingEdge(String node, EdgeI edge) {{ getOutgoingEdgeSet(node).add(edge); }} }