Cd_graph { void display() to * (DisplayVisitor); /*Description: creates a Hash set of defined classes. Also creates a second hashset that lists the classes defined multiple times. */ (@ HashSet defined = new HashSet(); HashSet duplicate_defined_classes = new HashSet(); public void logDefinedClasses(final ClassGraph cg) { TraversalGraph Neighbor_vertexes= new TraversalGraph("from Cd_graph bypassing Neighbors to Vertex", cg); defined = (HashSet) Neighbor_vertexes.traverse( this, new Visitor() { HashSet hashS; public void start(){hashS = new HashSet();} public void before( Vertex vert ) { Ident vertname = vert.get_vertex_name(); if (hashS.contains(vertname)) { if(!duplicate_defined_classes.contains(vertname)) Main.reportError(Main.ERROR_MULTDEF,"!!Class " + vertname + " is defined multiple times!!"); duplicate_defined_classes.add(vertname); } else { hashS.add(vertname); } } public Object getReturnValue(){return hashS;} }); } /* Description: Flattens the Class Graph */ public HashMap common; public void flattenClassGraph(final ClassGraph cg) { common = common_parts(cg); TraversalGraph Tg= new TraversalGraph( "from Cd_graph bypassing Alternat_ns to Any_vertex_List",cg); Tg.traverse(this, new Visitor() { public Ident currentAdj; public void before(Adjacency adj){currentAdj = adj.get_source().get_vertex_name(); } public void before (Any_vertex_List vertList) { Any_vertex_List addList; String childPtr = currentAdj.toString(); String parentPtr = getParent(childPtr); Vector parents = new Vector(); while (parentPtr != null) { parents.add(parentPtr); parentPtr = getParent(parentPtr); } Iterator i = parents.iterator(); while (i.hasNext()) { String currentParent = (String) i.next(); addList = ((Any_vertex_List) common.get(currentParent)); while (addList.hasMoreElements()) { vertList.push((Any_vertex) addList.nextElement()); } } } }); this.removeCommonParts(cg); } public HashMap common_parts(final ClassGraph cg) { TraversalGraph TG= new TraversalGraph("from Cd_graph through Alternat_ns to Any_vertex_List",cg); return (HashMap) TG.traverse(this, new Visitor() { public HashMap commonParts; public Ident currentAdj; public void start() { commonParts = new HashMap(); } public void before(Adjacency adj){currentAdj = adj.get_source().get_vertex_name();} public void before (Any_vertex_List vertList) { commonParts.put( currentAdj.toString(), vertList ); } public Object getReturnValue(){return commonParts;} }); } public void removeCommonParts(final ClassGraph cg) { TraversalGraph TG= new TraversalGraph("from Cd_graph through Alternat_ns to Any_vertex_List",cg); TG.traverse(this, new Visitor() { public void before (Any_vertex_List vertList) {vertList.set_first(null);} }); } public void ICycle(final ClassGraph cg) { TraversalGraph Tg= new TraversalGraph("from Cd_graph bypassing {-> *,construct_ns,*} to Vertex",cg); Tg.traverse(this, new Visitor() { public Vector keyList; public HashMap check; public Vector getKeyList(String mapKey) {return (Vector) check.get(String.valueOf(mapKey));} public void start() {check = new HashMap();} public void before(Alternat_ns alt) {keyList = new Vector();} public void before(Vertex vert) { String vertname = vert.get_vertex_name().toString(); if (keyList != null) keyList.add(vertname); } public void after (Adjacency adj) { if (keyList != null) { Vector values = new Vector(); String sourceName = adj.get_source().get_vertex_name().toString(); deriveInheritance(values, sourceName, sourceName); Iterator i = keyList.iterator(); while (i.hasNext()) { String checkingKey = (String) i.next(); if (values.contains(checkingKey)){ String message = new String(" ->Inheritance cycle detected from "); for (int list = values.size() - 1; list >= 0; --list) message = message + "class "+values.get(list) + " to "; message = message + "class "+checkingKey; Main.reportError(Main.ERROR_INHERITCYCLE,message); Main.stopExec(); } check.put(checkingKey, values.clone());} values = null; keyList = null; } } public void deriveInheritance(Vector list, String str, String stop) { list.add(str); if (check.keySet().contains(str)){ if (!getKeyList(str).contains(stop)){ String nextValue = (String) getKeyList(str).get(0); deriveInheritance(list, nextValue, stop);} } } }); } /*Description: checks for Multiple inheritance via a self created data structure, used before I studied the details of the hashmap and hashset */ public static MICheckList inherit_list; public static Vertex current; public static Adjacency currentadj; private boolean MIerror; void checkMInherit(ClassGraph classg) {inherit_list=new MICheckList(); MIerror=false; TraversalGraph Adjacency = new TraversalGraph("from Cd_graph to Adjacency",Main.cg); Adjacency.traverse(this, new Visitor() { void before( Adjacency adj) {get_a(adj);} }); if (MIerror) Main.stopExec(); } void get_a(Adjacency adj) {currentadj=adj; TraversalGraph DerivedClasses = new TraversalGraph("from Adjacency via Term_Bar_list to Vertex",Main.cg); DerivedClasses.traverse(adj, new Visitor() { void before(Vertex a) {get_b(a);} }); } void get_b(Vertex vert) { current=vert; TraversalGraph Alternats = new TraversalGraph("from Adjacency bypassing {Vertex_Comma_list, Neighbors} to Vertex", Main.cg); Alternats.traverse(Cd_graph.currentadj, new Visitor() { void before(Vertex a ) {MICheckList check = Cd_graph.inherit_list.contains(Cd_graph.current); if (check!=null) {Main.reportError(Main.ERROR_MINHERIT,"---Multiple Inheritance, Class " + check.get_sub().tostring() + " inherits from multiple classes: " + a.tostring() + " and " + check.get_superc().tostring()+ "---"); MIerror=true;} else Cd_graph.inherit_list.add(Cd_graph.current,a); } }); } /* Description: checks for violations to the Unique Parts Rule */ public void uniquePartsCheck(final ClassGraph cg) { TraversalGraph TG= new TraversalGraph("from Cd_graph to {Regular,Labeled}",cg); TG.traverse(this, new Visitor() { HashSet partNames; String currentAdj; public void before(Adjacency adj){ partNames = new HashSet(); currentAdj = adj.get_source().get_vertex_name().toString(); } public void before(Regular reg) { addToPartList(reg.get_vertex().get_vertex().get_vertex_name().toString().toLowerCase()); } public void before(Labeled label) { addToPartList(label.get_label_name().toString()); } private void addToPartList(String add) { if (partNames.contains(add)) { Main.reportError(Main.ERROR_UNIQUEPART,"[Error]: Class" + currentAdj + "has part" + add + "that is not unique"); } else {partNames.add(add);}; } }); } /* Description:Checks for undefined classes and Terminal Buffer Rule Violations. */ public HashSet undefined = new HashSet(); public HashMap relations = new HashMap(); public HashSet TBRErrorList= new HashSet(); public String getParent(String vName) { return (String) relations.get(String.valueOf(vName)); } public void ndef_TBR_check(final ClassGraph cg) { TraversalGraph TG= new TraversalGraph("from Cd_graph through Neighbors to Vertex",cg); TG.traverse( this, new Visitor() { public boolean inPClass; public Ident currentAdj; public Integer adjParts; public boolean isSubClass; public void start() { isSubClass = false; inPClass = false; } public void before(Adjacency adj){ adjParts = new Integer(0); currentAdj = adj.get_source().get_vertex_name(); } public void before(Vertex adj) { Ident vertName = adj.get_vertex_name(); if ( (adjParts.intValue() > 1 || inPClass) && adj.isTerminalClass() && !TBRErrorList.contains(currentAdj)) {Main.reportError(Main.ERROR_TBR, "*Warning:Class "+currentAdj.toString()+" violates the Terminal Buffer Rule*"); TBRErrorList.add(currentAdj); } if(!defined.contains(vertName)) { if (!undefined.contains(vertName) && !Vertex.isTerminalClass(vertName.toString())) Main.reportError(Main.ERROR_NDEF,"!!Class " + vertName + " is NOT defined!!"); undefined.add(vertName); } } public void before(Any_vertex_List vertList){ adjParts = new Integer(vertList.size()); } public void before(Term_Bar_list barList) {isSubClass = true;} public void after(Term_Bar_list barList) {isSubClass = false;} public void before(Term_Comma_list commaList) {inPClass = true;} public void after(Term_Comma_list commaList) {inPClass = false;} }); } @) }