Codelet (GitHub link) automates the insertion of already unit-tested example code into your JavaDoc, using taglets. As with all taglets, Codelet is executed as part of javadoc.exe. It is now released in beta.

There are four Codelet taglets:

– {@codelet.and.out}: Displays source code immediately followed by its output
– {@codelet}: Displays source code only
– {@codelet.out}: Displays output only
– {@file.textlet}: Displays the contents of any plain-text file, such as the input for an example code.

This displays the same example as above, starting with (the line containing) Adder adder, and ending with the secondprintln(adder.getSum()). This also eliminates the extra indentation, which in this case is six spaces.

Output (between the horizontal rules):

Source

It is possible to write your own customizers which, for example, can “linkify” function names, change the template in which source-and-output is displayed, and do any arbitrary alteration to any or all lines. Examples include highlighting something in yellow, or making regular expression replacements.

As a final example, and as a contrast to those above, here is the taglet that blindly prints all lines from an example code, without any changes. It uses no customizer: