You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme-sandbox.html 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <html>
  2. <title>README - AspectJ sandbox for sample code and instructions</title>
  3. <body>
  4. <h2>README - AspectJ sandbox for sample code and instructions</h2>
  5. This directory is a place to put scraps that might end up in the
  6. AspectJ documentation or on the web site:
  7. <ul>
  8. <li>sample code for AspectJ programs,
  9. </li>
  10. <li>sample code for extensions to AspectJ tools and API's,
  11. </li>
  12. <li>sample scripts for invoking AspectJ tools, and
  13. </li>
  14. <li>documentation trails showing how to do given tasks
  15. using AspectJ, AJDT, or various IDE or deployment
  16. environments.
  17. </li>
  18. </ul>
  19. In the past, we found it tedious to keep and verify
  20. sample code used in documentation because it involves
  21. copying the code from the documentation
  22. into a form that can be tested (or vice versa).
  23. Further, there are a lot of tips and sample code
  24. contributed on the mailing lists, but they can be
  25. difficult to find when needed. This aims to be
  26. a place where such contributions can be gathered,
  27. kept in good order, and extracted for use in docs,
  28. without too much overhead.
  29. <p>
  30. Code in the sandbox is kept in a running state;
  31. it's tested by running the harness on the sandbox
  32. test suite file
  33. <a href="sandbox-test.xml">sandbox-test.xml</a>
  34. or
  35. <a href="sandbox-api-test.xml">sandbox-api-test.xml</a>.
  36. To extract the code for documentation, we use a tool
  37. that recognizes
  38. a sample within a source file if it has comments
  39. signalling the start and end of the sample.
  40. Keeping sample code in sync with the documentation
  41. and with the test suite specification only takes
  42. a bit of care with formatting and comments.
  43. The rest of this document tells how.
  44. <h3>Documenting samples</h3>
  45. <p><code>org.aspectj.internal.tools.build.SampleGatherer</code>
  46. (in the build module) extracts samples
  47. of the following form from any "source" file
  48. (currently source, html, text, and shell scripts):
  49. <pre>
  50. ... some text, possibly including @author tags
  51. {comment} START-<skipParse/>SAMPLE [anchorName] [anchor title] {end-comment}
  52. ... sample code ...
  53. {comment} END-<skipParse/>SAMPLE [anchorName] {end-comment}
  54. ... more text ...
  55. </pre>
  56. <p>
  57. Each sample extracted consists of the code and associated
  58. attributes: the source location, the anchor name
  59. and title, any text flagged with XXX,
  60. and the author pulled from the closest-preceding
  61. <code>@author</code> tag. (If there is no author,
  62. the AspectJ team is presumed.)
  63. <code>SampleGatherer</code> can render the collected
  64. samples back out to HTML (todo: or DocBook) for
  65. inclusion in the FAQ, the online
  66. samples, the Programming Guide, etc.
  67. An editor might reorder or annotate the samples
  68. but the code should not be edited
  69. to avoid introducing mistakes.
  70. <p>To help keep the sample code in sync with the docs...
  71. <ul>
  72. <li>Use comments in the sample to explain the code,
  73. rather than describing it in the documentation.
  74. </li>
  75. <li>Preformat samples to be included without modification
  76. in docs:
  77. <ul>
  78. <li>Use 4 spaces rather than a tab for each indent.
  79. </li>
  80. <li>Keep lines short - 60 characters or less.
  81. </li>
  82. <li>In Java, code taken out of context of the defining type
  83. can be indented only once in the source code,
  84. even though they might normally be indented more.
  85. </li>
  86. <li>In AspectJ, indent advice pointcuts beyond the block code:
  87. <pre>
  88. before() : call(!public * com.company.library..*.*(String,..))
  89. && within(Runnable+) { // indent once more than code
  90. // code here
  91. }
  92. </pre>
  93. </li>
  94. </ul>
  95. </li>
  96. </ul>
  97. <p>
  98. Where you put the sample code depends on how big it is
  99. and what it's for. Any code intended as an extension to
  100. the AspectJ tools goes in the <a href="api-clients">api-clients/</a>
  101. directory.
  102. Most code will instead be samples of AspectJ programs.
  103. Subdirectories of this directory should be the base directories of
  104. different source sets.
  105. The <a href="common">common/</a> directory should work for
  106. most code snippets, but standalone, self-consistent code
  107. belongs in its own directory,
  108. as do sets pertaining to particular publications or tutorials.
  109. An example of this are the sources for the "Test Inoculated"
  110. article in the <a href="inoculated">inoculated/</a> directory.
  111. Finally, the <a href="testsrc">testsrc/</a> directory is reserved for
  112. code used to test the other code in the sandbox. There should
  113. be no samples under testsrc.
  114. <h3>Testing samples</h3>
  115. We try to make sure that the samples we present to people
  116. actually work by testing each kind differently:
  117. <ul>
  118. <li>Most Java and AspectJ programs are tested using
  119. <a href="sandbox-test.xml">sandbox-test.xml</a>.
  120. </li>
  121. <li>API clients are tested using
  122. <a href="sandbox-api-test.xml">sandbox-api-test.xml</a>,
  123. which requires building <code>aspectjtools.jar</code>.
  124. </li>
  125. <li>Shell and Ant scripts should be run per instructions.
  126. </li>
  127. <li>HTML and text files must be manually reviewed.
  128. </li>
  129. </ul>
  130. When adding Java or AspectJ code, add a corresponding test case
  131. in <a href="sandbox-test.xml">sandbox-test.xml</a>.
  132. This file has the same format as other harness test suites;
  133. for more information,
  134. see <a href="../../tests/readme-writing-compiler-tests.html">
  135. ../../tests/readme-writing-compiler-tests.html</a>.
  136. The test suite should run and pass after new code is added
  137. and before samples are extracted.
  138. <p>To keep Java/AspectJ code in sync with the tests:
  139. <ul>
  140. <li>The test title should be prefixed with the anchor name and
  141. have any suffixes necessary for clarity and to make sure
  142. there are unique titles for each test.
  143. E.g., for a sample with the anchor
  144. "<code>language-initialization</code>",
  145. <pre>
  146. &lt;ajc-test
  147. dir="common"
  148. title="language-initialization constructor-call example">
  149. ...
  150. &lt;/ajc-test>
  151. </pre>
  152. (Someday we'll be able to compare the test titles with
  153. the anchor names to verify that the titles contain
  154. all the anchor names.)
  155. <p></li>
  156. <li>Avoid mixing compiler-error tests with ordinary code,
  157. so others can reuse the target code in their samples.
  158. Most of the sample code should compile.
  159. <p></li>
  160. <li>Any code that is supposed to trigger a compiler error
  161. should be tested by verifying that the error message
  162. is produced, checking either or both of the line number
  163. and the message text. E.g.,
  164. <pre>
  165. &lt;compile files="declares/Declares.java, {others}"
  166. &lt;message kind="error" line="15" text="Factory"/>
  167. &lt;/compile>
  168. </pre>
  169. Where a test case refers to a line number,
  170. we have to keep the expected message
  171. and the target code in sync.
  172. You can help with this by adding a comment in the target code
  173. so people editing the code know not to fix
  174. or move the code. E.g.,
  175. <pre>
  176. void spawn() {
  177. new Thread(this, toString()).start(); // KEEP CE 15 declares-factory
  178. }
  179. </pre>
  180. Any good comment could work, but here are some optional conventions:
  181. <p>
  182. <ul>
  183. <li>Use "CE" or "CW" for compiler error or warning, respectively.
  184. <p></li>
  185. <li>Specify the line number, if one is expected.
  186. <p></li>
  187. <li>Specify the affected test title(s) or sample code anchor label
  188. to make it easier to find the test that will break if the
  189. code is modified. (The editor can also run the tests
  190. to find any broken ones.)
  191. <p>
  192. </li>
  193. </ul>
  194. </li>
  195. </ul>
  196. If the code is broken (e.g., if it no longer works in the latest
  197. version of AspectJ), then prefix SAMPLE with BROKEN in the tag:
  198. <pre>
  199. {comment} START-<skipParse/>BROKEN-SAMPLE ...
  200. ... sample code ...
  201. {comment} END-<skipParse/>BROKEN-SAMPLE ...
  202. ... more text ...
  203. </pre>
  204. It will no longer be gathered, but can be fixed and reinstated.
  205. <p>
  206. Happy coding!
  207. <hr>
  208. </body>
  209. </html>