Is there a way to create a Javadoc for a subset of public methods? For example, annotating public methods as "not part of the public API",

I know how to create Javadoc for a subset of classes / interfaces / packages. But is there a way to create Javadoc only for a subset of public methods?

What I would prefer is the ability to mark methods (Javadoc tag or annotation) as belonging to a specific API or not be part of it. Then create a tool that creates Javadoc only for the specified set of methods - those that form the API.

Choosing between public / private / batch method access is not enough for my project. The public method may or may not belong to the public API, or it may belong to API 1, but not API 2. In fact, I would like to be able to select an API from an arbitrary subset of my public methods.

+7
source share
2 answers

If you use the javadoc command-line tool, you can exclude public methods by marking them as Deprecated and using the -nodeprecated parameter. But if you want something more complex, you will have to implement it yourself.

A rough idea on how to do this:

  • Create custom annotations @ API1, @ API2, etc.
  • Classify your methods using these annotations (i.e. mark them)
  • Write a custom Ant task that reads a configuration parameter (for example, from a file) that tells which API you want to generate Javadoc for.
  • Still in the Ant task, loop through the annotated methods and replace any API annotations that are NOT the selected API with deprecated annotation. This excludes them from Javadoc.

IMHO, this is a lot of trouble. As they said in the comments, if you have a class with multiple interfaces (for different user profiles, I think?), Consider writing separate interfaces.

+2
source

If you are not tied to javadoc, you can try Doxygen with conditional sections :

 public class SomeClass { /// @cond API1 /** * This method can be called as part of API1 only. */ public void method() { ... } /// @endcond /// @cond (API1 || API2) /** * This method can be called as part of API1 or API2. */ public void method2() { ... } /// @endcond } 

When you group methods appropriately, you can also limit the number of @cond statements @cond .

When creating documentation, the following methods can be selected that can be included in the ENABLED_SECTIONS configuration.

+2
source

All Articles