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 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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|1.2]</replaceable></term>
  201. <listitem><para>Specify classfile target setting (1.1 or 1.2, default is 1.1)
  202. </para></listitem>
  203. </varlistentry>
  204. <varlistentry>
  205. <term>-1.3</term>
  206. <listitem><para>Set compliance level to 1.3 (default)
  207. </para></listitem>
  208. </varlistentry>
  209. <varlistentry>
  210. <term>-1.4</term>
  211. <listitem><para>Set compliance level to 1.4
  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. in -1.3 mode and 1.4 in -1.4 mode).
  218. When using -source 1.3, an assert() statement valid under
  219. Java 1.4 will result in a compiler error.
  220. When using -source 1.4,
  221. treat <literal>assert</literal> as a keyword and
  222. implement assertions according to the 1.4 language spec.
  223. </para></listitem>
  224. </varlistentry>
  225. <varlistentry>
  226. <term>-nowarn</term>
  227. <listitem><para>Emit no warnings (equivalent to '-warn:none')
  228. This does not suppress messages
  229. generated by <literal>declare warning</literal> or
  230. <literal>Xlint</literal>.
  231. </para></listitem>
  232. </varlistentry>
  233. <varlistentry>
  234. <term>-warn: <replaceable>items</replaceable></term>
  235. <listitem><para>Emit warnings for any instances of
  236. the comma-delimited list of questionable code
  237. (eg '-warn:unusedLocals,deprecation'):
  238. <programlisting><!-- unable to embed itemizedlist? -->
  239. constructorName method with constructor name
  240. packageDefaultMethod attempt to override package-default method
  241. deprecation usage of deprecated type or member
  242. maskedCatchBlocks hidden catch block
  243. unusedLocals local variable never read
  244. unusedArguments method argument never read
  245. unusedImports import statement not used by code in file
  246. none suppress all compiler warnings
  247. </programlisting>
  248. <literal>-warn:none</literal> does not suppress messages
  249. generated by <literal>declare warning</literal> or
  250. <literal>Xlint</literal>.
  251. </para></listitem>
  252. </varlistentry>
  253. <varlistentry>
  254. <term>-deprecation</term>
  255. <listitem><para>Same as -warn:deprecation
  256. </para></listitem>
  257. </varlistentry>
  258. <varlistentry>
  259. <term>-noImportError</term>
  260. <listitem><para>Emit no errors for unresolved imports
  261. </para></listitem>
  262. </varlistentry>
  263. <varlistentry>
  264. <term>-proceedOnError</term>
  265. <listitem><para>Keep compiling after error,
  266. dumping class files with problem methods
  267. </para></listitem>
  268. </varlistentry>
  269. <varlistentry>
  270. <term>-g<replaceable>:[lines,vars,source]</replaceable></term>
  271. <listitem>
  272. <para>debug attributes level, that may take three forms:
  273. <programlisting>
  274. -g all debug info ('-g:lines,vars,source')
  275. -g:none no debug info
  276. -g:{items} debug info for any/all of [lines, vars, source], e.g.,
  277. -g:lines,source
  278. </programlisting>
  279. </para></listitem>
  280. </varlistentry>
  281. <varlistentry>
  282. <term>-preserveAllLocals</term>
  283. <listitem><para>Preserve all local variables during code generation
  284. (to facilitate debugging).
  285. </para></listitem>
  286. </varlistentry>
  287. <varlistentry>
  288. <term>-referenceInfo</term>
  289. <listitem><para>Compute reference information.
  290. </para></listitem>
  291. </varlistentry>
  292. <varlistentry>
  293. <term>-encoding <replaceable>format</replaceable></term>
  294. <listitem><para>Specify default source encoding format.
  295. Specify custom encoding on a per file basis by suffixing
  296. each input source file/folder name with '[encoding]'.
  297. </para></listitem>
  298. </varlistentry>
  299. <varlistentry>
  300. <term>-verbose</term>
  301. <listitem><para>Emit messages about accessed/processed compilation units
  302. </para></listitem>
  303. </varlistentry>
  304. <varlistentry>
  305. <term>-log <replaceable>file</replaceable></term>
  306. <listitem><para>Specify a log file for compiler messages.
  307. </para></listitem>
  308. </varlistentry>
  309. <varlistentry>
  310. <term>-progress</term>
  311. <listitem><para>Show progress (requires -log mode).
  312. </para></listitem>
  313. </varlistentry>
  314. <varlistentry>
  315. <term>-time</term>
  316. <listitem><para>Display speed information.
  317. </para></listitem>
  318. </varlistentry>
  319. <varlistentry>
  320. <term>-noExit</term>
  321. <listitem><para>Do not call System.exit(n) at end of compilation
  322. (n=0 if no error)
  323. </para></listitem>
  324. </varlistentry>
  325. <varlistentry>
  326. <term>-repeat <replaceable>N</replaceable></term>
  327. <listitem><para>Repeat compilation process N times
  328. (typically to do performance analysis).
  329. </para></listitem>
  330. </varlistentry>
  331. <varlistentry>
  332. <term>-Xnoweave</term>
  333. <listitem><para>(Experimental) produce unwoven class files
  334. for input using -injars.
  335. </para></listitem>
  336. </varlistentry>
  337. <varlistentry>
  338. <term>-XnoInline</term>
  339. <listitem><para>(Experimental) do not inline around advice
  340. </para></listitem>
  341. </varlistentry>
  342. <varlistentry>
  343. <term>-XincrementalFile <replaceable>file</replaceable></term>
  344. <listitem><para>(Experimental) This works like incremental mode,
  345. but using a file rather than standard input to control the compiler.
  346. It will recompile each time file is changed and
  347. and halt when file is deleted.
  348. </para></listitem>
  349. </varlistentry>
  350. <varlistentry>
  351. <term>-XserializableAspects</term>
  352. <listitem><para>(Experimental) Normally it is an error to declare
  353. aspects Serializable. This option removes that restriction.
  354. </para></listitem>
  355. </varlistentry>
  356. </variablelist>
  357. </refsect2>
  358. <refsect2> <title>File names</title>
  359. <para>ajc accepts source files with either the <filename>.java</filename>
  360. extension or the <filename>.aj</filename> extension. We normally use
  361. <filename>.java</filename> for all of our files in an AspectJ system -- files
  362. that contain aspects as well as files that contain classes. However, if
  363. you have a need to mechanically distinguish files that use AspectJ's
  364. additional functionality from those that are pure Java we recommend using
  365. the <filename>.aj</filename> extension for those files.</para>
  366. <para>We'd like to discourage other means of mechanical distinction such as
  367. naming conventions or sub-packages in favor of the <filename>.aj</filename>
  368. extension.</para>
  369. <para>
  370. <itemizedlist>
  371. <listitem>Filename conventions are hard to enforce and lead to awkward names
  372. for your aspects. Instead of <filename>TracingAspect.java</filename> we
  373. recommend using <filename>Tracing.aj</filename> (or just
  374. <filename>Tracing.java</filename>) instead.</listitem>
  375. <listitem>Sub-packages move aspects out of their natural place in a system
  376. and can create an artificial need for privileged aspects. Instead of
  377. adding a sub-package like <filename>aspects</filename> we recommend using the
  378. <filename>.aj</filename> extension and including these files in your existing
  379. packages instead.</listitem>
  380. </itemizedlist>
  381. </para>
  382. </refsect2>
  383. <refsect2>
  384. <title>Compatibility</title>
  385. <para>
  386. AspectJ is a compatible extension to the Java programming language. The
  387. AspectJ compiler adheres to the <ulink
  388. url="http://java.sun.com/docs/books/jls/index.html"> <citetitle
  389. pubwork="book">The Java Language Specfication, Second
  390. Edition</citetitle></ulink> and to the <ulink
  391. url="http://java.sun.com/docs/books/vmspec/index.html"><citetitle
  392. pubwork="book">The Java Virtual Machine Specification, Second
  393. Edition</citetitle></ulink> and runs on any Java 2 compatible
  394. platform. The code it generates runs on any Java 1.1 or later
  395. compatible platform.</para>
  396. </refsect2>
  397. <refsect2>
  398. <title>Examples</title>
  399. <example id="simpleexample">
  400. <title>A simple example</title>
  401. <para>Compile two files:</para>
  402. <programlisting>
  403. ajc HelloWorld.java Trace.java
  404. </programlisting>
  405. </example>
  406. <example id="exampleusingargfile">
  407. <title>An example using -argfile/@</title>
  408. <para>
  409. To avoid specifying file names on the command line,
  410. list source files in a line-delimited text argfile.
  411. Source file paths may be absolute or relative to the argfile,
  412. and may include other argfiles by @-reference.
  413. The following file <literal>sources.lst</literal>
  414. contains absolute and relative files and @-references:
  415. <para><programlisting>
  416. Gui.java
  417. /home/user/src/Library.java
  418. data/Repository.java
  419. data/Access.java
  420. @../../common/common.lst
  421. @/home/user/src/lib.lst
  422. view/body/ArrayView.java</programlisting></para>
  423. Compile the files using either the -argfile or @ form:
  424. <para><programlisting>
  425. ajc -argfile sources.lst
  426. ajc @sources.lst</programlisting></para>
  427. </para>
  428. <para>
  429. Argfiles are also supported by jikes and javac, so you
  430. can use the files in hybrid builds. However, the support varies:
  431. </para>
  432. <para>
  433. <itemizedlist>
  434. <listitem>Only ajc accepts command-line options</listitem>
  435. <listitem>Jikes and Javac do not accept internal @argfile references.
  436. </listitem>
  437. <listitem>Jikes and Javac only accept the @file form on the command line.</listitem>
  438. </itemizedlist>
  439. </para>
  440. </example>
  441. <example id="examplebytecode">
  442. <title>An example using -injars and -aspectpath</title>
  443. <para>Bytecode weaving using -injars:
  444. AspectJ 1.1 supports weaving from input zip or jar files containing
  445. class files. Using input jars is like compiling the corresponding
  446. source files, and all binaries are emitted to output. Although
  447. Java-compliant compilers may differ in their output, ajc should
  448. take as input any class files produced by javac, jikes, eclipse,
  449. and, of course, ajc. Aspects included in -injars will be woven into
  450. like other .class files, but they will specify any crosscutting
  451. code (i.e., they will not be woven into other types). To use
  452. aspects in their binary form to specify crosscutting,
  453. see -aspectpath below.
  454. </para>
  455. <para>Aspect libraries using -aspectpath:
  456. AspectJ 1.1 supports weaving from read-only libraries containing
  457. aspects. Like input jars, they affect all input; unlike input
  458. jars, they themselves are not affected or emitted as output.
  459. Sources compiled with aspect libraries must be run with the same
  460. aspect libraries on their classpath.
  461. </para>
  462. <para>The following example builds the tracing example in a
  463. command-line environment; it creates a read-only aspect library,
  464. compiles some classes for use as input bytecode, and
  465. compiles the classes and other sources with the aspect library.
  466. </para>
  467. <para>The tracing example is in the AspectJ distribution
  468. ({aspectj}/doc/examples/tracing). This uses the following files:
  469. </para>
  470. <para><programlisting>
  471. aspectj1.1/
  472. bin/
  473. ajc
  474. lib/
  475. aspectjrt.jar
  476. examples/
  477. tracing/
  478. Circle.java
  479. ExampleMain.java
  480. lib/
  481. AbstractTrace.java
  482. TraceMyClasses.java
  483. notrace.lst
  484. Square.java
  485. tracelib.lst
  486. tracev3.lst
  487. TwoDShape.java
  488. version3/
  489. Trace.java
  490. TraceMyClasses.java
  491. </programlisting></para>
  492. <para>Below, the path separator is taken as ";", but file separators
  493. are "/". All commands are on one line. Adjust paths and
  494. commands to your environment as needed.
  495. </para><para>Setup the path, classpath, and current directory:
  496. <para><programlisting>
  497. cd examples
  498. export ajrt=../lib/aspectjrt.jar
  499. export CLASSPATH="$ajrt"
  500. export PATH="../bin:$PATH"
  501. </programlisting></para>
  502. </para><para>Build a read-only tracing library:
  503. <para><programlisting>
  504. ajc -argfile tracing/tracelib.lst -outjar tracelib.jar
  505. </programlisting></para>
  506. </para><para>Build the application with tracing in one step:
  507. <para><programlisting>
  508. ajc -aspectpath tracelib.jar -argfile tracing/notrace.lst -outjar tracedapp.jar
  509. </programlisting></para>
  510. </para><para>Run the application with tracing:
  511. <para><programlisting>
  512. java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain
  513. </programlisting></para>
  514. </para><para>Build the application with tracing from binaries in two steps:
  515. <listitem><para>
  516. (a) Build the application classes (using javac for demonstration's sake):
  517. <para><programlisting>
  518. mkdir classes
  519. javac -d classes tracing/*.java
  520. jar cfM app.jar -C classes .
  521. </programlisting></para>
  522. </para></listitem>
  523. <listitem><para>
  524. (b) Build the application with tracing:
  525. <para><programlisting>
  526. ajc -injars app.jar -aspectpath tracelib.jar -outjar tracedapp.jar
  527. </programlisting></para>
  528. </para></listitem>
  529. </para><para>Run the application with tracing (same as above):
  530. <para><programlisting>
  531. java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain
  532. </programlisting></para>
  533. </para><para>Run the application without tracing:
  534. <para><programlisting>
  535. java -classpath "app.jar" tracing.ExampleMain
  536. </programlisting></para>
  537. </para>
  538. </example>
  539. </refsect2>
  540. <refsect2>
  541. <title>The AspectJ compiler API</title>
  542. <para>The AspectJ compiler is implemented completely in Java and can be
  543. called as a Java class. The only interface that should be considered
  544. public are the public methods in <literal>org.aspectj.tools.ajc.Main</literal>.
  545. E.g., <literal>main(String[] args)</literal> takes the
  546. the standard <command>ajc</command> command line arguments.
  547. This means that an alternative way to run the
  548. compiler is </para>
  549. <cmdsynopsis>
  550. <command><literal>java org.aspectj.tools.ajc.Main</literal></command>
  551. <arg><replaceable>option...</replaceable></arg>
  552. <arg><replaceable>file...</replaceable></arg>
  553. </cmdsynopsis>
  554. <para>To access compiler messages programmatically, use the methods
  555. <literal>setHolder(IMessageHolder holder)</literal> and/or
  556. <literal>run(String[] args, IMessageHolder holder)</literal>.
  557. </para>
  558. </refsect2>
  559. <refsect2>
  560. <title>Stack Traces and the SourceFile attribute</title>
  561. <para>Unlike traditional java compilers, the AspectJ compiler may in
  562. certain cases generate classfiles from multiple source files.
  563. Unfortunately, the original Java class file format does not support
  564. multiple
  565. SourceFile attributes. In order to make sure all source file
  566. information is available, the AspectJ compiler may in some cases
  567. encode multiple filenames in the SourceFile attribute.
  568. When the Java VM generates stack traces, it uses this attribute
  569. to specify the source file.
  570. </para>
  571. <para>(The AspectJ 1.0 compiler also supports the .class file extensions of JSR-45.
  572. These permit compliant debuggers (such as jdb in Java 1.4.1) to identify
  573. the right file and line even given many source files for a single class.
  574. JSR-45 support is planned for ajc in AspectJ 1.1, but is not in the initial
  575. release. To get fully debuggable .class files, use the -XnoInline option.)
  576. </para>
  577. <para>Probably the only time you may see this format is when you view
  578. stack traces, where you may encounter traces of the format
  579. </para>
  580. <programlisting>
  581. java.lang.NullPointerException
  582. at Main.new$constructor_call37(Main.java;SynchAspect.java[1k]:1030)
  583. </programlisting>
  584. <para>where instead of the usual
  585. </para>
  586. <programlisting>
  587. File:LineNumber
  588. </programlisting>
  589. <para>format, you see
  590. </para>
  591. <programlisting>
  592. File0;File1[Number1];File2[Number2] ... :LineNumber
  593. </programlisting>
  594. <para>In this case, LineNumber is the usual offset in lines plus the
  595. "start line" of the actual source file. That means you use LineNumber
  596. both to identify the source file and to find the line at issue.
  597. The number in [brackets] after each file tells you the
  598. virtual "start line" for that file (the first file has a start of 0).
  599. </para>
  600. <para> In our example from the null pointer exception trace,
  601. the virtual start line is 1030. Since the file SynchAspect.java
  602. "starts" at line 1000 [1k], the LineNumber points to line 30 of
  603. SynchAspect.java.
  604. </para>
  605. <para> So, when faced with such stack traces, the way to find the actual
  606. source location is to look through the list of "start line" numbers to
  607. find the one just under the shown line number. That is the file where
  608. the source location can actually be found. Then, subtract that "start
  609. line" from the shown line number to find the actual line number within
  610. that file.
  611. </para>
  612. <para>In a class file that comes from only a single source file, the AspectJ
  613. compiler generates SourceFile attributes consistent with
  614. traditional Java compilers.
  615. </para>
  616. </refsect2>
  617. </refsect1>
  618. </refentry>
  619. <!-- Local variables: -->
  620. <!-- fill-column: 79 -->
  621. <!-- sgml-local-ecat-files: devguide.ced -->
  622. <!-- sgml-parent-document:("devguide.sgml" "book" "refentry") -->
  623. <!-- End: -->