Writing custom Javadoc tags (JDK 1.4)


With the Java SDK 1.4 you are allowed to provide custom tags to the javadoc tool.  One example is putting @pre and @post tags in your method headers.  We would like those tags to appear in the javadoc output just like @param and @return. Now we can!

The first step is to actually put the tag in your source code, for example:

 /**
   * Determine a birth year given an age
   *
   * @param age how old a person is in standard Earth years.
   * @pre 0 < age < 2000
   * @post none
   * @return String the year the person was born
   */
 public String findYear(int age) {}


Then invoke the javadoc command providing the -tag command line flag to specify how the custom tag is to appear in the output, for example:

javadoc -tag pre:cm:"Precondition:"  -tag post:cm:"Postcondition:"  *.java

There are three arguments to the -tag flag:
    pre    the name of the tag
    cm    code letters indicating where the tag can appear, in this case in Constructors and Methods.
   "Precondition:" the text to be placed in the output

The example will produce this output:

findYear

public java.lang.String findYear(int age)
Determine a birth year given an age

Parameters:
age - how old a person is in standard Earth years
Returns:
String the year the person was born
Precondition:
0 < age < 2000
Postcondition:
none
See the complete reference at
http://java.sun.com/j2se/1.4/docs/tooldocs/windows/javadoc.html#tag