Integrated: 8308715: Create a mechanism for Implicitly Declared Class javadoc

Pavel Rappo prappo at openjdk.org
Tue Dec 5 22:11:48 UTC 2023


On Tue, 28 Nov 2023 14:32:14 GMT, Pavel Rappo <prappo at openjdk.org> wrote:

> Please review this PR to support _JEP 463 Implicitly Declared Classes and Instance Main Method (Second Preview)_ in JavaDoc.
> 
> [JEP 463](https://openjdk.org/jeps/463) is the next iteration of [JEP 445](https://openjdk.org/jeps/445), which introduced the ability to have a source file as a launchable, "classless" method bag
> 
> 
> % cat HelloWorld.java
> /** Run me. */
> void main() {
>     print("Hello, world!");
> }
> 
> /** Shortcut for printing strings. */
> void print(String arg) {
>     System.out.println(arg);
> }
> 
> 
> which the compiler interprets as a familiar class
> 
> 
> final class HelloWorld {
> 
>     HelloWorld() {
>     }
> 
>     /** Run me. */
>     void main() {
>         print("Hello, world!");
>     }
> 
>     /** Shortcut for printing strings. */
>     void print(String arg) {
>         System.out.println(arg);
>     }    
> }
> 
> 
> ### How JEP 445 works with JavaDoc today
> 
> In JDK 21, javadoc can document such a file **without any changes to the javadoc tool**. The only thing that the user needs to do is to make sure that the following options are present:
> 
> * `--enable-preview` and `--source=21`
> * `-package`
> 
> The first pair of options tells javadoc to use preview features, which JEP 445 is one of. Without these preview-related options, javadoc will raise the following error:
> 
> 
> % javadoc --version
> javadoc 21
> 
> % javadoc HelloWorld.java -d /tmp/throwaway
> Loading source file HelloWorld.java...
> HelloWorld.java:2: error: unnamed classes are a preview feature and are disabled by default.
> void main() {
> ^
>   (use --enable-preview to enable unnamed classes)
> 1 error
> 
> 
> The second option, `-package`, tells javadoc to document classes that are public, protected, or declared with package access (colloquially known as "package private"). Without this option, javadoc will only document public and protected classes, which do not include the interpreted class:
> 
> 
> % javadoc --enable-preview --source=21 HelloWorld.java -d /tmp/throwaway
> Loading source file HelloWorld.java...
> Constructing Javadoc information...
> error: No public or protected classes found to document.
> 1 error
> 
> 
> When those additional options are present, javadoc does its job:
> 
> 
> % javadoc --enable-preview --source=21 -package HelloWorld.java -d /tmp/throwaway
> Loading source file HelloWorld.java...
> Constructing Javadoc information...
> Creating destination directory: "/tmp/throwaway/"
> Building index for all the packages and classes...
> Standard Doclet version 21+35-LTS-2513
> Building tree for all the packages and classes...
> Generating /tmp/throwaway/HelloWorld.htm...

This pull request has now been integrated.

Changeset: 430564cf
Author:    Pavel Rappo <prappo at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/430564cf8882e9acf86a193eb76030c6254f798c
Stats:     238 lines in 5 files changed: 231 ins; 0 del; 7 mod

8308715: Create a mechanism for Implicitly Declared Class javadoc

Reviewed-by: jjg

-------------

PR: https://git.openjdk.org/jdk/pull/16853


More information about the javadoc-dev mailing list