AspectJ
From Free net encyclopedia
AspectJ is an aspect-oriented extension to the Java programming language created at Xerox PARC by Chris Maeda, who originally coined the term "aspect-oriented programming" (no one remembers exactly when). Gregor Kiczales coined the term "crosscutting". The Xerox group's work was integrated into the Eclipse Foundation's Eclipse Java IDE in December 2002, abandoning support for users of the Netbeans IDE at this point. This helped AspectJ become one of the most widely-used aspect-oriented languages.
In March 2005, AspectWerkz merged with AspectJ to form a single language. Other commercial Aspect-oriented frameworks include JBoss and Spring AOP.
Contents |
Simple Language Description
All valid Java programs are also valid AspectJ programs, but AspectJ also allows programmers to define special constructs called aspects. Aspects can contain several entities unavailable to standard classes. These are:
- inter-type declarations — allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an
acceptVisitor
method to thePoint
class:
aspect VisitAspect {
Point.acceptVisitor(Visitor v) {
v.visit(this);
}
}
- pointcuts — allow a programmer to specify a set of join points (well-defined moments in the execution of a program, like a method call, object instantiation, or variable accesses). All pointcuts are boolean expressions (quantifications) that evaluate to
true
whenever a matching joinpoint occurs. This pointcut captures all executions of any method that begins withset
in an object of typePoint
:
pointcut set() : execution(* *.set*(..) ) && this(Point);
- advice — allows a programmer to specify what actions to perform when a pointcut evaluates to true. The actions can be performed before, after, or around the specified join point. Here, the advice refreshes the display every time something on
Point
is set, using the pointcut declared above:
after () : set() {
Display.update();
}
See the AspectJ Programming Guide for a more detailed description of the language.
Tools, Compilation, and AspectJ
The compilation of an AspectJ program includes an additional stage compared to non-aspect-oriented languages. This stage is called weaving. Weaving occurs after the normal compilation of the non-aspect, or base code, completes. The weaving process takes the aspects (pointcuts and advice) and determines where the advice may apply and alters the bytecode appropriately. Weaving may occur immediately after compilation, or this process may be delayed until the classes are loaded into the JVM. This process is known as load-time weaving.
The most widely used and most efficient compiler for AspectJ is maintained with the AspectJ project, but there is another, more extensible and research oriented, compiler called the Aspect Bench Compiler, or abc.
A suite of tools designed specifically to work with AspectJ in the Eclipse Java IDE has been developed as another project in the Eclipse Foundation. It is called AJDT. These tools help programmers understand how the aspects crosscut the base code.
See also
External links
- http://eclipse.org/aspectj
- http://aspectbench.org/
- Xerox has Template:US patent for AOP/AspectJ, but published AspectJ source code under the Common Public License, which grants some patent rights.
- http://www.eclipse.org/aspectj/doc/released/progguide/index.html
- AJDTbg:AspectJ
de:AspectJ es:AspectJ it:Aspectj ja:AspectJ pl:AspectJ tr:AspectJ