Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom javadoc tags?

Tags:

java

javadoc

How do I create custom javadoc tags such as @pre / @post? I found some links that explain it but I haven't had luck with them. These are some of the links:

http://www.developer.com/java/other/article.php/3085991/Javadoc-Programming.html

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html

like image 357
Carlos Avatar asked Apr 20 '10 18:04

Carlos


People also ask

Can you use HTML tags in Javadoc comments?

There are no real restrictions on the use of HTML in Javadoc comments. The Javadoc documentation states: Comments are written in HTML - The text must be written in HTML, in that they should use HTML entities and can use HTML tags.

How do you write a Javadoc comment?

Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.

Is Javadoc still used?

Javadoc is pretty much the accepted standard for documenting java code.


2 Answers

java code

/**  * @custom.mytag hey ho...  */ 

java doc option

-tag custom.mytag:a:"This is my Tag:" 

output

This is my Tag:

hey ho...

like image 87
appsthatmatter Avatar answered Sep 22 '22 08:09

appsthatmatter


Custom tags should not be created using HTML because javadoc might change it's implementation or how it presents data, maybe they'll start using Markdown in the future, also the Javadoc exporter will not catch missing information and you might have empty "tags".

First use whatever tag you want:

/**  * Comments and a {@link #methodLink} for this method.  *   * @tt.wrapper {@link OtherClass}  *  */ public String extractName() {     // method contents } 

Notice that the custom tag has the format @[prefix].[tagName], this is due to the fact that doclet (or another Eclipse plugin) might release it's own tag with the same name, and your tag would just override the standard tag, so we add a prefix to make it less likely of that happening.

Comment from doclet.

Custom tags that could override future standard tags: @wrapper To avoid potential overrides, use at least one period character (.) in custom tag names.


Now you have to tell the Javadoc exporter about this custom tag, @tt.wrapper. Go to Project > Generate Javadoc.. in Eclipse (Indigo in my case).

After configuring the settings for the first two screens of this dialog (using "Next" to change screens) you should see this screen:

Third configuration screen for Eclipse Doclet Javadoc Export

You should notice that the "Extra Javadoc options.." text box has the value you must add for the Javadoc exporter to create the HTML equivalent of your tag.

In our case the option is this (if you want multiple tags, put them on a new line):

-tag tt.wrapper:a:"API Wrapper:" 

Now when you export your Javadoc (I also recommend saving an ANT script so you don't have to go through this dialog every time) you will have your custom tag in bold with the description, and the values underneath.

P.S. I have yet to find a way to add the ability to add auto-completion for the custom tags, but it seems impossible in Indigo, maybe it'll be in future releases (not sure if Juno has it).

like image 45
knownasilya Avatar answered Sep 21 '22 08:09

knownasilya