TerminalVisitor{ (@ HashSet allClasses = new HashSet(); HashSet terminals = new HashSet(); //////////////////////////// HashSet getHashSet(){ return allClasses; } /////////////////////////// void setTerminalsHash(){ terminals.add("Ident"); terminals.add("Graph"); terminals.add("Text"); terminals.add("Word"); terminals.add("Line"); terminals.add("AroundContinuation"); } /////////////////////////// HashSet getTerminalHash(){ terminals.clear(); setTerminalsHash(); return terminals; } ////////////////////////// void before(Adjacency host){ String sName = host.get_source().get_vertex_name().toString(); // Specify strategy for traversing to the parts of the Adjacency String partStrat = "from Adjacency bypassing {-> *, superclass, *} through Neighbors to Vertex"; Iterator iter = Main.cg.gather(host, partStrat).iterator(); HashSet partHash = new HashSet(); Iterator it = partHash.iterator(); while(iter.hasNext()){ String v = ((Vertex)(iter.next())).get_vertex_name().toString(); partHash.add(v); } //Get the hash set containing the terminal classes HashSet termHash = getTerminalHash(); TraversalGraph pClasses = new TraversalGraph("from Cd_graph bypassing {-> *, superclass, *} through Neighbors to Vertex", Main.cg); //Get the vertex names of the part classes UndefinedVisitor uv2 = new UndefinedVisitor(); pClasses.traverse(Main.cd, uv2); HashSet hash = uv2.getHashSet(); Iterator partClasses = hash.iterator(); while(partClasses.hasNext()){ String vName = partClasses.next().toString(); //Check if the Terminal Buffer Rule was violated // System.out.println("Checking if " + sName + " VIOLATES the Terminal Buffer Rule ..."); if((partHash.contains(vName)) && (partHash.size() > 1 ) && termHash.contains(vName)){ System.out.print("\nThe " + sName + " class violates the TERMINAL BUFFER RULE." ); System.out.println(" Class " + vName + " is NOT the ONLY part."); System.exit(1); } else { // System.out.println(sName + " PASSED the Terminal Buffer Rule Check !!!"); } } partHash.clear(); } ///////////////////////////// void before (Vertex host){ allClasses.add(host.get_vertex_name().toString()); } @) } ////////////////////////// ////////////////////////// Cd_graph{ (@ //Method for checking if the class violates the TBR void TBR_Check(){ String strategy = "from Cd_graph to-stop Adjacency bypassing {-> *, superclass, *}"; //Visit all the Adjacencies TerminalVisitor tv = new TerminalVisitor(); Main.cg.traverse(this, strategy, tv); } @) }