Question

I am trying to generate a javadoc for a program, however the entire first block is not included in the documentation. I have two class files, Item.java and Proj1.java, but neither will include the first comment block. In Item.java, it looks like this:

/************************************************************************
 * @author Namfuak
 * @version 1.0, Spring 2014
 * Class file of an Item to use in proj1.
 * Contains the name and price
 * of the item, as well as a few helpful methods.
 ************************************************************************/

import java.text.DecimalFormat;

/**
  Contains data for each Item to be tallied.  Item name and price are
  stored in private variables.
 */

What's odd is that although the second block ("Contains data...") is also outside the class scope, it is included in the documentation. I have tried reformatting the header block to not have extra stars, to not have stars beginning lines, and to be after the import statement, but the behavior does not change. I have included and not included the "-author" and "-version" tags in my command line statement, with no change. The javadoc command line output does not say there are any warnings or errors.

Was it helpful?

Solution

Because that's not recognized by the javadoc compiler.

http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#principles

Specifically:

  • The first line contains the begin-comment delimiter ( /**).
  • The last line contains the end-comment delimiter ( */) Note that unlike the begin-comment delimiter, the end-comment contains only a single asterisk.

This is why the second bit is turned into Javadoc.

Edit from comments: You can't have two blocks at the top of the class; only one is going to get used. Also, the spec states that comments before imports are ignored.

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javadoc.html#documentationcomments

Placement of comments - Documentation comments are recognized only when placed immediately before class, interface, constructor, method, or field declarations -- see the class example, method example, and field example. Documentation comments placed in the body of a method are ignored. Only one documentation comment per declaration statement is recognized by the Javadoc tool.

A common mistake is to put an import statement between the class comment and the class declaration. Avoid this, as the Javadoc tool will ignore the class comment.

The class should look like:

import java.text.DecimalFormat;
/**
 * Contains data for each Item to be tallied.  Item name and price are
 * stored in private variables.
 * @author Namfuak
 * @version 1.0, Spring 2014
 */
 public class MyClass { 

OTHER TIPS

Add the

@author Namfuak
@version 1.0, Spring 2014

in the second comment block.

It should be there, in the comments block
which is right before your class code starts.

See here for details.

JavaDoc

Also, use -author when calling the JavaDoc tool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top