This file is indexed.

/usr/share/doc/aspectj-doc/devguide/ajc-ref.html is in aspectj-doc 1.8.8-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>ajc</title><link rel="stylesheet" type="text/css" href="aspectj-docs.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="The AspectJtm Development Environment Guide"><link rel="up" href="command-line-tools.html#ajc-ref-top" title="ajc, the AspectJ compiler/weaver"><link rel="prev" href="command-line-tools.html" title="Chapter 2. AspectJ command-line tools"><link rel="next" href="ajdoc-ref-top.html" title="ajdoc, the AspectJ documentation tool"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ajc</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="command-line-tools.html">Prev</a> </td><th width="60%" align="center"><code class="literal">ajc</code>, the AspectJ compiler/weaver</th><td width="20%" align="right"> <a accesskey="n" href="ajdoc-ref-top.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="ajc-ref"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ajc &#8212; compiler and bytecode weaver for the AspectJ and Java languages</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">ajc</code>  [<em class="replaceable"><code>Options</code></em>] [[<em class="replaceable"><code>file...</code></em>] |  [@<em class="replaceable"><code>file...</code></em>] |  [-argfile <em class="replaceable"><code>file...</code></em>]]</p></div></div><div class="refsect1"><a name="ajc"></a><h2>Description</h2><p>The <span class="command"><strong>ajc</strong></span> command compiles and weaves AspectJ and 
      Java source and .class files, producing .class files compliant with any 
      Java VM (1.1 or later).  It combines compilation and bytecode weaving
      and supports incremental builds; you can also weave bytecode
      at run-time using <a class="xref" href="ltw.html" title="Chapter 5. Load-Time Weaving">Load-Time Weaving</a>.
      </p><p> The arguments after the options specify the source file(s) to compile.
        To specify source classes, use <em class="parameter"><code>-inpath</code></em> (below).
        Files may be listed directly on the command line or in a file.
        The <em class="parameter"><code>-argfile <em class="replaceable"><code>file</code></em></code></em> 
        and <em class="parameter"><code>@<em class="replaceable"><code>file</code></em></code></em> forms
        are equivalent, and are interpreted as meaning all the arguments 
        listed in the specified file. 
    </p><p>	
        <span class="command"><strong>Note:</strong></span> 
        You must explicitly pass <span class="command"><strong>ajc</strong></span> all necessary sources.
        Be sure to include the source not only for the
        aspects or pointcuts but also for any affected types.  
        Specifying all sources is necessary because, unlike javac, ajc does not 
        search the sourcepath for classes.
        (For a discussion of what affected types might be required,
         see <a class="ulink" href="../progguide/implementation.html" target="_top">The AspectJ
         Programming Guide, Implementation Appendix</a>.)
    </p><p>
        To specify sources, you can list source files as arguments or use the 
        options <em class="parameter"><code>-sourceroots</code></em> or <em class="parameter"><code>-inpath</code></em>.
        If there are multiple sources for any type, the result is undefined
        since ajc has no way to determine which source is correct.  (This 
        happens most often when users include the destination directory
        on the inpath and rebuild.)
    </p><div class="refsect2"><a name="ajc_options"></a><h3>Options</h3><div class="variablelist"><dl class="variablelist"><dt><span class="term">-injars <em class="replaceable"><code>JarList</code></em></span></dt><dd><p>
        deprecated: since 1.2, use -inpath, which also takes
        directories.
        </p></dd><dt><span class="term">-inpath <em class="replaceable"><code>Path</code></em></span></dt><dd><p>
        Accept as source bytecode any .class files in the 
        .jar files or directories on Path.  
        The output will include these
        classes, possibly as woven with any applicable aspects.
        Path is a single argument containing
        a list of paths to zip files or directories, 
        delimited by the platform-specific path delimiter.
        </p></dd><dt><span class="term">-aspectpath <em class="replaceable"><code>Path</code></em></span></dt><dd><p>
        Weave binary aspects from jar files and directories on path into all sources.
        The aspects should have been output by the same version
        of the compiler.
        When running the output classes, the run classpath should contain 
        all aspectpath entries.
        Path, like classpath, is a single argument containing
        a list of paths to jar files, delimited by the platform-
        specific classpath delimiter.
        </p></dd><dt><span class="term">-argfile <em class="replaceable"><code>File</code></em></span></dt><dd><p>
          The file contains a line-delimited list of arguments.
		  Each line in the file should contain one option, filename, or
		  argument string (e.g., a classpath or inpath). 
		  Arguments read from the file are inserted into the argument list
		  for the command.  Relative paths in the file are calculated from
		  the directory containing the file (not the current working directory).
		  Comments, as in Java, start with <code class="literal">//</code> and
          extend to the end of the line.  Options specified in argument
          files may override rather than extending existing option values,
          so avoid specifying options like <em class="replaceable"><code>-classpath</code></em>
          in argument files unlike the argument file is the only build
          specification.  The form <em class="replaceable"><code>@file</code></em> is the same
          as specifying <em class="replaceable"><code>-argfile file</code></em>.
        </p></dd><dt><span class="term">-outjar <em class="replaceable"><code>output.jar</code></em></span></dt><dd><p>Put output classes in zip file output.jar.
        </p></dd><dt><span class="term">-outxml</span></dt><dd><p>Generate aop.xml file for load-time weaving with default name.
        </p></dd><dt><span class="term">-outxmlfile <em class="replaceable"><code>custom/aop.xml</code></em></span></dt><dd><p>Generate aop.xml file for load-time weaving with custom name.
        </p></dd><dt><span class="term">-incremental</span></dt><dd><p>Run the compiler continuously.
        After the initial compilation, the compiler will
        wait to recompile until it reads a newline from the standard
        input, and will quit when it reads a 'q'.
        It will only recompile necessary components, so a recompile
        should be much faster than doing a second compile.
        This requires -sourceroots.
        </p></dd><dt><span class="term">-sourceroots <em class="replaceable"><code>DirPaths</code></em></span></dt><dd><p>Find and build all .java or .aj source files under 
        any directory listed in DirPaths. 
        DirPaths, like classpath, is a single argument containing
        a list of paths to directories, delimited by the platform-
        specific classpath delimiter.
        Required by -incremental.
        </p></dd><dt><span class="term">-crossrefs</span></dt><dd><p>
          Generate a build .ajsym file into the output directory.  Used for
          viewing crosscutting references by tools like the AspectJ
          Browser.
        </p></dd><dt><span class="term">-emacssym</span></dt><dd><p>
          Generate .ajesym symbol files for emacs support (deprecated).
        </p></dd><dt><span class="term">-Xlint</span></dt><dd><p>Same as -Xlint:warning (enabled by default)
        </p></dd><dt><span class="term">-Xlint:{level}</span></dt><dd><p>Set default level for messages about potential
           programming mistakes in crosscutting code.
           {level} may be ignore, warning, or error.
           This overrides entries in 
	       org/aspectj/weaver/XlintDefault.properties
           from aspectjtools.jar, but does not override levels set
           using the -Xlintfile option.
        </p></dd><dt><span class="term">-Xlintfile <em class="replaceable"><code>PropertyFile</code></em></span></dt><dd><p>Specify properties file to set levels for
           specific crosscutting messages.   
           PropertyFile is a path to a Java .properties file that
           takes the same property names and values as
	       org/aspectj/weaver/XlintDefault.properties
           from aspectjtools.jar, which it also overrides.
        </p></dd><dt><span class="term">-help</span></dt><dd><p>
          Emit information on compiler options and usage
        </p></dd><dt><span class="term">-version</span></dt><dd><p>
          Emit the version of the AspectJ compiler
        </p></dd><dt><span class="term">-classpath <em class="replaceable"><code>Path</code></em></span></dt><dd><p>
          Specify where to find user class files.
        Path is a single argument containing
        a list of paths to zip files or directories, 
        delimited by the platform-specific path delimiter.
        </p></dd><dt><span class="term">-bootclasspath <em class="replaceable"><code>Path</code></em></span></dt><dd><p>
          Override location of VM's bootclasspath 
          for purposes of evaluating types when compiling.
        Path is a single argument containing
        a list of paths to zip files or directories, 
        delimited by the platform-specific path delimiter.
        </p></dd><dt><span class="term">-extdirs <em class="replaceable"><code>Path</code></em></span></dt><dd><p>
          Override location of VM's extension directories 
          for purposes of evaluating types when compiling.
        Path is a single argument containing
        a list of paths to directories, 
        delimited by the platform-specific path delimiter.
        </p></dd><dt><span class="term">-d <em class="replaceable"><code>Directory</code></em></span></dt><dd><p>
          Specify where to place generated .class files.
          If not specified, <em class="replaceable"><code>Directory</code></em> 
          defaults to the current working dir.
        </p></dd><dt><span class="term">-target <em class="replaceable"><code>[1.1 to 1.5]</code></em></span></dt><dd><p>Specify classfile target setting (1.1 to 1.5, default is 1.2)
        </p></dd><dt><span class="term">-1.3</span></dt><dd><p>Set compliance level to 1.3 
            This implies -source 1.3 and -target 1.1.
        </p></dd><dt><span class="term">-1.4</span></dt><dd><p>Set compliance level to 1.4 (default)
            This implies -source 1.4 and -target 1.2.
        </p></dd><dt><span class="term">-1.5</span></dt><dd><p>Set compliance level to 1.5.
            This implies -source 1.5 and -target 1.5.
        </p></dd><dt><span class="term">-source <em class="replaceable"><code>[1.3|1.4|1.5]</code></em></span></dt><dd><p>Toggle assertions (1.3, 1.4, or 1.5 - default is 1.4).
            When using -source 1.3, an assert() statement valid under
            Java 1.4 will result in a compiler error.
          When using -source 1.4, 
          treat <code class="literal">assert</code> as a keyword and 
          implement assertions according to the 1.4 language spec.
          When using -source 1.5,
            Java 5 language features are permitted. 
        </p></dd><dt><span class="term">-nowarn</span></dt><dd><p>Emit no warnings (equivalent to '-warn:none')
        This does not suppress messages
        generated by <code class="literal">declare warning</code> or
        <code class="literal">Xlint</code>.
        </p></dd><dt><span class="term">-warn: <em class="replaceable"><code>items</code></em></span></dt><dd><p>Emit warnings for any instances of
        the comma-delimited list of questionable code 
        (eg '-warn:unusedLocals,deprecation'):
        </p><pre class="programlisting">
    constructorName        method with constructor name
    packageDefaultMethod   attempt to override package-default method
    deprecation            usage of deprecated type or member
    maskedCatchBlocks      hidden catch block
    unusedLocals           local variable never read
    unusedArguments        method argument never read
    unusedImports          import statement not used by code in file
    none                   suppress all compiler warnings
        </pre><p>
        <code class="literal">-warn:none</code> does not suppress messages
        generated by <code class="literal">declare warning</code> or
        <code class="literal">Xlint</code>.
        
        </p></dd><dt><span class="term">-deprecation</span></dt><dd><p>Same as -warn:deprecation
        </p></dd><dt><span class="term">-noImportError</span></dt><dd><p>Emit no errors for unresolved imports
        </p></dd><dt><span class="term">-proceedOnError</span></dt><dd><p>Keep compiling after error, 
                        dumping class files with problem methods
        </p></dd><dt><span class="term">-g<em class="replaceable"><code>:[lines,vars,source]</code></em></span></dt><dd><p>debug attributes level, that may take three forms:
        </p><pre class="programlisting">
    -g         all debug info ('-g:lines,vars,source')
    -g:none    no debug info
    -g:{items} debug info for any/all of [lines, vars, source], e.g.,
               -g:lines,source
        </pre><p>
            
        </p></dd><dt><span class="term">-preserveAllLocals</span></dt><dd><p>Preserve all local variables during code generation
        (to facilitate debugging).
        </p></dd><dt><span class="term">-referenceInfo</span></dt><dd><p>Compute reference information.
        </p></dd><dt><span class="term">-encoding <em class="replaceable"><code>format</code></em></span></dt><dd><p>Specify default source encoding format.
            Specify custom encoding on a per file basis by suffixing
			each input source file/folder name with '[encoding]'.
        </p></dd><dt><span class="term">-verbose</span></dt><dd><p>Emit messages about accessed/processed compilation units 
        </p></dd><dt><span class="term">-showWeaveInfo</span></dt><dd><p>Emit messages about weaving 
        </p></dd><dt><span class="term">-log <em class="replaceable"><code>file</code></em></span></dt><dd><p>Specify a log file for compiler messages.
        </p></dd><dt><span class="term">-progress</span></dt><dd><p>Show progress (requires -log mode).
        </p></dd><dt><span class="term">-time</span></dt><dd><p>Display speed information.
        </p></dd><dt><span class="term">-noExit</span></dt><dd><p>Do not call System.exit(n) at end of compilation
			(n=0 if no error)
        </p></dd><dt><span class="term">-repeat <em class="replaceable"><code>N</code></em></span></dt><dd><p>Repeat compilation process N times 
        (typically to do performance analysis).
        </p></dd><dt><span class="term">-XterminateAfterCompilation</span></dt><dd><p>Causes compiler to terminate before weaving
        </p></dd><dt><span class="term">-XaddSerialVersionUID</span></dt><dd><p>Causes the compiler to calculate and add
        the SerialVersionUID field to any type implementing
        Serializable that is affected by an aspect.  The field
        is calculated based on the class before weaving has
        taken place.
        </p></dd><dt><span class="term">-Xreweavable[:compress]</span></dt><dd><p>(Experimental - deprecated as now default) 
            Runs weaver in reweavable mode which causes
        it to create woven classes that can be rewoven, subject to the restriction that
        on attempting a reweave all the types that advised the woven type must be accessible.
        </p></dd><dt><span class="term">-XnoInline</span></dt><dd><p>(Experimental) do not inline around advice
        </p></dd><dt><span class="term">-XincrementalFile <em class="replaceable"><code>file</code></em></span></dt><dd><p>(Experimental) This works like incremental mode, 
        but using a file rather than standard input to control the compiler.  
        It will recompile each time file is changed and
        and halt when file is deleted.
        </p></dd><dt><span class="term">-XserializableAspects</span></dt><dd><p>
        (Experimental) Normally it is an error to declare
        aspects Serializable.  This option removes that restriction.
        </p></dd><dt><span class="term">-XnotReweavable</span></dt><dd><p>
    (Experimental) Create class files that can't be subsequently rewoven by AspectJ.
        </p></dd><dt><span class="term">-Xajruntimelevel:1.2, ajruntimelevel:1.5</span></dt><dd><p>
        (Experimental) Allows code to be generated that targets a 1.2 or a 1.5 level AspectJ runtime (default 1.5)
         </p></dd></dl></div></div><div class="refsect2"><a name="idp61521248"></a><h3>File names</h3><p>ajc accepts source files with either the <code class="filename">.java</code>
    extension or the <code class="filename">.aj</code> extension.  We normally use
    <code class="filename">.java</code> for all of our files in an AspectJ system -- files
    that contain aspects as well as files that contain classes.  However, if
    you have a need to mechanically distinguish files that use AspectJ's
    additional functionality from those that are pure Java we recommend using
    the <code class="filename">.aj</code> extension for those files.</p><p>We'd like to discourage other means of mechanical distinction such as
    naming conventions or sub-packages in favor of the <code class="filename">.aj</code>
    extension.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Filename conventions are hard to enforce and lead to awkward names
    for your aspects.  Instead of <code class="filename">TracingAspect.java</code> we
    recommend using <code class="filename">Tracing.aj</code> (or just
    <code class="filename">Tracing.java</code>) instead.</p></li><li class="listitem"><p>Sub-packages move aspects out of their natural place in a system
    and can create an artificial need for privileged aspects.  Instead of
    adding a sub-package like <code class="filename">aspects</code> we recommend using the
    <code class="filename">.aj</code> extension and including these files in your existing
    packages instead.</p></li></ul></div></div><div class="refsect2"><a name="idp61531168"></a><h3>Compatibility</h3><p>
        AspectJ is a compatible extension to the Java programming language. The
        AspectJ compiler adheres to the <a class="ulink" href="http://java.sun.com/docs/books/jls/index.html" target="_top"> <em class="citetitle">The Java Language Specfication, Second
        Edition</em></a> and to the <a class="ulink" href="http://java.sun.com/docs/books/vmspec/index.html" target="_top"><em class="citetitle">The Java Virtual Machine Specification, Second
        Edition</em></a> and runs on any Java 2 compatible
        platform. The code it generates runs on any Java 1.1 or later
        compatible platform.
        For more information on compatibility with
          Java and with previous releases of AspectJ,
          see
          <a class="xref" href="compatibility.html#versionCompatibility" title="Version Compatibility">AspectJ Version Compatibility</a>.
      </p></div><div class="refsect2"><a name="idp61535424"></a><h3>Examples</h3><div class="example"><a name="simpleexample"></a><p class="title"><b>Example 2.1. A simple example</b></p><div class="example-contents"><p>Compile two files:</p><pre class="programlisting">
        ajc HelloWorld.java Trace.java
        </pre></div></div><br class="example-break"><div class="example"><a name="exampleusingargfile"></a><p class="title"><b>Example 2.2. An example using -argfile/@</b></p><div class="example-contents"><p>
          To avoid specifying file names on the command line, 
          list source files in a line-delimited text argfile.
          Source file paths may be absolute or relative to the argfile,
          and may include other argfiles by @-reference.
          The following file <code class="literal">sources.lst</code>
          contains absolute and relative files and @-references:
          </p><pre class="programlisting">
Gui.java
/home/user/src/Library.java
data/Repository.java
data/Access.java
@../../common/common.lst
@/home/user/src/lib.lst
view/body/ArrayView.java</pre><p>Compile the files using either the -argfile or @ form:</p><pre class="programlisting">
ajc -argfile sources.lst
ajc @sources.lst</pre><p>
        Argfiles are also supported by jikes and javac, so you 
        can use the files in hybrid builds.  However, the support varies:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Only ajc accepts command-line options</p></li><li class="listitem"><p>Jikes and Javac do not accept internal @argfile references.
            </p></li><li class="listitem"><p>Jikes and Javac only accept the @file form on the command line.</p></li></ul></div></div></div><br class="example-break"><div class="example"><a name="examplebytecode"></a><p class="title"><b>Example 2.3. An example using -inpath and -aspectpath</b></p><div class="example-contents"><p>Bytecode weaving using -inpath:
          AspectJ 1.2 supports weaving .class files in input zip/jar files 
          and directories. 
          Using input jars is like compiling the corresponding 
          source files, and all binaries are emitted to output.  Although 
          Java-compliant compilers may differ in their output, ajc should 
          take as input any class files produced by javac, jikes, eclipse, 
          and, of course, ajc.  Aspects included in -inpath will be woven into
          like other .class files, and they will affect other types as usual.
        </p><p>Aspect libraries using -aspectpath:
          AspectJ 1.1 supports weaving from read-only libraries containing 
          aspects.  Like input jars, they affect all input; unlike input 
          jars, they themselves are not affected or emitted as output.  
          Sources compiled with aspect libraries must be run with the same 
          aspect libraries on their classpath. 
        </p><p>The following example builds the tracing example in a 
        command-line environment; it creates a read-only aspect library, 
      compiles some classes for use as input bytecode, and 
       compiles the classes and other sources with the aspect library.
        </p><p>The tracing example is in the AspectJ distribution 
        ({aspectj}/doc/examples/tracing).  This uses the following files:
        </p><pre class="programlisting">
 aspectj1.1/ 
   bin/ 
     ajc 
   lib/ 
     aspectjrt.jar 
   examples/ 
     tracing/ 
       Circle.java 
       ExampleMain.java 
       lib/ 
         AbstractTrace.java 
         TraceMyClasses.java 
       notrace.lst 
       Square.java 
       tracelib.lst 
       tracev3.lst 
       TwoDShape.java 
       version3/ 
         Trace.java 
         TraceMyClasses.java 
        </pre><p>Below, the path separator is taken as ";", but file separators 
are "/".  All commands are on one line.  Adjust paths and 
commands to your environment as needed. 

</p><p>Setup the path, classpath, and current directory:</p><pre class="programlisting">
    cd examples 
    export ajrt=../lib/aspectjrt.jar 
    export CLASSPATH="$ajrt" 
    export PATH="../bin:$PATH" 
        </pre><p>Build a read-only tracing library:</p><pre class="programlisting">
    ajc -argfile tracing/tracelib.lst -outjar tracelib.jar 
        </pre><p>Build the application with tracing in one step:</p><pre class="programlisting">
    ajc -aspectpath tracelib.jar -argfile tracing/notrace.lst -outjar tracedapp.jar 
        </pre><p>Run the application with tracing:</p><pre class="programlisting">
    java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain 
        </pre><p>Build the application with tracing from binaries in two steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
(a) Build the application classes (using javac for demonstration's sake):</p><pre class="programlisting">
    mkdir classes 
    javac -d classes tracing/*.java 
    jar cfM app.jar -C classes . 
        </pre></li><li class="listitem"><p>
(b) Build the application with tracing:</p><pre class="programlisting">
    ajc -inpath app.jar -aspectpath tracelib.jar -outjar tracedapp.jar 
        </pre></li></ul></div><p>Run the application with tracing (same as above):</p><pre class="programlisting">
    java -classpath "$ajrt;tracedapp.jar;tracelib.jar" tracing.ExampleMain 
        </pre><p>Run the application without tracing:</p><pre class="programlisting">
    java -classpath "app.jar" tracing.ExampleMain
        </pre></div></div><br class="example-break"></div><div class="refsect2"><a name="idp61560704"></a><h3>The AspectJ compiler API</h3><p>The AspectJ compiler is implemented completely in Java and can be
        called as a Java class.  The only interface that should be considered
        public are the public methods in <code class="literal">org.aspectj.tools.ajc.Main</code>.
        E.g., <code class="literal">main(String[] args)</code> takes the
        the standard <span class="command"><strong>ajc</strong></span> command line arguments. 
        This means that an alternative way to run the
        compiler is </p><div class="cmdsynopsis"><p><code class="command"><code class="literal">java org.aspectj.tools.ajc.Main</code></code>  [<em class="replaceable"><code>option...</code></em>] [<em class="replaceable"><code>file...</code></em>]</p></div><p>To access compiler messages programmatically, use the methods
         <code class="literal">setHolder(IMessageHolder holder)</code> and/or
         <code class="literal">run(String[] args, IMessageHolder holder)</code>.
		  <code class="literal">ajc</code> reports each message to the holder
		  using <code class="literal">IMessageHolder.handleMessage(..)</code>.
		  If you just want to collect the messages, use
		  <code class="literal">MessageHandler</code> as your		  
		  <code class="literal">IMessageHolder</code>.
		  For example, compile and run the following with 
		  <code class="literal">aspectjtools.jar</code> on the classpath:
      </p><pre class="programlisting">
import org.aspectj.bridge.*;
import org.aspectj.tools.ajc.Main;
import java.util.Arrays;

public class WrapAjc {
  public static void main(String[] args) {
    Main compiler = new Main();
    MessageHandler m = new MessageHandler();
    compiler.run(args, m);
    IMessage[] ms = m.getMessages(null, true);
    System.out.println("messages: " + Arrays.asList(ms));
  }
}
        </pre></div><div class="refsect2"><a name="idp61573664"></a><h3>Stack Traces and the SourceFile attribute</h3><p>Unlike traditional java compilers, the AspectJ compiler may in
            certain cases generate classfiles from multiple source files.
            Unfortunately, the original Java class file format does not support 
            multiple
            SourceFile attributes.  In order to make sure all source file
            information is available, the AspectJ compiler may in some cases
            encode multiple filenames in the SourceFile attribute.  
            When the Java VM generates stack traces, it uses this attribute
            to specify the source file.
      </p><p>(The AspectJ 1.0 compiler also supports the .class file extensions of JSR-45.
      These permit compliant debuggers (such as jdb in Java 1.4.1) to identify 
      the right file and line even given many source files for a single class.
      JSR-45 support is planned for ajc in AspectJ 1.1, but is not in the initial
      release.  To get fully debuggable .class files, use the -XnoInline option.)  
      </p><p>Probably the only time you may see this format is when you view
            stack traces, where you may encounter traces of the format
      </p><pre class="programlisting">
java.lang.NullPointerException
  at Main.new$constructor_call37(Main.java;SynchAspect.java[1k]:1030)
</pre><p>where instead of the usual 
      </p><pre class="programlisting">
File:LineNumber
</pre><p>format, you see
      </p><pre class="programlisting">
File0;File1[Number1];File2[Number2] ... :LineNumber
</pre><p>In this case, LineNumber is the usual offset in lines plus the 
      "start line" of the actual source file.  That means you use LineNumber 
      both to identify the source file and to find the line at issue. 
      The number in [brackets] after each file tells you the
      virtual "start line" for that file (the first file has a start of 0).  
      </p><p> In our example from the null pointer exception trace, 
      the virtual start line is 1030.  Since the file SynchAspect.java
      "starts" at line 1000 [1k], the LineNumber points to line 30 of
      SynchAspect.java.
      </p><p> So, when faced with such stack traces, the way to find the actual
      source location is to look through the list of "start line" numbers to
      find the one just under the shown line number.  That is the file where
      the source location can actually be found.  Then, subtract that "start
      line" from the shown line number to find the actual line number within
      that file.
      </p><p>In a class file that comes from only a single source file, the AspectJ
            compiler generates SourceFile attributes consistent with
            traditional Java compilers.
      </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="command-line-tools.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="command-line-tools.html#ajc-ref-top">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ajdoc-ref-top.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. AspectJ command-line tools </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <code class="literal">ajdoc</code>, the AspectJ documentation tool</td></tr></table></div></body></html>