// ****** CLASSES ****** // ClassGraph { (@ void check_parameters() throws Exception { System.out.println("Checking that every parameterized class is consistently defined and used ..."); RightChecker right_c = new RightChecker(null, new ComplexContainer()); LeftChecker left_c = new LeftChecker(null, new ComplexContainer()); this.check_right(right_c); this.check_left(left_c); for (int i = 0; i < right_c.get_rcon().size(); i+=2) { int location = left_c.get_lcon().indexOf(right_c.get_rcon().elementAt(i)); if (location == -1) System.out.println("J-Sem-Check:Error: Class " + right_c.get_rcon().elementAt(i) + " is not defined on the left hand side."); else if (right_c.get_rcon().elementAt(i+1).equals(left_c.get_lcon().elementAt(location+1))) System.out.println("Class " + right_c.get_rcon().elementAt(i) + " passed..."); else { System.out.println("J-Sem-Check:Error: Number of parameters of the Class "+ right_c.get_rcon().elementAt(i) + " do not match."); System.out.println("i = " + i); System.out.println("location = " + location); System.out.println("right_c.get_rcon().elementAt(i+1) = " + right_c.get_rcon().elementAt(i+1)); System.out.println("left_c.get_lcon().ele(location+1) = " + left_c.get_lcon().elementAt(location+1)); } } } void check_right(RightChecker rc) { this.tr(rc); } void check_left(LeftChecker lc) { this.tl(lc); } @) traversal tr(RightChecker rc) { bypassing ParamClassName to ClassSpec; } traversal tl(LeftChecker lc) { bypassing ClassParts to ParamClassName; } } ClassSpec { (@ void count_right(RightCounter rcnt) { this.trr(rcnt);} @) traversal trr (RightCounter rcnt) {to ClassName;} } ParamClassName { (@ void count_left(LeftCounter lcnt) { this.tll(lcnt);} @) traversal tll (LeftCounter lcnt) {to ClassName;} } // ****** MAIN ****** // Main { (@ static public void main(String args[]) throws Exception { ClassGraph a = ClassGraph.parse(System.in); a.check_parameters(); System.out.println("done"); } @) } // ****** VISITORS ****** // RightChecker{ before ClassSpec (@ if (host.get_actual_parameters() != null) { RightCounter right_cnt = new RightCounter(new Integer(0), null, new Integer(0)); host.count_right(right_cnt); rcon.addElement(right_cnt.get_classik().get_name().toString()); rcon.addElement(right_cnt.get_nparams()); } @) } LeftChecker{ before ParamClassName (@ if (host.get_parameters() != null) { LeftCounter left_cnt = new LeftCounter(new Integer(-1), null); host.count_left(left_cnt); lcon.addElement(left_cnt.get_classik().get_name().toString()); lcon.addElement(left_cnt.get_nparams()); } @) } RightCounter{ before ->*,actual_parameters,* (@ level = new Integer (level.intValue() + 1); @) after ->*,actual_parameters,* (@ level = new Integer (level.intValue() - 1); @) before ClassName (@ if (this.get_level().intValue() == 1) nparams = new Integer (nparams.intValue() + 1); if (this.get_classik() == null) this.set_classik(host); @) } LeftCounter{ before ClassName (@ nparams = new Integer (nparams.intValue() + 1); if (this.get_classik() == null) this.set_classik(host); @) }