/* GrepDoclet.java * * Copyright (c) 2002 Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka */ package gzz.util; import com.sun.javadoc.*; import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.ArrayList; import java.util.Iterator; /** A doclet which greps all javadocs for given tags and puts them out. * Used for creating and referring to UML diagrams from the javadocs. * @diagram Testdiagram foo * @diagram Testdiagram bar * @diagram Test2diagram quu * @diagram Testdiagram baz */ public class GrepDoclet { static void p(String s) { System.out.println(s); } /** Testing a field. * @diagram Test2diagram xyz */ public Map diagrams = new HashMap(); Diagram getDiagram(String dia) { Diagram d = (Diagram) diagrams.get(dia); if(d == null) { d = new Diagram(dia); diagrams.put(dia, d); } return d; } static class Diagram { String name; List text = new ArrayList(); Diagram(String name) { this.name = name; } void addText(String tag, String name, String txt) { text.add(tag+" \""+name+"\" "+txt ); } void print() { p("DIAGRAM \""+name+"\""); for(Iterator i = text.iterator(); i.hasNext();) { p("" + i.next()); } } } void addText(String text, String tag, String name) { String diagram; int ind = text.indexOf(' '); if(ind < 0) { diagram = text; text = ""; } else { diagram = text.substring(0,ind); text = text.substring(ind+1); } getDiagram(diagram).addText(tag, name, text); } void addClassToDiagram(String cls, String text) { addText(text, "CLASS", cls); } void addFieldToDiagram(String cls, String field, String text) { addText(text, "FIELD", field); } void addMethodToDiagram(String cls, String method, String text) { addText(text, "METHOD", method); } void handleField(String className, FieldDoc f) { Tag[] tags = f.tags("@diagram"); String name = f.name(); for(int i=0; i