Information About

Aspectj




In March 2005, AspectWerkz merged with AspectJ to form a single language. Other commercial Aspect-oriented Framework s include JBoss and Spring AOP .


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 Declaration s — allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an acceptVisitor method to the Point class:


::aspect VisitAspect {
:::Point.acceptVisitor(Visitor v) {
::::v.visit(this);
:::}
::}

  • Pointcut s — allow a programmer to specify a set of Join Point s (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 with set in an object of type Point:


  • ---.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 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

  • AJDT