I've been searching for an answer for several months and I have tried multiple things, including unzipping the Compressed folder src.zip and using it as a parameter for Javadoc (for example: javadoc -sourcepath src com.example.test
)
This is the default Javadoc that comes with the JDK 6 Update 24.
Let's say that I'm working on a new map that implements the java.util.Map
interface. By default the methods that I override from the Map interface should inherit the documentation from the interface, if I'm not mistaken. However, javadoc never does it.
The only thing that has worked this problem out so far, has been actually javadoc-ing the classes written by Java (for example: javadoc com.example.text java.util
). I don't want to do this because it makes it seem like I rewrote the Java classes, but is this the only way to do it? If it is I suppose I could just live with it, but it was my understanding that there was another way to do this.
Thank you =) I'm sorry if this is a little messy. This is my first time using Stack Overflow. I'm also sorry if this question has been asked already. I have read many similar questions by they don't cover everything that I wanted to ask and I've found them very confusing because they involve writing your own implementation of Javadoc. Anyway, thank you in advanced =)
All right =) If I understand correctly, you would like to see an example. This is a simpler example that I tried to see if it was because I was trying something that shouldn't work.
package com.example;
/**
* A simple class that returns an upper-case string representation.
*/
public class UpperCaseObject {
@Override public int hashCode() {
return super.hashcode();
}
/**
* {@inheritDoc}
*
* <P>The {@code toString} method for class {@code UpperCaseObject} returns
* converted to uppercase.</P>
*
* @see String#toUpperCase()
*/
@Override public String toString() {
return super.toString().toUpperCase();
}
}
I moved this example (file name is UpperCaseObject.java
) into a directory javadoc-test/com/example
and I also made another directory javadoc-test/java/lang
, placing Object.java
(from src.zip) in it.
The call to javadoc that I made was javadoc -link http://download.oracle.com/javase/6/docs/api/ com.example
from the directory javadoc-test
. I have the jdk6 bin directory in my path parameter.
The two things that I expected was for UpperCaseObject.hashCode
to inherit all of the documentation, and UpperCaseObject.toString
everything before the extra paragraph from java.lang.Object
. However, unfortunately, I didn't get any of the documentation.
Well, what I had to do was the following. It is just a simple workaround.
Unfortunately, I can only do a work around for now, but I'm convinced that it may be a problem with my version of Java. It sounds like other people have had a similar problem and came up with their own workarounds. This is just my own =)
I'll still be taking answers, but this is the most convenient option in the meanwhile. Thank you very much!
One thing you can do is link to the official Javadoc for those classes, using the -link
option:
javadoc -sourcepath src -link http://download.oracle.com/javase/6/docs/api com.example.test
This will allow Javadoc to treat the classes of the SDK as "external referenced classes". From the Javadoc documentation:
The referenced classes whose documentation is not being generated during a javadoc run. In other words, these classes are not passed into the Javadoc tool on the command line. Links in the generated documentation to those classes are said to be external references or external links. For example, if you run the Javadoc tool on only the java.awt package, then any class in java.lang, such as Object, is an external referenced class. External referenced classes can be linked to using the -link and -linkoffline options. An important property of an external referenced class is that its source comments are normally not available to the Javadoc run. In this case, these comments cannot be inherited.
Note that the Javadoc for these class will still not be inherited. However, you can now link to it, like so:
public class MyMap implements java.util.Map {
...
/**
* @see java.util.Map#isEmpty()
*/
@Override
public boolean isEmpty() {
...
}
}
[EDIT]
The @see
tag is there for illustration. Javadoc should automatically generate a "Specified By" link, so you could omit the Javadoc comment altogether.
The source file for the inherited method needs to be on the -sourcepath of the javadoc tool when it runs. You don't need to pass the inherited class on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With