Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

java - Inherit javadoc, without generating docs for inherited source

I would like class B to inherit the Javadoc from an interface that it implements, interface A. I have included the source for interface A in my Javadoc command, and class B correctly inherits the documentation.

Now I'm wondering if I can make the links it generates point to interface A's documentation on the web, rather than duplicating it on my site, i.e. the "Specified by:" links will link to an external page.

Is this possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is possible, yes. For being able to include inherited documentation, the source of interface A has to be findable in the sourcepath of javadoc, but should not be in the list of packages passed to javadoc for documentation creation. For linking, use the -link parameter. I just tried this (with the ant javadoc task):

<javadoc destdir="docs">
  <sourcepath>
    <!-- source of your class B -->
    <pathelement location="src" /> 
    <!-- source of external interface A -->
    <pathelement location="../example-src/src" />
  </sourcepath>

  <!-- your packages, to generate the docs for -->
  <package name="com.personal.myproject.*" />

  <!-- the location of the online documentation -->
  <link href="http://example.com/javadoc/"/>
</javadoc>

To command line javadoc, I think this translates like this (unix syntax, one line):

 javadoc -sourcepath ../example-src/src:src
         -d docs
         -link http://example.com/javadoc/
         -subpackages com.personal.myproject
         (other options...)

where

  • class B is in package com.personal.myproject,
  • interface A is in package com.example,
  • my own sources are in src,
  • the sources for interface A are in ../example-src/src.

In a example class created for this, javadoc would copy the documentation from A.methodName() to B.methodName(), but link to the online documentation at http://example.com/javadoc/com/example/A.html#methodName().

Thanks for asking this question, I always wanted to do this :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...