Section 6.3. ASPECTJ TOOLS


6.3. ASPECTJ TOOLS

This section presents a brief history and overview of the AspectJ compiler and the accompanying IDE support, ajdoc tool, and Ant tasks.

6.3.1. History

A good overview of the early history of aspect-oriented programming and AspectJ can be found in Chapter 5 of this book [7]. Table 6-2 summarizes the history of AspectJ since that time.

Table 6-2. The Recent History of AspectJ

AspectJ Version

Released

Significant Features

0.1

4/98

Domain specific languages: COOL (for synchronization) and RIDL (for remote invocation).

0.2

6/98

General purpose language.

0.3

5/99

Rewrite of AspectJ compiler from Lisp to Java.

0.5

1/00

ajdoc and first IDE support.

 

8/00

Compiler and core tools released as open-source.

1.0.0

11/01

First version to compile directly to bytecodes. Ant tasks and AspectJ Browser added.

 

2/02

AspectJ Development Tools project started on Eclipse.org.

1.1beta

12/02

AspectJ no longer a PARC project but an Eclipse technology project. Compiler extends Eclipse compiler and includes back-end weaving.

1.1.0

6/03

Aspect libraries, weaving into jar files, and incremental compilation.

1.2

4/04

Improved compiler (faster compilation, better error messages, and better generated code). Load-time weaving support.


6.3.2. The Compiler

The AspectJ compiler translates AspectJ source code into Java bytecodes. It supports a variety of options for achieving that end, and these are discussed in Section 6.3.2.1. Section 6.3.2.2 provides a high-level overview of the internal architecture of the compiler.

6.3.2.1 Features

The simplest way to use the AspectJ compiler (ajc) is to present it with a list of source files (.java or .aj). The compiler produces the corresponding Java bytecode class files.

The compiler can also take as input Java class files (.class), either in directories or in jar files, and link (weave) these with aspects to produce new versions of those classes. The aspects can be passed to the compiler in either source or binary form. Binary form aspects are packaged in jar files as aspect libraries: ajc supports the aspectpath option to pass aspect libraries to the compiler and the outjar option to assist in creating them in the first place.

As of AspectJ 1.2, class files produced by the ajc compiler can be re-linked with new versions of aspects and with additional aspects without needing to go back to the source files. This is supported by the Xreweavable option. The binary linking capabilities of the AspectJ compiler mean that the linker portion can be used to link classes with aspects as late as class definition time during class loading. AspectJ ships with a sample class loader that exploits this and an API for integrating the linker into an existing class loader hierarchy.

The AspectJ compiler also supports incremental compilation. If the source files for one or more classes are updated (or added, or deleted), then the AspectJ compiler recompiles and re-links just the classes defined in those files. The compiler can also detect updates to and incrementally re-link classes passed to it in binary form (.class files). If a change is detected in an aspect, then only the aspect is recompiled, but all the class files defined to the compiler are re-linked.

6.3.2.2 Implementation

The front-end of the compiler is responsible for translating AspectJ source files into class files. It is built as an extension to the Eclipse Java Development Tools (JDT) compiler. Aspects are compiled into class files that contain methods (with mangled names) for advice and inter-type declarations and have pointcut, advice, and other AspectJ-specific information encoded in attributes in the constant pool. The back-end of the compiler (the weaver) implements the bytecode transformations indicated by the encoded attributes to produce the final linked versions of the class files. Figure 6-3 provides an overview of the compilation process.

Figure 6-3. The AspectJ compiler, ajc.


The front-end part of the compilation process is complicated by inter-type declarations and privileged aspectsthese constructs all require changes to the Java compiler's default name-binding and static checking behavior.

The back-end of the compiler instruments classes by (for example) inserting calls to the precompiled advice methods. Crudely, each class file is processed in turn, and for each place in the bytecode that represents a join point in AspectJ's join point model, the pointcut expressions associated with all the advice in the system are checked to see if they could match at the join point. If a match is possible, then a call to the advice is inserted. Sometimes a definite match cannot be determined until runtime, in which case a run-time test is also inserted to guard the call to the advice. A good overview of AspectJ's weaving is found in [5]. An AspectJ developer's guide to the compiler and weaver is also available [6].

6.3.3. IDE Support for AspectJ

The goal of the IDE support provided for AspectJ is to make it as easy as possible for programmers to develop, understand, and work with AspectJ programs. A lot of emphasis is placed on showing crosscutting structurefor example, the advises and advised-by relationships that are shown for advice.

Figure 6-4 shows the DirtyTracking aspect from Listing 6-5 in AJDT under Eclipse. Syntax highlighting and code-completion are available in the editor buffer, and the outline view shows the places affected by advice, allowing the programmer to navigate among them.

Figure 6-4. DirtyTracking aspect in AJDT.


For working with larger software systems, AJDT also provides an aspect visualization perspective that uses a SeeSoft style presentation [4] to display the places in the source code that are affected by an aspect. The display can also be used for navigationclicking on a bar takes you to the source line. Figure 6-5 shows an example of the visualizer in action.

Figure 6-5. Aspect visualization.


Debugging AspectJ programs is also supported, as shown in Figure 6-6. More details about the features and functions of AJDT can be found on the AJDT project home page [2].

Figure 6-6. Debugging support.


For users not working in the Eclipse environment, AspectJ support is also available in Emacs, JBuilder, and NetBeans. The AspectJ distribution includes a simple browser, ajbrowser, which also shows the crosscutting structure of AspectJ programs.

6.3.4. Generating Documentation with ajdoc

The ajdoc tool produces javadoc-like documentation for AspectJ programs. Figures 6-7 and 6-8 show the output of ajdoc for an aspect and for a class with methods advised by an aspect. The goal of the tool is once more to make the crosscutting nature of the aspects in the program explicit, this time in the documentation.

Figure 6-7. ajdoc of an aspect.


Figure 6-8. Crosscutting structure shown in advised methods.


6.3.5. Ant Tasks

The Ant tasks included in the AspectJ distribution are designed to be plug-compatible with their Java counterparts wherever possible. The tasks allow the full set of features of the AspectJ compiler to be exploited, including the creation and use of aspect libraries and linking into existing class files.



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net