Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic type <P> converted to paragraph tag in Javadoc

I have a Java class with a generic type P. I want to document it in Javadoc. Normally I just do this:

/**  * ...  * @param <P> the type of publisher  */ 

This shows up fine in actual Javadoc. However, CheckStyle is warning me that I need to document the type P because it renders <P> as a HTML paragraph. Also, the Eclipse formatter interprets it as a paragraph as well, so it messes up the formatting.

Is there a better way of documenting type parameters with type P? I know I can disable the Eclipse formatter to no longer auto format javadoc, but I'd rather not (and it wouldn't solve the checkstyle problem anyway).

I also know I can just rename P to something else, but given the number of generic types I am working with here, it would make things a lot less readable.

like image 559
David ten Hove Avatar asked Aug 21 '15 09:08

David ten Hove


People also ask

What does P mean in Javadoc?

Your use of <P> to separate paragraphs will be in line with the rest of the Javadoc output.

What is a summary Javadoc?

This new tag allows the developer to explicitly specify what portion of the Javadoc comment appears in the "summary" rather than relying on Javadoc's default treatment looking for a period and space to demarcate the end of the summary portion of the comment.

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.

Where do I put Javadoc comments?

You can place JavaDoc comments in any of three different locations in a source file: Immediately before the declaration of a public class. Immediately before the declaration of a public field. Immediately before the declaration of a public method or constructor.


2 Answers

This is a bug in CheckStyle.

The official Javadoc documentation says that notation is correct:

Example of a type parameter of a class:

 /**   * @param <E> Type of element stored in a list   */ 

If you're stuck with this version of CheckStyle, then the only way to satisfy both constraints is to rename your P type parameter to something else.

like image 53
Daniel Pryden Avatar answered Sep 25 '22 12:09

Daniel Pryden


FOR POSTERITY: Turns out Checkstyle handles it just fine. The problem is that the whitespace added by the Eclipse formatter made Checkstyle (reasonably) argue that the Javadoc was incorrect. I also found an existing bug report for this bug in Eclipse: https://bugs.eclipse.org/bugs/show_bug.cgi?id=121728

like image 34
David ten Hove Avatar answered Sep 22 '22 12:09

David ten Hove