(Note: this is not the same question as to where to put the annotation or how to document the annotation itself)
When a piece of documented code is decorated with an annotation, this
annotation usually shows up in the generated javadocs (for @Documented
annotations).
But what if I'd like to add some reasoning to the javadoc? (why is the annotation needed
for this piece of code?)
There are two ways that come to my mind, but both are not ideal.
/**
* My piece of code.<p>
* Why @MyAnnotation is needed
*/
@MyAnnotation
public void pieceOfCode() {
This way the reason appears in the generated javadoc, but not together with the annotation itself.
/**
* My piece of code.
*/
// Why @MyAnnotation is needed
@MyAnnotation
public void pieceOfCode() {
Like that the reason is very close to the annotation itself (less chance to get lost in a refactoring), but doesn't appear in the generated javadocs.
What I would like is something like the @param
javadoc tag for annotations, e.g. @ann
:
/**
* My piece of code.
* @ann MyAnnotation There's a reason
*/
@MyAnnotation
public void pieceOfCode() {
For @Documented
annotations I'd then expect the comment at the @ann
tag to appear in the generated javadocs together with the mentioning of the annotation itself.
Is there a proper way do comment annotations? Are there any other javadoc tags that could help?