//Mihran Shahinian & Genci Xhaxhka //Checking that every alternative of a parameterized alternation class //has to use all its formal parameters in the same order .. ParamClassName { // Extended to visit Left Side of Alternation statement (@ ParamContainer goleft() { // Returns Vector containing left side parameters NameCollector pp = new NameCollector(new ParamContainer()); this.allParams(pp); return pp.get_cparams(); } @) traversal allParams(NameCollector pp) {to ClassName;} } Subclass { // Extended to visit Right Side of Alternation statement (@ ParamContainer goright() { NameCollector rs = new NameCollector(new ParamContainer()); this.actParams(rs); return rs.get_cparams(); } @) traversal actParams(NameCollector rs) {to ClassName;} } NameCollector { // visitor which adds the specified class names to vector before ClassName (@ this.get_cparams().addElement(host.get_name()); @) } ClassGraph { (@ void visit_cgraph() { AltCheckVisitor acv = new AltCheckVisitor(); this.through_alt(acv); } @) traversal through_alt(AltCheckVisitor acv) { bypassing { ConstructionClass, RepetitionClass } to ClassName ; } } Main { (@ static public void main(String args[]) throws Exception { ClassGraph a = ClassGraph.parse(System.in); System.out.println("\nChecking that every alternative of a " +"\n parameterized alternation class has \n" +" all its formal parameters in the same order ... \n"); a.visit_cgraph (); System.out.println("\n "); } @) } AltCheckVisitor { // Main Visitor which goes through alternation class before ParamClassName (@ lside = host.goleft(); // might be 1 (just the classname) or more. @) before Subclass (@ rside = host.goright(); // get them // might be 1 (just the classname) or more. if (lside.size() != rside.size()) { // Case 2 System.out.println ( " Check the number of arguments => " +lside.firstElement().toString() +"()" + " : " + rside.firstElement().toString() + "()..."); } else { // we know they're the same size Boolean passarg = new Boolean(true); for (int j = 1; j < lside.size(); j++) { // start from second element. if (! lside.elementAt(j).toString().equals(rside.elementAt(j).toString())) passarg = Boolean.valueOf("False"); } if (passarg.booleanValue()) System.out.print(" "+ lside.firstElement().toString() + "() : " + rside.firstElement().toString() + "() passed the test ...\n"); else System.out.println(" Icorrect Order of arguments => " + lside.firstElement().toString() +"()" + " : " + rside.firstElement().toString() + "()..." ); } @) }