Code in the sandbox is kept in a running state; it's tested by running the harness on the sandbox test suite file sandbox-test.xml or sandbox-api-test.xml. To extract the code for documentation, we use a tool that recognizes a sample within a source file if it has comments signalling the start and end of the sample. Keeping sample code in sync with the documentation and with the test suite specification only takes a bit of care with formatting and comments. The rest of this document tells how.
org.aspectj.internal.tools.build.SampleGatherer
(in the build module) extracts samples
of the following form from any "source" file
(currently source, html, text, and shell scripts):
... some text, possibly including @author tags {comment} START-SAMPLE [anchorName] [anchor title] {end-comment} ... sample code ... {comment} END- SAMPLE [anchorName] {end-comment} ... more text ...
Each sample extracted consists of the code and associated
attributes: the source location, the anchor name
and title, any text flagged with XXX,
and the author pulled from the closest-preceding
@author
tag. (If there is no author,
the AspectJ team is presumed.)
SampleGatherer
can render the collected
samples back out to HTML (todo: or DocBook) for
inclusion in the FAQ, the online
samples, the Programming Guide, etc.
An editor might reorder or annotate the samples
but the code should not be edited
to avoid introducing mistakes.
To help keep the sample code in sync with the docs...
before() : call(!public * com.company.library..*.*(String,..)) && within(Runnable+) { // indent once more than code // code here }
Where you put the sample code depends on how big it is and what it's for. Any code intended as an extension to the AspectJ tools goes in the api-clients/ directory. Most code will instead be samples of AspectJ programs. Subdirectories of this directory should be the base directories of different source sets. The common/ directory should work for most code snippets, but standalone, self-consistent code belongs in its own directory, as do sets pertaining to particular publications or tutorials. An example of this are the sources for the "Test Inoculated" article in the inoculated/ directory. Finally, the testsrc/ directory is reserved for code used to test the other code in the sandbox. There should be no samples under testsrc.
aspectjtools.jar
.
To keep Java/AspectJ code in sync with the tests:
language-initialization
",
<ajc-test dir="common" title="language-initialization constructor-call example"> ... </ajc-test>(Someday we'll be able to compare the test titles with the anchor names to verify that the titles contain all the anchor names.)
<compile files="declares/Declares.java, {others}" <message kind="error" line="15" text="Factory"/> </compile>Where a test case refers to a line number, we have to keep the expected message and the target code in sync. You can help with this by adding a comment in the target code so people editing the code know not to fix or move the code. E.g.,
void spawn() { new Thread(this, toString()).start(); // KEEP CE 15 declares-factory }Any good comment could work, but here are some optional conventions:
{comment} START-It will no longer be gathered, but can be fixed and reinstated.BROKEN-SAMPLE ... ... sample code ... {comment} END- BROKEN-SAMPLE ... ... more text ...
Happy coding!