HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Harness the Power of Javadoc..."
Vol. 9, Issue 5, p. 42

	



Listing 1

public class SimpleTagletExtender 
    extends SimpleTaglet {
    
  public SimpleTagletExtender() {
    super("review","Code Review:","tm");
  }
    
  public static void register(
        Map tgltMap) {
    SimpleTagletExtender tag = 
        new SimpleTagletExtender();
    Taglet t = (Taglet) tgltMap.get(
            tag.getName());
    if (t != null) {
        tgltMap.remove(tag.getName());
    }
    tgltMap.put(tag.getName(), tag);
  }
  
}

Listing 2

public class ReviewDoclet {
  public static Date startDt = null;

  public static boolean start(
      RootDoc root) {
    PackageDoc pkgs[] = 
        root.specifiedPackages();
    int totClsCnt = 0;
    int totRevCnt = 0;
        
    for (int i=0; i<pkgs.length; i++) {
      ClassDoc clsDocs[] = 
          pkgs[i].allClasses();
      int pkgClsCnt = clsDocs.length;
      int pkgRevCnt = 0;
   
      for (int j=0; j<clsDocs.length; 
          j++) {
        String msg = "    " 
            + clsDocs[j].name();
        Tag revTags[] = 
            clsDocs[j].tags("@review");
                
        if (revTags.length == 0) {
          System.out.println(msg 
              + " No review");         
        } else {
          Tag[] senTags = revTags[0]
              .firstSentenceTags();
          String tagTxt = "";
          for (int k=0; 
              k<senTags.length; k++) {
            tagTxt += 
                senTags[k].text();
          }
          System.out.println(msg 
              + " - " + tagTxt);
          pkgRevCnt++;
        }
      }
      totClsCnt += pkgClsCnt;
      totRevCnt += pkgRevCnt;
      System.out.println(
          "Package Total" + " - " 
          + pkgRevCnt + " of " 
          + pkgClsCnt + " classes\n");
    }
        
    System.out.println(
        "\nTotal coverage = " 
        + totRevCnt + " of " 
        + totClsCnt + " classes");
    return true;
  }
    
}

Listing 3

  static Date startDate = null;
  static SimpleDateFormat df = 
    new SimpleDateFormat("MM/dd/yyyy");
  
  public static int optionLength(
      String option) {
    if (option.equals("-date")) {
      return 1;
    } else {
      return 0;
    }
  }
    
  public static boolean validOptions(
      String opts[][], 
      DocErrorReporter reporter) {
    boolean valid = true;

    for (int i=0; i<opts.length; i++) {
      if (opts[i][0].equals("-date")) {
        try {
          startDate = 
              df.parse(opts[i][1]);
          valid = true;                       
        } catch (Exception e) {
          reporter.printError(
            "Error: bad date");
          valid = false;
        }
      }
    }
    return valid;
  }

Listing 4

for (int j=0; j<clsDocs.length; j++) {
  String msg = "    " 
      + clsDocs[j].name();
  Tag revDtTags[] = 
      clsDocs[j].tags("@reviewdate");
                
  if (revDtTags.length == 0) {
    System.out.println(msg 
        + " No review");         
  } else {
    String revDtStr = 
        revDtTags[0].text();
    try {
      Date revDt = df.parse(revDtStr);
      if (revDt.before(startDate)) {
        msg += " Old review";
      } else {
        msg += "OK";
      }
    } catch (ParseException e) {
    msg += " Bad date in tag";
    }
    System.out.println(msg);
  }
}

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.