Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc linking to a class in another package

Tags:

java

javadoc

I have two packages, Shapes and Fruits:

com.myproject.Shapes.
    Circle
    Square
    Triangle
com.myproject.Fruits.
    Apple
    Orange

I am writing the JavaDoc for Apple and need to provide an {@link} to Square.

I have tried all of the following, and none of them work:

{@link Square}
{@link com.myproject.Square}

I've been able to find documentation for linking to: (a) classes within the same package, or (b) externals URLs, but not classes in another package.

Any ideas what the correct syntax should be? Thanks!

like image 641
IAmYourFaja Avatar asked Sep 02 '11 17:09

IAmYourFaja


People also ask

How do you refer to a class in 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.

How do you add a link to a Javadoc?

@see <a href="URL#value">label</a> : Adds a link as defined by URL#value . The URL#value is a relative or absolute URL. The Javadoc tool distinguishes this from other cases by looking for a less-than symbol ( < ) as the first character.

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.

How do you inherit Javadoc?

use {@inheritdoc} explicitly states that comments should be inherited. javadoc documentation : "insert the {@inheritdoc} inline tag in a method main description or @return , @param , or @throws tag comment. the corresponding inherited main description or tag comment is copied into that spot."


3 Answers

The correct syntax variants are

{@link [<package>.]<class>[#<method>]}
{@link #<method>}

You were missing a complete package. The following example should be correct

{@link com.myproject.Shapes.Square} 
                     ^^^^^^
like image 81
Johan Sjöberg Avatar answered Oct 12 '22 14:10

Johan Sjöberg


For another package use this syntax:

{@link  package.class#member  label}

In your case this should be:

{@link com.myproject.Shapes.Square Square}

If you want to show only the class name then use the label, if complete path is desired then label is not required.

Reference: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#link

like image 30
Pranav Shah Avatar answered Oct 12 '22 15:10

Pranav Shah


The question is pretty old, but adding another answer for anyone having similar issue.

Using @see would give you a clickable link to go to a specified class or method, given that the class, if present in another package, is imported.

In case the class / method being referred is in another module, you will have to add a dependency of that module in the current module so that @see can provide you with a clickable link.

/**
 *     @see com.myproject.Square#method(int)
 */
like image 1
sss Avatar answered Oct 12 '22 14:10

sss