//checks for unique parts. // // Collaboration // role System played by Grammar // out void checkUnique(final ClassGraph cg) // in Strategy getAllUnitsToBeChecked // role UnitToBeChecked played by Statement // in Strategy checkAllParts // role NotDuplicated played by NonTerminal // System = List(UnitToBeChecked). // UnitToBeChecked = List(NotDuplicated). // NotDuplicated = Ident. Grammar{ {{ Strategy getAllUnitsToBeChecked = new Strategy("from Grammar to Statement"); void checkUnique(final ClassGraph cg){ cg.traverse(this, getAllUnitsToBeChecked, new Visitor(){ void before(Statement a){ a.checkDuplicateParts(cg); } }); } }} } Statement{ {{ Strategy checkAllParts = new Strategy( "from Statement through Expression to NonTerminal"); void checkDuplicateParts(ClassGraph cg){ cg.traverse(this, checkAllParts, new Visitor(){ HashSet hParts = new HashSet(); void before(NonTerminal l){ if(!hParts.add(l.get_ident())){ System.out.println("Element "+ l.get_ident() + " is not unique."); } } }); } }} }