Wednesday, September 27, 2006

Some conventions for Javadoc comments

I'm learning to use Java dev under Eclipse JDT these days and I find one interesting function -- JavaDOC. When in Delphi environment, I had to recompose all the explaintive documents after a new class established or some methods updated. It did take a lot of time to deal with the task.
However, in JavaDoc, the document is automatically generated upon some formatted comments. This is convenient. I searched for some conventions of writing effective and effecient javadoc comments and here are some main points:


the following contents are abstracted from SDN references:
Order of Block Tags
Include block tags in the following order:
* @param       (classes, interfaces, methods and constructors only)
* @return (methods only)
* @exception (@throws is a synonym added in Javadoc 1.2)
* @author (classes and interfaces only, required)
* @version (classes and interfaces only, required. See footnote 1)
* @see
* @since
* @serial (or @serialField or @serialData)
* @deprecated (see How and When To Deprecate APIs)

Ordering Multiple Instances of Same Tags

Multiple @author tags should be listed in chronological order, with the creator of the class listed at the top.

Multiple @param tags should be listed in argument-declaration order. This makes it easier to visually match the list to the declaration.

Multiple @throws tags (also known as @exception) should be listed alphabetically by the exception names.

Multiple @see tags should be ordered as follows:

   @see #field
@see #Constructor(Type, Type...)
@see #Constructor(Type id, Type id...)
@see #method(Type, Type,...)
@see #method(Type id, Type, id...)
@see Class
@see Class#field
@see Class#Constructor(Type, Type...)
@see Class#Constructor(Type id, Type id)
@see Class#method(Type, Type,...)
@see Class#method(Type id, Type id,...)
@see package.Class
@see package.Class#field
@see package.Class#Constructor(Type, Type...)
@see package.Class#Constructor(Type id, Type id)
@see package.Class#method(Type, Type,...)
@see package.Class#method(Type id, Type, id)
@see package

Required Tags
@param tag is "required" (by convention) for every parameter, even when the description is obvious.

@return tag is required for every method that returns something other than void, even if it is redundant with the method description. (Whenever possible, find something non-redundant (ideally, more specific) to use for the tag comment.)

Complete document on this topic can be found here:
How to Write Doc Comments for the Javadoc Tool