Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc reference param from another method

Tags:

java

javadoc

I don't want to write redundant javadoc comments. As you can see, @param x is in a way redundant. Is there a javadoc markup to set a reference from @param x in class B to @param x in class A or am I allowed to just leave it out?

/**
 * Class A constructor
 * 
 * @param x  position on x-axis
 */
public A(final int x) {
    this.x = x;
}

/**
 * Class B constructor
 * 
 * @param x  position on x-axis
 * @param y  position on y-axis
 */
public B(final int x, final int y) {
    super(x);
    this.y = y
}
like image 754
Matthias Avatar asked Mar 09 '11 21:03

Matthias


People also ask

How do you reference another Javadoc?

Javadoc provides the @link inline tag for referencing the members in the Java classes. We can think of the @link tag as similar to the anchor tag in HTML, which is used to link one page to another via hyperlinks. Similar to the anchor tag, the path_to_member is the destination, and the label is the display text.

What does @SEE mean in Javadoc?

In short, we use the @see tag when we want a link or a text entry that points to a reference. This tag adds a “See Also” heading to the reference. A document comment can hold any number of @see tags, all of which can be grouped under the same heading.

What does @param mean in Javadoc?

@param is a special format comment used by javadoc to generate documentation. it is used to denote a description of the parameter (or parameters) a method can receive.

What is @link in Java comments?

For Javadoc 1.2 and later, the standard format is to use @deprecated tag and the in-line {@link} tag. This creates the link in-line, where you want it. For example: /** * @deprecated As of JDK 1.1, replaced by * {@link #setBounds(int,int,int,int)} */


2 Answers

You can't leave it out, javadoc isn't smart, it just parses the comments, he can't say that the x parameter for the B constructor is the same than the A constructor even if there is inheritance in play.

I don't think there's a way to "factorize" this either. You'll just have to write all of them, sorry...

like image 156
krtek Avatar answered Sep 27 '22 16:09

krtek


With methods it should work: if you overwrite or implement a method, the parameters are copied if not provided.

Constructors are not inherited, and even less to a constructor with other parameter types. Javadoc has no way to know that you pass the parameter to another constructor, since it does not interpret the contents of the methods/constructors, only the outer interface.

So, I suppose you are out of luck, if you don't want to write your own doclet or change the standard doclet (and even then you would have to somehow say which constructor to inherit the params from). (This would be a useful addition, also for multiple similar methods in the same class, I think.)

like image 41
Paŭlo Ebermann Avatar answered Sep 27 '22 16:09

Paŭlo Ebermann