// uniqueparts.beh // // This file contains code which implements the Unique Parts check. // Visitor which implements the unique parts check. UniquePartsVisitor { {{ public void before(Adjacency a) { // Create new TraversalGraph which targets Opt_labeled_term. TraversalGraph tg = new TraversalGraph( "from Adjacency bypassing ParentList to Opt_labeled_term", Main.cg ); // List parts contains the Opt_labeled_term representation of // each construction edge. List parts = tg.gather(a); // HashSet distinct will hold the part names. HashSet distinct = new HashSet(); // Iterate through each part. The variables cur and partname are // Opt_labeled_term and Ident representations of the current // construction edge. Ident partname; Opt_labeled_term cur; ListIterator i = parts.listIterator(); while(i.hasNext()) { cur = (Opt_labeled_term) i.next(); // If cur is a Labeled object, then use label. if (cur.getClass().toString().equals("class Labeled")) partname = ((Labeled) cur).get_label_name(); // Else, use the class name, in lowercase letters, as the part // name. else partname = new Ident(cur.get_vertex().fetchIdent().toString().toLowerCase()); // If this partname is already in the distinct set, then report // an error. if (distinct.contains(partname)) { System.out.println( "*** Error: Part " + partname + " of class " + a.fetchIdent() + " is not unique." + '\n' ); Main.ecount++; break; } // Else, add to distinct list. else distinct.add(partname); } } }} }