Steps for creating custom doclet
I'm a complete newbie to this whole JavaDoc Doclet stuff. I trying to create a custom Doclet I think. I want to use all the standard annotations but add 1 of my one aswell and a method so only the methods with my annotation is shown.
I have a custom Doclet from the sun tutorial but don't have it creating a html file in docs folder or have it recognising any of the standard annotations. It doesn't extend or implement anything.
Any advice on the step to take when creating a Doclet would be much appreciated.
Hi,
Well, I think it's impossible to give you much of advice here on how to write your own doclet...
Just imagine, Javadoc itself is not so much more than a launcher of two things: the Java compiler and the doclet. The compiler parses Java code, collects some information about it and forms the object representation of that information which is provided to the doclet via Doclet API (a structure basically very much similar to XML DOM).
Further, the doclet should use that representation and to generate by it anything you wish. You wish to generate HTML? Fine! Just understand what HTML is (buy some fat book about it) and go ahead! Want to generate PDF? Nothing is simpler: PDF specs is free on the Adobe web-site... Want to generate some UML diagrams by it? There are lots of various graphics libraries to help you with that... and so on... so on... You are free to generate anything you wish and in any way you wish!
Best,
Leonid Rudy
http://www.docflex.com
Thanks for the reply Leonid, still confused do.
I'd like to create a HTML page that will show all the standard annotations/tags but also a custom tag. From the tutorial I have:
import com.sun.javadoc.*;
public class ListClass {
public static boolean start(RootDoc root) {
String tagName = "myTag";
writeContents(root.classes(), tagName);
return htmlDoclet.start(root);
return true;
}
private static void writeContents(ClassDoc[] classes, String tagName) {
for (int i=0; i < classes.length; i++) {
boolean classNamePrinted = false;
MethodDoc[] methods = classes[i].methods();
for (int j=0; j < methods.length; j++) {
Tag[] tags = methods[j].tags(tagName);
if (tags.length > 0) {
if (!classNamePrinted) {
System.out.println("\n" + classes[i].name() + "\n");
classNamePrinted = true;
}
System.out.println(methods[j].name());
for (int k=0; k < tags.length; k++) {
System.out.println("" + tags[k].name() + ": " + tags[k].text());
}
}
}
}
}
}
Should I be extending Standard or Doclet, I tried to extend Standard but it said it couldn't find myTag.
I read a few places it's probably easier to just create the whole Doclet thing from scratch but is very time consuming and seems a bit daunting to me.
I'm probably not making much sense but I'm a bit lost with all this.
I'm sure your well aware what the above does but just in case it prints out all methods that have the tag "myTag" but it only prints that tag, example of code and output
/**
* @param args
* @author someone
* @myTaggfggff
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("\nHello12");
test test1 = new test();
}
/**
* @author someone
* @myTag myTag comments
*/
public void testMethod (){
}
/**
* @author someone
*/
public void testMethod1 (){
}
test
main
@myTag: gfggff
testMethod
@myTag: myTag comments