AspectJ is an
aspect-oriented programming
In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
(AOP) extension created at
PARC for the
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
programming language. It is available in
Eclipse Foundation
The Eclipse Foundation AISBL is an independent, Europe-based not-for-profit corporation that acts as a steward of the Eclipse open source software development community, with legal jurisdiction in the European Union. It is an organization suppo ...
open-source projects, both stand-alone and integrated into
Eclipse
An eclipse is an astronomical event that occurs when an astronomical object or spacecraft is temporarily obscured, by passing into the shadow of another body or by having another body pass between it and the viewer. This alignment of three ce ...
. AspectJ has become a widely used de facto standard for AOP by emphasizing simplicity and usability for end users. It uses Java-like syntax, and included IDE integrations for displaying
crosscutting structure since its initial public release in 2001.
Simple language description
All valid Java programs are also valid AspectJ programs, but AspectJ lets programmers define special constructs called ''
aspects''. Aspects can contain several entities unavailable to standard classes. These are:
;
Extension method
In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-orie ...
s: Allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an
acceptVisitor
(see
visitor pattern
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to ...
) method to the
Point
class:
:
aspect VisitAspect
;
Pointcut In aspect-oriented programming, a pointcut is a set of join points. Pointcut specifies where exactly to apply advice, which allows separation of concerns and helps in modularizing business logic. Pointcuts are often specified using class names or m ...
s: Allow a programmer to specify
join point
In computer science, a join point is a point in the control flow of a program where the control flow can arrive via two different paths. In particular, it's a basic block that has more than one predecessor. In aspect-oriented programming a set of ...
s (well-defined moments in the execution of a program, like method call, object instantiation, or variable access). All pointcuts are expressions (
quantifications) that determine whether a given join point matches. For example, this point-cut matches the execution of any instance method in an object of type
Point
whose name begins with
set
:
:
pointcut set() : execution(* set*(..) ) && this(Point);
;
Advices: Allow a programmer to specify code to run at a join point matched by a
pointcut In aspect-oriented programming, a pointcut is a set of join points. Pointcut specifies where exactly to apply advice, which allows separation of concerns and helps in modularizing business logic. Pointcuts are often specified using class names or m ...
. The actions can be performed ''before'', ''after'', or ''around'' the specified
join point
In computer science, a join point is a point in the control flow of a program where the control flow can arrive via two different paths. In particular, it's a basic block that has more than one predecessor. In aspect-oriented programming a set of ...
. Here, the advice refreshes the display every time something on
Point
is set, using the pointcut declared above:
:
after () : set()
AspectJ also supports limited forms of pointcut-based static checking and aspect reuse (by inheritance). See th
AspectJ Programming Guidefor a more detailed description of the language.
AspectJ compatibility and implementations
AspectJ can be implemented in many ways, including
source-weaving or
bytecode-weaving, and directly in the
virtual machine (VM). In all cases, the AspectJ program becomes a valid Java program that runs in a Java VM. Classes affected by aspects are binary-compatible with unaffected classes (to remain compatible with classes compiled with the unaffected originals). Supporting multiple implementations allows the language to grow as technology changes, and being Java-compatible ensures platform availability.
Key to its success has been engineering and language decisions that make the language usable and programs deployable. The original Xerox AspectJ implementation used source weaving, which required access to source code. When Xerox contributed the code to Eclipse, AspectJ was reimplemented using the Eclipse Java compiler and a bytecode weaver based on
BCEL
The Byte Code Engineering Library (BCEL) is a project sponsored by the Apache Foundation previously under their Jakarta charter to provide a simple API for decomposing, modifying, and recomposing binary Java classes (I.e. bytecode). The project ...
, so developers could write aspects for code in binary (.class) form. At this time the AspectJ language was restricted to support a per-class model essential for incremental compilation and load-time weaving. This made IDE integrations as responsive as their Java counterparts, and it let developers deploy aspects without altering the build process. This led to increased adoption, as AspectJ became usable for impatient Java programmers and enterprise-level deployments. Since then, the Eclipse team has increased performance and correctness, upgraded the AspectJ language to support
Java 5
The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community P ...
language features like
generics and
annotations
An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented in the margin of book pages. For anno ...
, and integrated annotation-style pure-java aspects from
AspectWerkz
AspectJ is an aspect-oriented programming (AOP) extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become a widely us ...
.
The Eclipse project supports both command-line and
Ant
Ants are eusocial insects of the family Formicidae and, along with the related wasps and bees, belong to the order Hymenoptera. Ants evolved from vespoid wasp ancestors in the Cretaceous period. More than 13,800 of an estimated total of 22 ...
interfaces. A related Eclipse project has steadily improved the Eclipse IDE support for AspectJ (called ''AspectJ Development Tools (
AJDT
AspectJ is an aspect-oriented programming (AOP) extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become a widely us ...
)'') and other providers of crosscutting structure. IDE support for
emacs
Emacs , originally named EMACS (an acronym for "Editor MACroS"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
,
NetBeans
NetBeans is an integrated development environment (IDE) for Java (programming language), Java. NetBeans allows applications to be developed from a set of modular software components called ''modules''. NetBeans runs on Microsoft Windows, Windows, ...
, and
JBuilder
JBuilder is a discontinued integrated development environment (IDE) for the programming language Java from Embarcadero Technologies. Originally developed by Borland, JBuilder was spun off with CodeGear which was eventually purchased by Embarcader ...
foundered when Xerox put them into open source, but support for Oracle's JDeveloper did appear. IDE support has been key to Java programmers using AspectJ and understanding crosscutting concerns.
BEA has offered limited VM support for aspect-oriented extensions, but for extensions supported in all Java VM's would require agreement through Sun's Java Community Process (see also the java.lang.instrument package available since Java SE 5 — which is a common ground for JVM load-time instrumentation).
Academic interest in the semantics and implementation of
aspect-oriented languages has surrounded AspectJ since its release. The leading research implementation of AspectJ is th
AspectBench Compiler or ''abc''; it supports extensions for changing the syntax and semantics of the language and forms the basis for many AOP experiments that the AspectJ team can no longer support, given its broad user base.
Many programmers discover AspectJ as an enabling technology for other projects, most notably
Spring AOP
The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java ...
. A sister Spring project,
Spring Roo
Spring Roo is an open-source software tool that uses convention-over-configuration principles to provide rapid application development of Java-based enterprise software. The resulting applications use common Java technologies such as Spring Fram ...
, automatically maintains AspectJ
inter-type declarations as its principal code generation output.
History and contributors
Gregor Kiczales
Gregor Kiczales is an American computer scientist. He is currently a full time professor of computer science at the University of British Columbia in Vancouver, British Columbia, Canada. He is best known for developing the concept of aspect-orien ...
started and led the
Xerox PARC
PARC (Palo Alto Research Center; formerly Xerox PARC) is a research and development company in Palo Alto, California. Founded in 1969 by Jacob E. "Jack" Goldman, chief scientist of Xerox Corporation, the company was originally a division of Xero ...
team that eventually developed AspectJ. He coined the term ''crosscutting''. Fourth on the team,
Chris Maeda coined the term ''aspect-oriented programming.''
Jim Hugunin and
Erik Hilsdale (
Xerox PARC
PARC (Palo Alto Research Center; formerly Xerox PARC) is a research and development company in Palo Alto, California. Founded in 1969 by Jacob E. "Jack" Goldman, chief scientist of Xerox Corporation, the company was originally a division of Xero ...
team members 12 and 13) were the original compiler and weaver engineers,
Mik Kersten
Mik Kersten is a Polish- Canadian computer specialist who created and leads the open-source Eclipse Mylyn project. Kersten invented the Task-Focused Interface technology underlying Mylyn while working on his PhD at the University of British Col ...
implemented the IDE integration and started th
Eclipse AJDTproject with
Adrian Colyer (current lead of th
AspectJ project and
Andrew Clement (current compiler engineer).
The
AspectBench Compiler was developed and is maintained as a joint effort of the
Programming Tools Group at the
Oxford University Computing Laboratory
The Department of Computer Science is the computer science department of the University of Oxford, England, which is part of the university's Mathematical, Physical and Life Sciences Division, University of Oxford, Mathematical, Physical and Life ...
, the
Sable Research Group at
McGill University
McGill University (french: link=no, Université McGill) is an English-language public research university located in Montreal, Quebec, Canada. Founded in 1821 by royal charter granted by King George IV,Frost, Stanley Brice. ''McGill Universit ...
, and the Institute for
Basic Research in Computer Science (BRICS).
AspectWerkz
AspectWerkz is a dynamic, lightweight and high-performance
AOP/AOSD framework for
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
. It has been merged with the AspectJ project, which supports AspectWerkz functionality since AspectJ 5.
Jonas Boner and
Alex Vasseur engineered the AspectWerkz project, and later contributed to the AspectJ project when it merged in the AspectWerkz annotation style and load-time weaving support.
Unlike AspectJ prior to version 5, AspectWerkz did not add any new language constructs to Java, but instead supported declaration of aspects within
Java annotation
In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and Java packages may be annotated. Like Javadoc tags, Java annotations can ...
s. It utilizes bytecode modification to
weave classes at project build-time, class load time, as well as
runtime. It uses standardized . Aspects can be defined using either Java annotations (introduced with Java 5), Java 1.3/1.4 custom
doclet or a simple XML definition file.
AspectWerkz provides an API to use the very same aspects for proxies, hence providing a transparent experience, allowing a smooth transition for users familiar with proxies.
AspectWerkz is
free software
Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, no ...
. The
LGPL
The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
-style license allows the use of AspectWerkz 2.0 in both commercial and open source projects.
See also
*
Aspect-oriented programming
In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
*
Spring AOP
The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java ...
(part of the
Spring Framework
The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java ...
)
*
Aspect-oriented software development
In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding behavior to existing code (an advice) ''without'' modifying t ...
References
*
*
*
*
External links
AJDT* Aspect bench : https://web.archive.org/web/20170816093700/http://www.sable.mcgill.ca/abc/
AspectJ Home PageAspectWerkz Project homepageImprove modularity with aspect-oriented programmingSpring AOP and AspectJ Introduction* Xerox has for AOP/AspectJ, but published AspectJ source code under th
which grants some patent rights.
{{DEFAULTSORT:Aspectj
Programming languages
Aspect-oriented programming
Aspect-oriented software development
Cross-platform software
Eclipse (software)
Eclipse software
Eclipse technology
Java programming language family
Software distribution
Software using the Eclipse license
Programming languages created in 2001
2001 software
Cross-platform free software
High-level programming languages