// tbr.beh // // This file contains code which implements the Terminal Buffer Rule check // Visitor which implements the TBR check. The static var tclasses holds // the names of all terminal classes. TBRVisitor { {{ // Initialize tclasses. static String tclasses = "boolean char byte short int long float double " + // prim types "Boolean Character Integer Long Float Double " + // lang.* "Number String StringBuffer " + "Ident Text Line Word"; // demeter.* public void before(Adjacency a) { // Create traversal graph which targets Term objects. TraversalGraph tg = new TraversalGraph( "from Adjacency bypassing ParentList through Any_vertex_List to Term", Main.cg ); // The variable ptypes holds the targets of all a's construction // edges. List ptypes = tg.gather(a); // If there is not more than 1 construction edge, then a cannot // violate the TBR. if (ptypes.size() > 1) { // Iterate through each edge. ListIterator i = ptypes.listIterator(); while (i.hasNext()) { // If the const edge target is contained in tclasses, // we have a violation of the TBR. Ident cur = ((Term) i.next()).fetchIdent(); if (tclasses.indexOf(cur.toString()) > -1) { System.out.println( "*** Warning: " + "Class " + a.fetchIdent() + " violates the TBR. Class " + cur + " is not the only part class." + '\n' ); Main.wcount++; } } } } }} }