dnault / therapi-runtime-javadoc

Read Javadoc comments at run time.
Apache License 2.0
117 stars 19 forks source link

No javadoc created from constructors. #37

Closed jhameier closed 4 years ago

jhameier commented 4 years ago

Found that there is no way to pull the javadoc from a constructor.

Test Class:

/**
 * This is the class level javadoc.
 */
public class TestClass {

  /**
   * This is the ctor javadoc.
   */
  public TestClass() {}

  /**
   * This is the method javadoc.
   */
  public void testMethod() {}
}

Driver:

import com.github.therapi.runtimejavadoc.ClassJavadoc;
import com.github.therapi.runtimejavadoc.RuntimeJavadoc;

public class Test {
  public static void main(String[] args) {
    ClassJavadoc classJavadoc = RuntimeJavadoc.getJavadoc(TestClass.class);
    System.out.println(classJavadoc);
  }
}

Output

ClassJavadoc {
   name='TestClass', 
   comment=This is the class level javadoc., 
   fields=[], 
   methods=[MethodJavadoc {
                        name='testMethod', 
                        paramTypes='[]', 
                        comment=This is the method javadoc., 
                        params=[], 
                        exceptions=[],
                        other=[], 
                        returns=, 
                        seeAlso=[]
                   }], 
   seeAlso=[], 
   other=[]
}
dnault commented 4 years ago

Hi John, thanks for reporting this. It seems like a reasonable feature request.

One way to expose it would be to add a getConstructors() method to ClassJavadoc. It could probably return a List<MethodJavadoc> since there's not much difference between a Constructor and a regular method as far as Javadoc is concerned.

Out of curiosity, what is the use case for reading constructor Javadoc?

dnault commented 4 years ago

Hi John, would you be interested in submitting a pull request, either for this or #38 ? (I just want to give you an opportunity to contribute if that's something you want to do.)

jhameier commented 4 years ago

One way to expose it would be to add a getConstructors() method to ClassJavadoc

Yes that what I was thinking/hoping that it would be an easy fix since there is no real difference between a Ctor and Method javadoc.

Out of curiosity, what is the use case for reading constructor Javadoc?

We develop a dynamic aircraft simulator and optionally loaded classes are used to enhance the simulator capabilities depending on customer needs. There could be multiple constructors that are used to instantiate a single Optionally loaded class so there is a need to specifically have javadoc explaining the use of input parameters and how these affect what the optionally loaded class does.

My approach at writing javadoc for this project is to use the class level javadoc as a broad overview of what the class has to offer and ctor level javadoc is more targeted to the specifics of what the ctor offers. Using this approach and your library, I'm building documentation programatically. This allows our hands on customers to have concise documentation of extended simulator capabilities.

I used the returned javadoc to produce a markdown document and by extending the CustomFormatter, I can control some of the formatting and create well formatted documentation that is much easier to read then pure javadoc especially for non-technical folks. We also use flexmark to convert to html so that it can be read into swing components and made available at runtime in the simulator but my thought was to possibly extend the CustomFormatter and possibly even eliminate having to use that library altogether.

would you be interested in submitting a pull request

Unfortunately my schedule doesn't give me much free time these days. I'm currently working towards my Masters and simulation work has kept me quite busy over the last several months. But I will keep it in mind.

dnault commented 4 years ago

Very cool, sounds like you're working on an interesting project!

I was thinking/hoping that it would be an easy fix since there is no real difference between a Ctor and Method javadoc.

Turns out you were correct! The next release will support constructor javadoc. Release date is TBD (I want to see if it makes sense to address #38 in the same release) but should be within a few days.

dnault commented 4 years ago

@jhameier Version 0.11.0 is live on Maven Central with fixes for all of the issues you reported so far. Thanks for pushing this project forward.