The source of this document is at: http://www.ccs.neu.edu/research/demeter/sources/DemeterJava/examples/j-check-TBR1/evolution-steps Info about Java source code: http://www.ccs.neu.edu/research/demeter/sources/DemeterJava/examples/j-check-TBR1/README The three programs in ../j-check-TBR1 ../j-check-TBR2 ../j-check-TBR3 Presents an evolution of the Terminal-Buffer-Rule checker (page 393 of AP book) over three increasingly larger class dictionaries. See also: http://www.ccs.neu.edu/research/demeter/course/f96/hw/3/assign.html For the first two class dictionaries, the adaptive programs are identical. For the third one, the adaptive program needed to be adjusted. Both the traversal specifications and the Java programs. The three programs serve as an example of how adaptive programs should be developed. Initially a barebone class dictionary is used to get the program going. The class dictionary is gradually enlarged to add more behavior. An evolutionary mechanism is needed so that only the first program needs to be updated and then the third can be created automatically for many evolutions of the first program. Evolution history linking would be a good name for such a mechanism. The advantages would be that multiple variants of the the same program could be maintained more easily. CLASS DICTIONARY 1: program.cd in j-check-TBR1 --------------------------------------------- (@ import java.util.Vector; @) // class dictionary Cd_graph = Adj. Adj = Vertex Construct ".". Construct = "=" Labeled_vertex Labeled_vertex. Labeled_vertex = "<" Ident ">" Vertex. Vertex = Ident. // Visitors Main = . IsDemeterClassVisitor = // vector of cd defined class names ClassNames. CheckingVisitor = // vector of cd defined class names ClassNames Vertex // current class

Integer // number of parts per class Integer // number of terminal parts per class Boolean . ClassNames = *extends* Vector. // Vector(Ident) BEHAVIOR FILE: program.beh in j-check-TBR1 ------------------------------------------------ Cd_graph { // find Demeter classes: results in vector of class names traversal allClassDefinitions( IsDemeterClassVisitor dcv ) { bypassing{ -> *,ns,* } to Vertex; } (@ ClassNames findDemClasses(){ IsDemeterClassVisitor dcv = new IsDemeterClassVisitor(new ClassNames()); this.allClassDefinitions( dcv ); ClassNames cns = dcv.get_cd_defined_classes_out(); System.out.println(" first and last class " + cns.firstElement() + " " + cns.lastElement() + " size of vector " + cns.size()); return dcv.get_cd_defined_classes_out(); } @) // count number of parts (p) init per class def. // count number of parts whose class is terminal (pt) init per class def. // at end of construction class: if pt > 0 and p > 1 then violation. traversal allClasses ( CheckingVisitor ckv ) { bypassing {Alternat} to Vertex; } (@ boolean checkTBR(ClassNames demClasses) { CheckingVisitor ckv = new CheckingVisitor(); // transfer information ckv.set_cd_defined_classes_in(demClasses); ckv.set_passed(new Boolean(true)); this.allClasses( ckv ); return ckv.get_passed().booleanValue(); } @) } CheckingVisitor { (@ void inc_p() { set_p(new Integer(get_p().intValue() + 1)); } void inc_pt() { set_pt(new Integer(get_pt().intValue() + 1)); } void init_p() { set_p(new Integer(0)); } void init_pt() { set_pt(new Integer(0)); } @) before -> Adj, vertex, Vertex (@ this.set_className( new Vertex( dest.get_name() ) ); init_p(); init_pt(); @) before -> Labeled_vertex, *, Vertex (@ inc_p(); System.out.println(" target class " + dest.get_name().toString()); // if ( this.get_cd_defined_classes_in().contains( // dest.get_name())) {System.out.println ("CONTAINED");} // else { inc_pt();} if ( this.get_cd_defined_classes_in(). indexOf( dest.get_name() ) == -1 ) { inc_pt();} @) after Construct (@ int pti = pt.intValue(); int pi = p.intValue(); System.out.println(" parts " + pi + " terminal parts " + pti); if (( pti > 0 ) & (pi > 1)) { set_passed(new Boolean(false)); System.out.print( "Class violates the" + " Terminal Buffer Rule: " ); System.out.println(className.get_name() ); } @) } Main { (@ static public void main (String args[]) throws Exception { Cd_graph example = Cd_graph.parse( System.in ); if (example.checkTBR(example.findDemClasses())) { System.out.println( "Passed!" ); } } @) } // for big cd // traversal IsDemeterClassTraversal(IsDemeterClassVisitor v) { // bypassing { ClassParts, ClassMethods, -> *, parameters, * } to ClassName; IsDemeterClassVisitor { before Vertex (@ this.get_cd_defined_classes_out(). addElement(host.get_name()); @) } } INPUT 1: program.input in j-check-TBR1 ----------------------------------------- A = A A. OUTPUT: java Main < program.input first and last class A A size of vector 1 target class A target class A parts 2 terminal parts 0 Passed! CLASS DICTIONARY 2: program.cd in j-check-TBR2 --------------------------------------------- (@ import java.util.Vector; @) // class dictionary Cd_graph = Adj Adj_list. Adj = Vertex Neighbors ".". Neighbors: Construct | Alternat. Construct = "=" Any_vertex_list. Alternat = ":" Vertex "|" Vertex. Any_vertex : Labeled_vertex | Syntax_vertex. Syntax_vertex = String. Labeled_vertex = "<" Ident ">" Vertex. Adj_list: Cd_graph | Empty_cd_graph . Any_vertex_list: Nany_vertex_list | Empty. Nany_vertex_list = Any_vertex Any_vertex_list. Empty = . Empty_cd_graph = . Vertex = Ident. // Visitors Main = . IsDemeterClassVisitor = // vector of cd defined class names ClassNames. CheckingVisitor = // vector of cd defined class names ClassNames Vertex // current class

Integer // number of parts per class Integer // number of terminal parts per class Boolean . ClassNames = *extends* Vector. // Vector(Ident) INPUT 2: program.input in j-check-TBR2 ----------------------------------------- A1 = A1 A1. A2 = A1 A1. A = "x" X Integer. X = . B = Long. C = Integer Integer. T : R | S. S = Vector A.