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.

ajc.xml 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <refentry id="ajc-ref" xreflabel="The ajc Command-line Reference">
  2. <refnamediv>
  3. <refname>ajc</refname>
  4. <refpurpose>compiler and bytecode weaver for the AspectJ and Java languages</refpurpose>
  5. </refnamediv>
  6. <refsynopsisdiv>
  7. <cmdsynopsis>
  8. <command>ajc</command>
  9. <arg><replaceable>Options</replaceable></arg>
  10. <group>
  11. <arg><replaceable>file...</replaceable></arg>
  12. <arg>@<replaceable>file...</replaceable></arg>
  13. <arg>-argfile <replaceable>file...</replaceable></arg>
  14. </group>
  15. </cmdsynopsis>
  16. </refsynopsisdiv>
  17. <refsect1 id="ajc" xreflabel="ajc">
  18. <title>Description</title>
  19. <para>The <command>ajc</command> command compiles AspectJ and Java
  20. language files, weaving aspects as necessary to produce .class files
  21. compliant with any Java VM (1.1 or later).
  22. To do bytecode weaving, it also accepts input classes or aspects
  23. in binary form.
  24. </para>
  25. <para> The arguments after the options specify the source file(s) to compile.
  26. (Specify source classes using the <parameter>-injars</parameter> or
  27. <parameter>-inpath</parameter> options, below.)
  28. Files may be listed directly on the command line, or listed in a file.
  29. The <parameter>-argfile <replaceable>file</replaceable></parameter>
  30. and <parameter>@<replaceable>file</replaceable></parameter> forms
  31. are equivalent, and are interpreted as meaning all the files listed in
  32. the specified file. Each line in these files should contain one option
  33. or filename. Comments, as in Java, start with <literal>//</literal> and
  34. extend to the end of the line.
  35. </para>
  36. <para>
  37. <command>NB:</command>
  38. You must explicitly pass <command>ajc</command> all sources necessary
  39. for the compilation. When compiling source files containing aspects
  40. or pointcuts, be sure
  41. to include the source files for any types affected by the aspects or
  42. picked out by the pointcuts.
  43. (To exclude types from the scope affected by the aspect,
  44. change the corresponding pointcut or declaration.)
  45. This is necessary because, unlike javac, ajc does not search the
  46. sourcepath for classes.
  47. You may use the <parameter>-sourceroots</parameter> option to specify
  48. as source all the .aj and .java files in a set of directory trees.
  49. </para>
  50. <refsect2>
  51. <title>Options</title>
  52. <variablelist>
  53. <varlistentry>
  54. <term>-injars <replaceable>JarList</replaceable></term>
  55. <listitem><para>
  56. deprecated: since 1.2, use -inpath, which also takes
  57. directories.
  58. </para></listitem>
  59. </varlistentry>
  60. <varlistentry>
  61. <term>-inpath <replaceable>Path</replaceable></term>
  62. <listitem><para>
  63. Accept as source bytecode any .class files in the
  64. .jar files or directories on Path.
  65. The output will include these
  66. classes, possibly as woven with any applicable aspects.
  67. Path is a single argument containing
  68. a list of paths to zip files or directories,
  69. delimited by the platform-specific path delimiter.
  70. </para></listitem>
  71. </varlistentry>
  72. <varlistentry>
  73. <term>-aspectpath <replaceable>JarList</replaceable></term>
  74. <listitem><para>
  75. Weave binary aspects from JarList zip files into all sources.
  76. The aspects should have been output by the same version
  77. of the compiler.
  78. To run the output classes requires putting all the
  79. aspectpath entries on the run classpath.
  80. JarList, like classpath, is a single argument containing
  81. a list of paths to jar files, delimited by the platform-
  82. specific classpath delimiter.
  83. </para></listitem>
  84. </varlistentry>
  85. <varlistentry>
  86. <term>-argfile <replaceable>File</replaceable></term>
  87. <listitem><para>
  88. The file is a line-delimited list of arguments.
  89. These arguments are inserted into the argument list.
  90. </para></listitem>
  91. </varlistentry>
  92. <varlistentry>
  93. <term>-outjar <replaceable>output.jar</replaceable></term>
  94. <listitem><para>Put output classes in zip file output.jar.
  95. </para></listitem>
  96. </varlistentry>
  97. <varlistentry>
  98. <term>-incremental</term>
  99. <listitem><para>Run the compiler continuously.
  100. After the initial compilation, the compiler will
  101. wait to recompile until it reads a newline from the standard
  102. input, and will quit when it reads a 'q'.
  103. It will only recompile necessary components, so a recompile
  104. should be much faster than doing a second compile.
  105. This requires -sourceroots.
  106. </para></listitem>
  107. </varlistentry>
  108. <varlistentry>
  109. <term>-sourceroots <replaceable>DirPaths</replaceable></term>
  110. <listitem><para>Find and build all .java or .aj source files under
  111. any directory listed in DirPaths.
  112. DirPaths, like classpath, is a single argument containing
  113. a list of paths to directories, delimited by the platform-
  114. specific classpath delimiter.
  115. Required by -incremental.
  116. </para></listitem>
  117. </varlistentry>
  118. <varlistentry>
  119. <term>-emacssym</term>
  120. <listitem><para>
  121. Generate .ajesym symbol files for emacs support
  122. </para></listitem>
  123. </varlistentry>
  124. <varlistentry>
  125. <term>-Xlint</term>
  126. <listitem><para>Same as -Xlint:warning (enabled by default)
  127. </para></listitem>
  128. </varlistentry>
  129. <varlistentry>
  130. <term>-Xlint:{level}</term>
  131. <listitem><para>Set default level for messages about potential
  132. programming mistakes in crosscutting code.
  133. {level} may be ignore, warning, or error.
  134. This overrides entries in
  135. org/aspectj/weaver/XlintDefault.properties
  136. from aspectjtools.jar, but does not override levels set
  137. using the -Xlintfile option.
  138. </para></listitem>
  139. </varlistentry>
  140. <varlistentry>
  141. <term>-Xlintfile <replaceable>PropertyFile</replaceable></term>
  142. <listitem><para>Specify properties file to set levels for
  143. specific crosscutting messages.
  144. PropertyFile is a path to a Java .properties file that
  145. takes the same property names and values as
  146. org/aspectj/weaver/XlintDefault.properties
  147. from aspectjtools.jar, which it also overrides.
  148. </para></listitem>
  149. </varlistentry>
  150. <varlistentry>
  151. <term>-help</term>
  152. <listitem><para>
  153. Emit information on compiler options and usage
  154. </para></listitem>
  155. </varlistentry>
  156. <varlistentry>
  157. <term>-version</term>
  158. <listitem><para>
  159. Emit the version of the AspectJ compiler
  160. </para></listitem>
  161. </varlistentry>
  162. <varlistentry>
  163. <term>-classpath <replaceable>Path</replaceable></term>
  164. <listitem><para>
  165. Specify where to find user class files.
  166. Path is a single argument containing
  167. a list of paths to zip files or directories,
  168. delimited by the platform-specific path delimiter.
  169. </para></listitem>
  170. </varlistentry>
  171. <varlistentry>
  172. <term>-bootclasspath <replaceable>Path</replaceable></term>
  173. <listitem><para>
  174. Override location of VM's bootclasspath
  175. for purposes of evaluating types when compiling.
  176. Path is a single argument containing
  177. a list of paths to zip files or directories,
  178. delimited by the platform-specific path delimiter.
  179. </para></listitem>
  180. </varlistentry>
  181. <varlistentry>
  182. <term>-extdirs <replaceable>Path</replaceable></term>
  183. <listitem><para>
  184. Override location of VM's extension directories
  185. for purposes of evaluating types when compiling.
  186. Path is a single argument containing
  187. a list of paths to directories,
  188. delimited by the platform-specific path delimiter.
  189. </para></listitem>
  190. </varlistentry>
  191. <varlistentry>
  192. <term>-d <replaceable>Directory</replaceable></term>
  193. <listitem><para>
  194. Specify where to place generated .class files.
  195. If not specified, <replaceable>Directory</replaceable>
  196. defaults to the current working dir.
  197. </para></listitem>
  198. </varlistentry>
  199. <varlistentry>
  200. <term>-target <replaceable>[1.1 to 1.4]</replaceable></term>
  201. <listitem><para>Specify classfile target setting (1.1 to 1.4, default is 1.2)
  202. </para></listitem>
  203. </varlistentry>
  204. <varlistentry>
  205. <term>-1.3</term>
  206. <listitem><para>Set compliance level to 1.3
  207. </para></listitem>
  208. </varlistentry>
  209. <varlistentry>
  210. <term>-1.4</term>
  211. <listitem><para>Set compliance level to 1.4 (default)
  212. </para></listitem>
  213. </varlistentry>
  214. <varlistentry>
  215. <term>-source <replaceable>[1.3|1.4]</replaceable></term>
  216. <listitem><para>Toggle assertions (1.3 or 1.4, default is 1.3).
  217. When using -source 1.3, an assert() statement valid under
  218. Java 1.4 will result in a compiler error.
  219. When using -source 1.4,
  220. treat <literal>assert</literal> as a keyword and
  221. implement assertions according to the 1.4 language spec.
  222. </para></listitem>
  223. </varlistentry>
  224. <varlistentry>
  225. <term>-nowarn</term>
  226. <listitem><para>Emit no warnings (equivalent to '-warn:none')
  227. This does not suppress messages
  228. generated by <literal>declare warning</literal> or
  229. <literal>Xlint</literal>.
  230. </para></listitem>
  231. </varlistentry>
  232. <varlistentry>
  233. <term>-warn: <replaceable>items</replaceable></term>
  234. <listitem><para>Emit warnings for any instances of
  235. the comma-delimited list of questionable code
  236. (eg '-warn:unusedLocals,deprecation'):
  237. <programlisting><!-- unable to embed itemizedlist? -->
  238. constructorName method with constructor name
  239. packageDefaultMethod attempt to override package-default method
  240. deprecation usage of deprecated type or member
  241. maskedCatchBlocks hidden catch block
  242. unusedLocals local variable never read
  243. unusedArguments method argument never read
  244. unusedImports import statement not used by code in file
  245. none suppress all compiler warnings
  246. </programlisting>
  247. <literal>-warn:none</literal> does not suppress messages
  248. generated by <literal>declare warning</literal> or
  249. <literal>Xlint</literal>.
  250. </para></listitem>
  251. </varlistentry>
  252. <varlistentry>
  253. <term>-deprecation</term>
  254. <listitem><para>Same as -warn:deprecation
  255. </para></listitem>
  256. </varlistentry>
  257. <varlistentry>
  258. <term>-noImportError</term>
  259. <listitem><para>Emit no errors for unresolved imports
  260. </para></listitem>
  261. </varlistentry>
  262. <varlistentry>
  263. <term>-proceedOnError</term>
  264. <listitem><para>Keep compiling after error,
  265. dumping class files with problem methods
  266. </para></listitem>
  267. </varlistentry>
  268. <varlistentry>
  269. <term>-g<replaceable>:[lines,vars,source]</replaceable></term>
  270. <listitem>
  271. <para>debug attributes level, that may take three forms:
  272. <programlisting>
  273. -g all debug info ('-g:lines,vars,source')
  274. -g:none no debug info
  275. -g:{items} debug info for any/all of [lines, vars, source], e.g.,
  276. -g:lines,source
  277. </programlisting>
  278. </para></listitem>
  279. </varlistentry>
  280. <varlistentry>
  281. <term>-preserveAllLocals</term>
  282. <listitem><para>Preserve all local variables during code generation
  283. (to facilitate debugging).
  284. </para></listitem>
  285. </varlistentry>
  286. <varlistentry>
  287. <term>-referenceInfo</term>
  288. <listitem><para>Compute reference information.
  289. </para></listitem>
  290. </varlistentry>
  291. <varlistentry>
  292. <term>-encoding <replaceable>format</replaceable></term>
  293. <listitem><para>Specify default source encoding format.
  294. Specify custom encoding on a per file basis by suffixing
  295. each input source file/folder name with '[encoding]'.
  296. </para></listitem>
  297. </varlistentry>
  298. <varlistentry>
  299. <term>-verbose</term>
  300. <listitem><para>Emit messages about accessed/processed compilation units
  301. </para></listitem>
  302. </varlistentry>
  303. <varlistentry>
  304. <term>-showWeaveInfo</term>
  305. <listitem><para>Emit messages about weaving
  306. </para></listitem>
  307. </varlistentry>
  308. <varlistentry>
  309. <term>-log <replaceable>file</replaceable></term>
  310. <listitem><para>Specify a log file for compiler messages.
  311. </para></listitem>
  312. </varlistentry>
  313. <varlistentry>
  314. <term>-progress</term>
  315. <listitem><para>Show progress (requires -log mode).
  316. </para></listitem>
  317. </varlistentry>
  318. <varlistentry>
  319. <term>-time</term>
  320. <listitem><para>Display speed information.
  321. </para></listitem>
  322. </varlistentry>
  323. <varlistentry>
  324. <term>-noExit</term>
  325. <listitem><para>Do not call System.exit(n) at end of compilation
  326. (n=0 if no error)
  327. </para></listitem>
  328. </varlistentry>
  329. <varlistentry>
  330. <term>-repeat <replaceable>N</replaceable></term>
  331. <listitem><para>Repeat compilation process N times
  332. (typically to do performance analysis).
  333. </para></listitem>
  334. </varlistentry>
  335. <varlistentry>
  336. <term>-Xnoweave</term>
  337. <listitem><para>(Experimental) produce unwoven class files
  338. for input using -injars.
  339. </para></listitem>
  340. </varlistentry>
  341. <varlistentry>
  342. <term>-Xreweavable[:compress]</term>
  343. <listitem><para>(Experimental) runs weaver in reweavable mode which causes
  344. it to create woven classes that can be rewoven, subject to the restriction that
  345. on attempting a reweave all the types that advised the woven type must be accessible.
  346. </para></listitem>
  347. </varlistentry>
  348. <varlistentry>
  349. <term>-XnoInline</term>
  350. <listitem><para>(Experimental) do not inline around advice
  351. </para></listitem>
  352. </varlistentry>
  353. <varlistentry>
  354. <term>-XincrementalFile <replaceable>file</replaceable></term>
  355. <listitem><para>(Experimental) This works like incremental mode,
  356. but using a file rather than standard input to control the compiler.
  357. It will recompile each time file is changed and
  358. and halt when file is deleted.
  359. </para></listitem>
  360. </varlistentry>
  361. <varlistentry>
  362. <term>-XserializableAspects</term>
  363. <listitem><para>(Experimental) Normally it is an error to declare
  364. aspects Serializable. This option removes that restriction.
  365. </para></listitem>
  366. </varlistentry>
  367. </variablelist>
  368. </refsect2>
  369. <refsect2>
  370. <title>File names</title>
  371. <para>ajc accepts source files with either the <filename>.java</filename>
  372. extension or the <filename>.aj</filename> extension. We normally use
  373. <filename>.java</filename> for all of our files in an AspectJ system -- files
  374. that contain aspects as well as files that contain classes. However, if
  375. you have a need to mechanically distinguish files that use AspectJ's
  376. additional functionality from those that are pure Java we recommend using
  377. the <filename>.aj</filename> extension for those files.</para>
  378. <para>We'd like to discourage other means of mechanical distinction such as
  379. naming conventions or sub-packages in favor of the <filename>.aj</filename>
  380. extension.</para>
  381. <itemizedlist>
  382. <listitem><para>Filename conventions are hard to enforce and lead to awkward names
  383. for your aspects. Instead of <filename>TracingAspect.java</filename> we
  384. recommend using <filename>Tracing.aj</filename> (or just
  385. <filename>Tracing.java</filename>) instead.</para></listitem>
  386. <listitem><para>Sub-packages move aspects out of their natural place in a system
  387. and can create an artificial need for privileged aspects. Instead of
  388. adding a sub-package like <filename>aspects</filename> we recommend using the
  389. <filename>.aj</filename> extension and including these files in your existing
  390. packages instead.</para></listitem>
  391. </itemizedlist>
  392. </refsect2>
  393. <refsect2>
  394. <title>Compatibility</title>
  395. <para>
  396. AspectJ is a compatible extension to the Java programming language. The
  397. AspectJ compiler adheres to the <ulink
  398. url="http://java.sun.com/docs/books/jls/index.html"> <citetitle
  399. pubwork="book">The Java Language Specfication, Second
  400. Edition</citetitle></ulink> and to the <ulink
  401. url="http://java.sun.com/docs/books/vmspec/index.html"><citetitle
  402. pubwork="book">The Java Virtual Machine Specification, Second
  403. Edition</citetitle></ulink> and runs on any Java 2 compatible
  404. platform. The code it generates runs on any Java 1.1 or later
  405. compatible platform.</para>
  406. </refsect2>
  407. <refsect2>
  408. <title>Examples</title>
  409. <example id="simpleexample">
  410. <title>A simple example</title>
  411. <para>Compile two files:</para>
  412. <programlisting>
  413. ajc HelloWorld.java Trace.java
  414. </programlisting>
  415. </example>
  416. <example id="exampleusingargfile">
  417. <title>An example using -argfile/@</title>
  418. <para>
  419. To avoid specifying file names on the command line,
  420. list source files in a line-delimited text argfile.
  421. Source file paths may be absolute or relative to the argfile,
  422. and may include other argfiles by @-reference.
  423. The following file <literal>sources.lst</literal>
  424. contains absolute and relative files and @-references:
  425. </para>
  426. <programlisting>
  427. Gui.java
  428. /home/user/src/Library.java
  429. data/Repository.java
  430. data/Access.java
  431. @../../common/common.lst
  432. @/home/user/src/lib.lst
  433. view/body/ArrayView.java</programlisting>
  434. <para>Compile the files using either the -argfile or @ form:</para>
  435. <programlisting>
  436. ajc -argfile sources.lst
  437. ajc @sources.lst</programlisting>
  438. <para>
  439. Argfiles are also supported by jikes and javac, so you
  440. can use the files in hybrid builds. However, the support varies:
  441. </para>
  442. <itemizedlist>
  443. <listitem><para>Only ajc accepts command-line options</para></listitem>
  444. <listitem><para>Jikes and Javac do not accept internal @argfile references.
  445. </para></listitem>
  446. <listitem><para>Jikes and Javac only accept the @file form on the command line.</para></listitem>
  447. </itemizedlist>
  448. </example>
  449. <example id="examplebytecode">
  450. <title>An example using -injars and -aspectpath</title>
  451. <para>Bytecode weaving using -injars:
  452. AspectJ 1.1 supports weaving from input zip or jar files containing
  453. class files. Using input jars is like compiling the corresponding
  454. source files, and all binaries are emitted to output. Although
  455. Java-compliant compilers may differ in their output, ajc should
  456. take as input any class files produced by javac, jikes, eclipse,
  457. and, of course, ajc. Aspects included in -injars will be woven into
  458. like other .class files, but they will specify any crosscutting
  459. code (i.e., they will not be woven into other types). To use
  460. aspects in their binary form to specify crosscutting,
  461. see -aspectpath below.
  462. </para>
  463. <para>Aspect libraries using -aspectpath:
  464. AspectJ 1.1 supports weaving from read-only libraries containing
  465. aspects. Like input jars, they affect all input; unlike input
  466. jars, they themselves are not affected or emitted as output.
  467. Sources compiled with aspect libraries must be run with the same
  468. aspect libraries on their classpath.
  469. </para>
  470. <para>The following example builds the tracing example in a
  471. command-line environment; it creates a read-only aspect library,
  472. compiles some classes for use as input bytecode, and
  473. compiles the classes and other sources with the aspect library.
  474. </para>
  475. <para>The tracing example is in the AspectJ distribution
  476. ({aspectj}/doc/examples/tracing). This uses the following files:
  477. </para>
  478. <para><programlisting>
  479. aspectj1.1/
  480. bin/
  481. ajc
  482. lib/
  483. aspectjrt.jar
  484. examples/
  485. tracing/
  486. Circle.java
  487. ExampleMain.java
  488. lib/
  489. AbstractTrace.java
  490. TraceMyClasses.java
  491. notrace.lst
  492. Square.java
  493. tracelib.lst
  494. tracev3.lst
  495. TwoDShape.java
  496. version3/
  497. Trace.java
  498. TraceMyClasses.java
  499. </programlisting></para>
  500. <para>Below, the path separator is taken as ";", but file separators
  501. are "/". All commands are on one line. Adjust paths and
  502. commands to your environment as needed.
  503. </para><para>Setup the path, classpath, and current directory:</para>
  504. <programlisting>
  505. cd examples
  506. export ajrt=../lib/aspectjrt.jar
  507. export CLASSPATH="$ajrt"
  508. export PATH="../bin:$PATH"
  509. </programlisting>
  510. <para>Build a read-only tracing library:</para>
  511. <programlisting>
  512. ajc -argfile tracing/tracelib.lst -outjar tracelib.jar
  513. </programlisting>
  514. <para>Build the application with tracing in one step:</para>
  515. <programlisting>
  516. ajc -aspectpath tracelib.jar -argfile tracing/notrace.lst -outjar tracedapp.jar
  517. </programlisting>
  518. <para>Run the application with tracing:</para>
  519. <programlisting>
  520. java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain
  521. </programlisting>
  522. <para>Build the application with tracing from binaries in two steps:</para>
  523. <itemizedlist><listitem><para>
  524. (a) Build the application classes (using javac for demonstration's sake):</para>
  525. <programlisting>
  526. mkdir classes
  527. javac -d classes tracing/*.java
  528. jar cfM app.jar -C classes .
  529. </programlisting>
  530. </listitem>
  531. <listitem><para>
  532. (b) Build the application with tracing:</para>
  533. <programlisting>
  534. ajc -injars app.jar -aspectpath tracelib.jar -outjar tracedapp.jar
  535. </programlisting>
  536. </listitem></itemizedlist>
  537. <para>Run the application with tracing (same as above):</para>
  538. <programlisting>
  539. java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain
  540. </programlisting>
  541. <para>Run the application without tracing:</para>
  542. <programlisting>
  543. java -classpath "app.jar" tracing.ExampleMain
  544. </programlisting>
  545. </example>
  546. </refsect2>
  547. <refsect2>
  548. <title>The AspectJ compiler API</title>
  549. <para>The AspectJ compiler is implemented completely in Java and can be
  550. called as a Java class. The only interface that should be considered
  551. public are the public methods in <literal>org.aspectj.tools.ajc.Main</literal>.
  552. E.g., <literal>main(String[] args)</literal> takes the
  553. the standard <command>ajc</command> command line arguments.
  554. This means that an alternative way to run the
  555. compiler is </para>
  556. <cmdsynopsis>
  557. <command><literal>java org.aspectj.tools.ajc.Main</literal></command>
  558. <arg><replaceable>option...</replaceable></arg>
  559. <arg><replaceable>file...</replaceable></arg>
  560. </cmdsynopsis>
  561. <para>To access compiler messages programmatically, use the methods
  562. <literal>setHolder(IMessageHolder holder)</literal> and/or
  563. <literal>run(String[] args, IMessageHolder holder)</literal>.
  564. </para>
  565. </refsect2>
  566. <refsect2>
  567. <title>Stack Traces and the SourceFile attribute</title>
  568. <para>Unlike traditional java compilers, the AspectJ compiler may in
  569. certain cases generate classfiles from multiple source files.
  570. Unfortunately, the original Java class file format does not support
  571. multiple
  572. SourceFile attributes. In order to make sure all source file
  573. information is available, the AspectJ compiler may in some cases
  574. encode multiple filenames in the SourceFile attribute.
  575. When the Java VM generates stack traces, it uses this attribute
  576. to specify the source file.
  577. </para>
  578. <para>(The AspectJ 1.0 compiler also supports the .class file extensions of JSR-45.
  579. These permit compliant debuggers (such as jdb in Java 1.4.1) to identify
  580. the right file and line even given many source files for a single class.
  581. JSR-45 support is planned for ajc in AspectJ 1.1, but is not in the initial
  582. release. To get fully debuggable .class files, use the -XnoInline option.)
  583. </para>
  584. <para>Probably the only time you may see this format is when you view
  585. stack traces, where you may encounter traces of the format
  586. </para>
  587. <programlisting>
  588. java.lang.NullPointerException
  589. at Main.new$constructor_call37(Main.java;SynchAspect.java[1k]:1030)
  590. </programlisting>
  591. <para>where instead of the usual
  592. </para>
  593. <programlisting>
  594. File:LineNumber
  595. </programlisting>
  596. <para>format, you see
  597. </para>
  598. <programlisting>
  599. File0;File1[Number1];File2[Number2] ... :LineNumber
  600. </programlisting>
  601. <para>In this case, LineNumber is the usual offset in lines plus the
  602. "start line" of the actual source file. That means you use LineNumber
  603. both to identify the source file and to find the line at issue.
  604. The number in [brackets] after each file tells you the
  605. virtual "start line" for that file (the first file has a start of 0).
  606. </para>
  607. <para> In our example from the null pointer exception trace,
  608. the virtual start line is 1030. Since the file SynchAspect.java
  609. "starts" at line 1000 [1k], the LineNumber points to line 30 of
  610. SynchAspect.java.
  611. </para>
  612. <para> So, when faced with such stack traces, the way to find the actual
  613. source location is to look through the list of "start line" numbers to
  614. find the one just under the shown line number. That is the file where
  615. the source location can actually be found. Then, subtract that "start
  616. line" from the shown line number to find the actual line number within
  617. that file.
  618. </para>
  619. <para>In a class file that comes from only a single source file, the AspectJ
  620. compiler generates SourceFile attributes consistent with
  621. traditional Java compilers.
  622. </para>
  623. </refsect2>
  624. </refsect1>
  625. </refentry>