Codelet: Automated insertion of already unit-tested example code (its source code, console output, and input text-files) into JavaDoc, using inline taglets--Codelet makes it possible to have always accurate documentation. As with all inline taglets, codelets are automatically processed when generating your JavaDoc. Customizations include:
| Type | Example | Description |
| {@link com.github.aliteralmind.codelet.CodeletType#SOURCE_CODE {@.codelet}} | {@code {@.codelet fully.qualified.examples.ExampleClass}} | Replaced with all source-code lines from an example code's Java file. |
| {@link com.github.aliteralmind.codelet.CodeletType#CONSOLE_OUT {@.codelet.out}} | {@code {@.codelet.out fully.qualified.examples.ExampleClass}}
or {@code {@.codelet.out fully.qualified.examples.ExampleClass("command", -1, "line", true, "params")}} |
Executes the example code, with optional command line parameters, and displays its console output. |
| {@link com.github.aliteralmind.codelet.CodeletType#SOURCE_AND_OUT {@.codelet.and.out}} | {@code {@.codelet.and.out fully.qualified.examples.ExampleClass}} | Prints both source-code and its output. |
| {@link com.github.aliteralmind.codelet.CodeletType#FILE_TEXT {@.file.textlet}} | {@code {@.file.textlet fully\qualified\examples\doc-files\input.txt}} | Replaced with all lines in a plain-text file, such as for displaying an example code's input. |
Other:
com.github.xbn.testdev.{@link com.github.xbn.testdev.VerifyApplicationOutput} to unit test applications.SourceCodeTemplate).
Codelet: Example: No customizerThis first example demonstrates a codelet with no customizer, displaying all lines, without change, followed by its output.
(This is the example class used throughout this documentation.)
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo}
Output (between the horizontal rules):
Codelet: Example: Hello Codelet!: A basic useThis displays the above example class, but eliminates its package-declaration line and all multi-line comment blocks.
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%eliminateCommentBlocksAndPackageDecl()}
Output (between the horizontal rules):
This is a simple, self-contained, compilable example, which your users can copy, paste, compile, and run.
The customizer portion, which follows the {@linkplain com.github.aliteralmind.codelet.CodeletInstance#CUSTOMIZER_PREFIX_CHAR percent sign} ({@code '%'})
eliminateCommentBlocksAndPackageDecl()
{@linkplain com.github.aliteralmind.codelet.BasicCustomizers#eliminateCommentBlocksAndPackageDecl(CodeletInstance, CodeletType) eliminates} all multi-line comments, including the license block and all JavaDoc blocks, and the package declaration line.
(This uses the {@linkplain com.github.aliteralmind.codelet.CodeletBaseConfig#DEFAULT_AND_OUT_TMPL_PATH default template}, which can be edited directly. A different template can be assigned to a single taglet by creating a custom customizer. The {@linkplain com.github.aliteralmind.codelet.TemplateOverrides template overrides} configuration file allows a different template to assigned to all taglets in a single file or entire package.)
{@code {@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%eliminateCommentBlocksAndPackageDecl()}}
is basically equivalent to all of the following:
{@.codelet com.github.aliteralmind.codelet.examples.adder.AdderDemo%eliminateCommentBlocksAndPackageDecl()}
{@.codelet.out com.github.aliteralmind.codelet.examples.adder.AdderDemo}
and
{@.file.textlet examples\com\github\aliteralmind\codelet\examples\adder\AdderDemo.java%eliminateCommentBlocksAndPackageDecl()}
{@.codelet.out com.github.aliteralmind.codelet.examples.adder.AdderDemo}
({@linkplain com.github.aliteralmind.codelet.examples.TrivialTestClassForFileTextletWithCustomizer View the above.})
and
{@.file.textlet C:\java_code\my_library\examples\com\github\aliteralmind\codelet\examples\adder\AdderDemo.java%eliminateCommentBlocksAndPackageDecl()}
{@.codelet.out com.github.aliteralmind.codelet.examples.adder.AdderDemo}
Codelet: Example: Displaying a "code snippet"An alternative to a fully-working example is to display only a portion of the example code's source, using the {@link com.github.aliteralmind.codelet.BasicCustomizers#lineRange(CodeletInstance, CodeletType, Integer, Boolean, String, Integer, Boolean, String, String) lineRange} customizer:
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%lineRange(1, false, "Adder adder", 2, false, "println(adder.getSum())", "^ ")}
Output (between the horizontal rules):
It starts with (the line containing) {@code "Adder adder"}, and ends with the second {@code "println(adder.getSum())"}. This also eliminates the extra indentation, which in this case is six spaces.
The {@code false} parameters indicate the strings are literal. {@code true} treats them as regular expressions.
Codelet: Example: Custom Customizer: Making function/constructor/class/field names into clickable JavaDoc links[Go to: Notes and debugging tips, Putting it all together, full customizer versions one, two, three]
The final example displays the same line snippet from a previous example. Since it is not possible to know what strings should be made clickable, nor the method (or constructor, class, or field) it represents, this requires a custom customizer function. As a reminder, here is the original code-snippet:
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%lineRange(1, false, "Adder adder", 2, false, "println(adder.getSum())", "^ ")}
Output (between the horizontal rules):
Our goal is to link the first constructor ({@code "Adder()"}) and {@code "getSum()"} function.
All customizer functions return a {@link com.github.aliteralmind.codelet.CustomizationInstructions} object, which is made up of:
The same filter and template as in the original example (as used by its customizer function: {@link com.github.aliteralmind.codelet.BasicCustomizers}.{@link com.github.aliteralmind.codelet.BasicCustomizers#lineRange(CodeletInstance, CodeletType, Integer, Boolean, String, Integer, Boolean, String, String) lineRange}) can also be used here:
{@link com.github.aliteralmind.codelet.NewLineFilterFor NewLineFilterFor}.{@link com.github.aliteralmind.codelet.NewLineFilterFor#lineRange(int, boolean, String, Appendable, Appendable, int, boolean, String, Appendable, Appendable, Appendable, Appendable, LengthInRange) lineRange}{@link com.github.xbn.linefilter.alter.NewTextLineAltererFor}.{@link com.github.xbn.linefilter.alter.NewTextLineAltererFor#escapeHtml() escapeHtml}(){@link com.github.aliteralmind.codelet.alter.NewLineAltererFor}.{@link com.github.aliteralmind.codelet.alter.NewLineAltererFor#eliminateIndentationOrNull(String, Appendable) eliminateIndentationOrNull}("^ ", null)
And (3) replace the {@code Adder} constructor and (4) {@code getSum()} function to JavaDoc links.To replace the {@code Adder} constructor call to a link, use
{@link com.github.aliteralmind.codelet.alter.NewJDLinkForWordOccuranceNum}.{@link com.github.aliteralmind.codelet.alter.NewJDLinkForWordOccuranceNum#constructor(CodeletInstance, int, Class, String, Appendable, Appendable, Appendable, Appendable) constructor}(instance, 1, Adder.class, "(*)", null, null)
Simlarly, here is the {@code getSum()} function link alterer:
NewJDLinkForWordOccuranceNum.{@link com.github.aliteralmind.codelet.alter.NewJDLinkForWordOccuranceNum#method(CodeletInstance, int, Class, String, Appendable, Appendable, Appendable, Appendable) method}(instance, 1, Adder.class, "getSum()", null, null)
Where {@code "getSum()"} is the function signature's {@linkplain com.github.aliteralmind.codelet.simplesig.MethodSigSearchTerm search-term}.
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%adderDemo_lineSnippetWithLinks()}
Output (between the horizontal rules):
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%com.github.aliteralmind.codelet.examples.LineRangeWithLinksCompact#adderDemo_lineSnippetWithLinks()}(In this {@code overview-summary.html} file,
{@code ":adderDemo_lineSnippetWithLinks()"}
must actually be
{@code ":com.github.aliteralmind.codelet.examples.LineRangeWithLinksCompact#adderDemo_lineSnippetWithLinks()"}
because that is the class in which the customizer function exists (is contained). In the {@linkplain com.github.aliteralmind.codelet.examples.LineRangeWithLinksCompact full example} (click the left-arrow
to return) it can be shortened to
{@code ":adderDemo_lineSnippetWithLinks()"}
because one of the default customizer classes is the one containing the taglet--if it is indeed a class.)
The full customizer function (version 1 of 3):
Notes:
<PRE> method", it is not possible to have any links, due to its limitation that all less-than characters ('<') must be html escaped.
The same function, with documentation on the available {@linkplain com.github.aliteralmind.codelet.CodeletBaseConfig#GLOBAL_DEBUG_LEVEL debugging} parameters (version 2 of 3):
And again, this time with automated {@linkplain com.github.aliteralmind.codelet.CodeletBootstrap#NAMED_DEBUGGERS_CONFIG_FILE named debuggers} (version 3 of 3, presented as a fully-working, ready-to-use class):
This requires all of the following lines to be added the named-debugger {@linkplain com.github.aliteralmind.codelet.CodeletBootstrap#NAMED_DEBUGGERS_CONFIG_FILE configuration file}:
To turn an item off, set it to {@code -1}. To turn it on, set it to zero.
LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.allalterer=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.elimindent=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.blockend.validfilter=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.blockend=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.blockstart.validfilter=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.blockstart=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.linenums=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.filter.alllines=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.constructor.searchterm.doesmatch=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.constructor.searchterm=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.constructor.validfilter=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.constructor=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.getSum.searchterm.doesmatch=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.getSum.searchterm=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.getSum.validfilter=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.link.getSum=-1 LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks.template=-1
Codelet: InstallationCodelet requires the 1.7 version of the {@code javadoc.exe} tool. The code whose JavaDoc has codelet-taglets in it has no version restrictions.
(For building, see XBN-Java's installation instructions. The Codelet build process is derived from XBN-Java's.)
View Release notes (includes downloads and release notes for all previous versions)
INSTALLATION_DIR\codelet_${jd_project_version_number}_config_and_dependency_jars\dependency_jars\*
INSTALLATION_DIR\codelet_${jd_project_version_number}-all.jar (or {@code ".jar"})
Codelet: Installation: Custom taglets and the Codelet configuration directoryExecuting {@code javadoc} in turn executes Codelet. Its four custom taglets must be registered, and the required Codelet system property must be passed to {@code javadoc.exe}:
System.getProperty("file.separator", "\\")).Executing Codelet at the command-line:
{@code javadoc -taglet com.github.aliteralmind.codelet.taglet.SourceCodeTaglet -taglet com.github.aliteralmind.codelet.taglet.SourceAndOutTaglet -taglet com.github.aliteralmind.codelet.taglet.ConsoleOutTaglet -taglet com.github.aliteralmind.codelet.taglet.FileTextTaglet -J-Dcodelet_config_dir=C:\java_code\codelet_${jd_project_version_number}\${jd_project_codelet_config_dir}\}
Information on JavaDoc's {@code -J} flag, and {@code java}'s {@code -D} flag (for the {@code -D} link, scroll down a bit).
Executing Codelet with Apache Ant:
<javadoc packagenames="my.package" sourcepath="C:\java_code\" destdir="${dir_build_docs_javadoc}"
additionalparam="-J-Dcodelet_config_dir=C:\java_code\codelet_${jd_project_version_number}\${jd_project_codelet_config_dir}\">
<taglet name="com.github.aliteralmind.codelet.taglet.SourceCodeTaglet">
<taglet name="com.github.aliteralmind.codelet.taglet.SourceAndOutTaglet">
<taglet name="com.github.aliteralmind.codelet.taglet.ConsoleOutTaglet">
<taglet name="com.github.aliteralmind.codelet.taglet.FileTextTaglet"/>
</javadoc>
This assumes that Codelet is on your Ant-classpath.
Codelet: Installation: Configuring Codelet itselfAt a minimum, the following three values must be set in {@link com.github.aliteralmind.codelet.CodeletBaseConfig codelet.properties}:
C:\java_code\project_name\${BASE}examples\\${BASE}src\\,${BASE}test\\,${BASE}examples\\