// To demonstrate how to translate class dictionaries // into printing visitors // in /proj/asl/lieber/java/java-envs/j-g-print A { (@ void g_print() { PrintingVisitor pv = new PrintingVisitor(); this.t(pv); } @) // it is important that you traverse to all classes whose // objects you want to print. If you forget to traverse to // Y, Y-objects will not print. This is an advantage since // you can control with the traversal specification what // to print. // Demeter/Java does not yet allow to traverse to all // classes reachable from A by omitting the to part // (like Demeter/C++ does //traversal t(PrintingVisitor pv) { to {D,E,Y};} traversal t(PrintingVisitor pv) { to * ;} } Main { (@ static public void main(String args[]) throws Exception { A a = A.parse(System.in); a.g_print(); System.out.println("done "); } @) } PrintingVisitor{ // The class dictionary is translated systematically into // a PrintingVisitor. All syntax has to be associated with // a class since Demeter/Java does not yet support // edge wrappers. Introduce intermediate classes, if needed. // For example, to express // A = "a" B "x" Y "enda". // write instead // A = "a" B X "enda". // X = "x" Y. // X is an example of an intermediate class. // The class definition // A = "a" B X "enda". // is translated into the following two visitor methods before A (@ System.out.print(" a "); @) after A (@ System.out.print(" enda "); @) // B ~ "(" {C} ")". before B (@ System.out.print(" ( "); @) after B (@ System.out.print(" ) "); @) // X = "x" Y. before X (@ System.out.print(" x "); @) // D = "d" Ident. before D (@ System.out.print(" d " + host.get_text() + " "); @) // E = "e" Integer. before E (@ System.out.print(" e " + host.get_integer().intValue() + " "); @) }