See: Description
| Package | Description |
|---|---|
| com.github.aliteralmind.codelet |
Main package.
|
| com.github.aliteralmind.codelet.alter |
Classes related to the alteration-portion of a customizer function.
|
| com.github.aliteralmind.codelet.simplesig |
Generically-useful utilities for searching among methods with parameter wildcards, and for specifying and invoking "simplified" method signatures, which accept only primitives and non-null strings.
|
| com.github.aliteralmind.codelet.taglet |
The only part of Codelet that depends on
com.sun.javadoc. |
| com.github.aliteralmind.codelet.type |
Type-specific taglet-processors and templates.
|
| com.github.aliteralmind.codelet.util |
Generically-useful classes for blacklisting file names, accessing Java-related files given its base-directory and fully-qualified name, and JavaDoc related utilities.
|
| Package | Description |
|---|---|
| com.github.aliteralmind.codelet.examples |
Full examples used throughout Codelet.
|
| com.github.aliteralmind.codelet.examples.adder |
Trivial classes used in Codelet examples.
|
| com.github.aliteralmind.codelet.examples.for_testing_only | |
| com.github.aliteralmind.codelet.examples.non_xbn |
Example code demonstrating Codelet-like functionality, but that does not use any
com.github.aliteralmind.codelet classes. |
| com.github.aliteralmind.codelet.examples.simplesig |
Example code demonstrating the classes in
com.github.aliteralmind.codelet.simplesig. |
| com.github.aliteralmind.codelet.examples.util |
Example code demonstrating the classes in
com.github.aliteralmind.codelet.util. |
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:
doctest module (along with reStructuredText and Sphinx),
| Type | Example | Description |
{@.codelet} |
{@.codelet fully.qualified.examples.ExampleClass} |
Replaced with all source-code lines from an example code's Java file. |
{@.codelet.out} |
{@.codelet.out fully.qualified.examples.ExampleClass}
or {@.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. |
{@.codelet.and.out} |
{@.codelet.and.out fully.qualified.examples.ExampleClass} |
Prints both source-code and its output. |
{@.file.textlet} |
{@.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. |
CustomizationInstructions object (line filter, alterer, template)Other:
com.github.xbn.testdev.VerifyApplicationOutput to unit test applications.Known issues, and major to-dos
SourceCodeTemplate). javadoc.exe, although this does not affect reliability. It is likely an issue that won't go away.
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):
/*license*\
Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com)
This software is dual-licensed under the:
- Lesser General Public License (LGPL) version 3.0 or, at your option, any later version;
- Apache Software License (ASL) version 2.0.
Either license may be applied at your discretion. More information may be found at
- http://en.wikipedia.org/wiki/Multi-licensing.
The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at:
- LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
- ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
\*license*/
package com.github.aliteralmind.codelet.examples.adder;
/**
<p>Demonstration of {@code com.github.aliteralmind.codelet.examples.adder.Adder}.</p>
<p>{@code java com.github.aliteralmind.codelet.examples.AdderDemo}</p>
* @since 0.1.0
* @author Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a>
**/
public class AdderDemo {
public static final void main(String[] ignored) {
Adder adder = new Adder();
System.out.println(adder.getSum());
adder = new Adder(5, -7, 20, 27);
System.out.println(adder.getSum());
}
}
Output:
0 45
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):
public class AdderDemo {
public static final void main(String[] ignored) {
Adder adder = new Adder();
System.out.println(adder.getSum());
adder = new Adder(5, -7, 20, 27);
System.out.println(adder.getSum());
}
}
Output:
0 45
This is a simple, self-contained, compilable example, which your users can copy, paste, compile, and run.
The customizer portion, which follows the percent sign ('%')
eliminateCommentBlocksAndPackageDecl()
eliminates all multi-line comments, including the license block and all JavaDoc blocks, and the package declaration line.
(This uses the default template, which can be edited directly. A different template can be assigned to a single taglet by creating a custom customizer. The template overrides configuration file allows a different template to assigned to all taglets in a single file or entire package.)
{@.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}
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 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):
Adder adder = new Adder(); System.out.println(adder.getSum()); adder = new Adder(5, -7, 20, 27); System.out.println(adder.getSum());
Output:
0 45
It starts with (the line containing) "Adder adder", and ends with the second "println(adder.getSum())". This also eliminates the extra indentation, which in this case is six spaces.
The false parameters indicate the strings are literal. 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):
Adder adder = new Adder(); System.out.println(adder.getSum()); adder = new Adder(5, -7, 20, 27); System.out.println(adder.getSum());
Output:
0 45
Our goal is to link the first constructor ("Adder()") and "getSum()" function.
All customizer functions return a CustomizationInstructions object, which is made up of:
The same filter and template as in the original example (as used by its customizer function: ) can also be used here:BasicCustomizers.lineRange
NewLineFilterFor.lineRangeNewTextLineAltererFor.escapeHtml()NewLineAltererFor.eliminateIndentationOrNull("^ ", null)
And (3) replace the Adder constructor and (4) getSum() function to JavaDoc links.To replace the Adder constructor call to a link, use
NewJDLinkForWordOccuranceNum.constructor(instance, 1, Adder.class, "(*)", null, null)
1 indicates the first occurance of "Adder(" should be linked,"(*)" is the constructor's parameter-list search-term, in this case meaning one or more of any type,Adder.class is the link-target class, andnull parameters are for optional debugging. Possible values include:null: No debugging is outputSystem.out: Prints to the console.getDebugApblIfOn(3, instance)
getDebugApblIfOn(instance, "Adder.constructor.link.replacer")
"Adder.constructor.link.replacer" is active. Making a named debug level active is done by setting it to either zero, or to a number less-than-or-equal to the current debugging level.Simlarly, here is the getSum() function link alterer:
NewJDLinkForWordOccuranceNum.method(instance, 1, Adder.class, "getSum()", null, null)
Where "getSum()" is the function signature's search-term.
The taglet:
{@.codelet.and.out com.github.aliteralmind.codelet.examples.adder.AdderDemo%adderDemo_lineSnippetWithLinks()}
Output (between the horizontal rules):
Adder adder = new Adder(); System.out.println(adder.getSum()); adder = new Adder(5, -7, 20, 27); System.out.println(adder.getSum());
Output:
0 45
(In this overview-summary.html file,
":adderDemo_lineSnippetWithLinks()"
must actually be
":com.github.aliteralmind.codelet.examples.LineRangeWithLinksCompact#adderDemo_lineSnippetWithLinks()"
because that is the class in which the customizer function exists (is contained). In the full example (click the left-arrow
to return) it can be shortened to
":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):
private static final CustomizationInstructions<SourceCodeTemplate> adderDemo_lineSnippetWithLinks(CodeletInstance instance, CodeletType needed_defaultAlterType) {
FilteredLineIterator filter = NewLineFilterFor.lineRange(
1, false, "Adder adder", null, null,
2, false, "println(adder", null, null,
null, null, null);
TextLineAlterer[] alterers = {
NewTextLineAltererFor.escapeHtml(),
NewLineAltererFor.eliminateIndentationOrNull("^ ", null),
NewJDLinkForWordOccuranceNum.constructor(instance,
1, Adder.class, "(*)", null, null, null, null),
NewJDLinkForWordOccuranceNum.method(instance,
1, Adder.class, "getSum()", null, null, null, null)};
return new CustomizationInstructions<SourceCodeTemplate>(instance,
needed_defaultAlterType).
filter(filter).
orderedAlterers(null, NullElement.OK, ExpirableElements.OPTIONAL,
MultiAlterType.CUMULATIVE, alterers).
defaultOrOverrideTemplate(null).
build();
}
Notes:
CodeletInstance and com.github.aliteralmind.codelet.CodeletType are required as the first and second parameters in all customizer functions. Both are ommitted from all taglet-calls.<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 debugging parameters (version 2 of 3):
private static final CustomizationInstructions<SourceCodeTemplate> adderDemo_lineSnippetWithLinks(CodeletInstance instance, CodeletType needed_defaultAlterType) {
FilteredLineIterator filter = NewLineFilterFor.lineRange(
1, false, "Adder adder",
null, //debugStartFilter: on=System.out, off=null
null, //dbgStart
2, false, "println(adder",
null, //dbgEndFilter
null, //dbgEnd
null, //dbgLineNums
null, null); //dbgAllLines and its range
TextLineAlterer[] alterers = {
NewTextLineAltererFor.escapeHtml(),
NewLineAltererFor.eliminateIndentationOrNull("^ ",
null), //debug
NewJDLinkForWordOccuranceNum.constructor(instance,
1, Adder.class, "(*)",
null, //dbgRplcr
null, //dbgFilter
null, //dbgSearchTerm
null), //dbgSearchTermDoesMatch
NewJDLinkForWordOccuranceNum.method(instance,
1, Adder.class, "getSum()",
null, //dbgRplcr
null, //dbgFilter
null, //dbgSearchTerm
null)}; //dbgSearchTermDoesMatch
return new CustomizationInstructions<SourceCodeTemplate>(instance,
needed_defaultAlterType).
filter(filter).
orderedAlterers(
null, //debug
NullElement.OK, ExpirableElements.OPTIONAL,
MultiAlterType.CUMULATIVE, alterers).
defaultOrOverrideTemplate(
null). //debug
build();
}
And again, this time with automated named debuggers (version 3 of 3, presented as a fully-working, ready-to-use class):
import com.github.aliteralmind.codelet.CodeletInstance;
import com.github.aliteralmind.codelet.CodeletType;
import com.github.aliteralmind.codelet.CustomizationInstructions;
import com.github.aliteralmind.codelet.alter.NewJDLinkForWordOccuranceNum;
import com.github.aliteralmind.codelet.alter.NewLineAltererFor;
import com.github.aliteralmind.codelet.NewLineFilterFor;
import com.github.aliteralmind.codelet.examples.adder.Adder;
import com.github.xbn.linefilter.alter.NewTextLineAltererFor;
import com.github.xbn.linefilter.alter.TextLineAlterer;
import com.github.xbn.linefilter.FilteredLineIterator;
import com.github.aliteralmind.codelet.type.SourceCodeTemplate;
import com.github.xbn.analyze.alter.ExpirableElements;
import com.github.xbn.analyze.alter.MultiAlterType;
import com.github.xbn.array.NullElement;
import static com.github.aliteralmind.codelet.CodeletBaseConfig.*;
public class LineRangeWithLinksAndNamedDebugs {
private static final CustomizationInstructions<SourceCodeTemplate> adderDemo_lineSnippetWithLinks(CodeletInstance instance, CodeletType needed_defaultAlterType) {
String debugPrefix = "LineRangeWithLinksAndNamedDebugs.adderDemo_lineSnippetWithLinks";
FilteredLineIterator filter = NewLineFilterFor.lineRange(instance, debugPrefix,
1, false, "Adder adder",
2, false, "println(adder");
TextLineAlterer[] alterers = {
NewTextLineAltererFor.escapeHtml(),
NewLineAltererFor.eliminateIndentationOrNull("^ ",
getDebugApblIfOn(instance, debugPrefix + ".elimindent")),
NewJDLinkForWordOccuranceNum.constructor(instance, debugPrefix, null,
1, Adder.class, "(*)"),
NewJDLinkForWordOccuranceNum.method(instance, debugPrefix, null,
1, Adder.class, "getSum()")};
return new CustomizationInstructions<SourceCodeTemplate>(instance,
needed_defaultAlterType).
filter(filter).
orderedAlterers(getDebugApblIfOn(instance, debugPrefix + ".allalterer"),
NullElement.OK, ExpirableElements.OPTIONAL,
MultiAlterType.CUMULATIVE, alterers).
defaultOrOverrideTemplate(
getDebugApblIfOn(instance, debugPrefix + ".template")).
build();
}
}
This requires all of the following lines to be added the named-debugger configuration file:
To turn an item off, set it to -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: InstallationThis version is 0.1.4.1
aliteralmind.comCodelet requires the 1.7 version of the 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.)
<dependency> <groupId>com.github.aliteralmind</groupId> <artifactId>codelet</artifactId> <version>0.1.4.1</version> </dependency>
View Release notes (includes downloads and release notes for all previous versions)
codelet_0.1.4.1-all.jar: Core classes, example code, and unit tests: local copy, aliteralmind.comcodelet_0.1.4.1.jar: Core classes only: local copy, aliteralmind.comcodelet_0.1.4.1_config_and_dependency_jars.jar: All external jars required to use Codelet, including tools.jar from the JDK 1.7_51, which contains com.sun.javadoc and com.sun.tools.doclets: local copy, aliteralmind.comcodelet_0.1.4.1-sources.jar: Source code, including all files necessary for building Codelet: local copy, aliteralmind.comcodelet_0.1.4.1-javadoc.jar: JavaDoc documentation for local installation: local copyaliteralmind.comcodelet_0.1.4.1_config_and_dependency_jars.zip (download link above) to your classpath:
INSTALLATION_DIR\codelet_0.1.4.1_config_and_dependency_jars\dependency_jars\* INSTALLATION_DIR\codelet-0.1.4.1-all.jar
(or codelet-0.1.4.1.jar)
javadoc to recognize Codelet taglets
Codelet: Installation: Custom taglets and the Codelet configuration directoryExecuting javadoc in turn executes Codelet. Its four custom taglets must be registered, and the required Codelet system property must be passed to javadoc.exe:
codelet_config_dir: The path to the directory in which all Codelet configuaration files exist. Must end with a file-separator (the value returned by System.getProperty("file.separator", "\\")).Executing Codelet at the command-line:
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_0.1.4.1\codelet_config\
Information on JavaDoc's -J flag, and java's -D flag (for the -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_0.1.4.1\codelet_config\"> <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 codelet.properties:
base_dir_base_dir: The root directory on which all other directory values are based on. This is used by other values with ${BASE}. Example value:
C:\java_code\project_name\example_class_src_base_dir: The directory in which the top-most package name of all example code resides. Example value
${BASE}examples\\enclosing_class_src_base_dirs: The directory in which the top-most package name of all codelet-taglet containing classes reside. Example value
${BASE}src\\,${BASE}test\\,${BASE}examples\\Copyright 2014, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.
https://github.com/aliteralmind/codelet