// rename // Cd_graph => ClassGraph // Alternat => AlternationClass // Vertex => ClassName or ClassSpec // Labeled_vertex => Part // Adj => ClassDef // Construct => ConstructionClass ClassGraph { // find Demeter classes: results in vector of class names traversal allClassDefinitions( IsDemeterClassVisitor dcv ) { // FOR BIG CD bypassing { ClassParts, ClassMethods, -> *, parameters, * } to ClassName; // bypassing{ Neighbors } to Vertex; } (@ ClassNames findDemClasses(){ IsDemeterClassVisitor dcv = new IsDemeterClassVisitor(new ClassNames()); this.allClassDefinitions( dcv ); 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 {AlternationClass} to ClassName; } (@ 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 -> ClassDef, paramclassname, ParamClassName (@ // FOR NEW CD dig deeper this.set_className( new ClassName( dest.get_classname().get_name() ) ); init_p(); init_pt(); @) before {-> Part, classspec, ClassSpec, -> ClassParents, classspec, ClassSpec} (@ inc_p(); // FOR NEW CD dig deeper if ( this.get_cd_defined_classes_in(). indexOf( dest.get_classname().get_name() ) == -1 ) { inc_pt();} @) after ConstructionClass (@ if (( pt.intValue() > 0 ) & (p.intValue() > 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 { ClassGraph example = ClassGraph.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 ClassName (@ this.get_cd_defined_classes_out(). addElement(host.get_name()); @) }