Jump to content

AspectJ: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Update Current Version, Update Current Version Reference Link
References: +reflist
 
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Short description|Aspect-oriented Java programming extension}}
{{Multiple issues|
{{More citations needed|date=March 2024}}
{{No footnotes|date=March 2024}}
}}
{{Infobox programming language
{{Infobox programming language
| name = AspectJ
| name = AspectJ
| logo =
| logo =
| caption = [[Cross-cutting concern|crosscutting]] objects for better modularity
| caption = [[Cross-cutting concern|crosscutting]] objects for better modularity
| paradigm = [[Aspect-oriented programming|aspect-oriented]]
| paradigm = [[Aspect-oriented programming|aspect-oriented]]
| released = {{Start date|2001}}
| released = {{Start date|2001}}
| designer =
| designer =
| developer = [[Eclipse Foundation]]
| developer = [[Eclipse Foundation]]
| latest release version = 1.9.4
| latest release version = {{wikidata|property|reference|edit|P348}}
| latest release date = {{Start date and age|{{wikidata|qualifier|P348|P577}}}}
| latest release date = {{release date|2019|05|10}} <ref name="Eclipse Consortium">{{cite web | work=Release README| title=AspectJ 1.9.4 | url=https://www.eclipse.org/aspectj/doc/released/README-194.html | accessdate=2019-06-11 }}</ref>
| typing =
| typing =
| implementations = [[The AspectJ Development Tools]] for [[Eclipse (software)|Eclipse]]
| implementations = [[The AspectJ Development Tools]] for [[Eclipse (software)|Eclipse]]
| dialects =
| dialects =
| influenced by =
| influenced by =
| influenced =
| influenced =
| programming language = [[Java (programming language)|Java]]
| programming language = [[Java (programming language)|Java]]
| operating system = [[Cross-platform]]
| operating system = [[Cross-platform]]
Line 19: Line 24:
| website = {{URL|http://www.eclipse.org/aspectj/}}
| website = {{URL|http://www.eclipse.org/aspectj/}}
| file ext = aj
| file ext = aj
| wikibooks =
| wikibooks =
}}
}}


'''AspectJ''' is an [[aspect-oriented programming]] (AOP) extension created at [[PARC (company)|PARC]] for the [[Java (programming language)|Java]] programming language. It is available in [[Eclipse Foundation]] open-source projects, both stand-alone and integrated into [[Eclipse (computing)|Eclipse]]. 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 [[Cross-cutting concern|crosscutting structure]] since its initial public release in 2001.
'''AspectJ''' is an [[aspect-oriented programming]] (AOP) extension for the [[Java (programming language)|Java]] programming language, created at [[PARC (company)|PARC]]. It is available in [[Eclipse Foundation]] open-source projects, both stand-alone and integrated into [[Eclipse (computing)|Eclipse]]. 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 [[Cross-cutting concern|crosscutting structure]] since its initial public release in 2001.


==Simple language description==
==Simple language description==
Line 29: Line 34:
;[[Extension method]]s: Allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an <code>acceptVisitor</code> (see [[visitor pattern]]) method to the <code>Point</code> class:
;[[Extension method]]s: Allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an <code>acceptVisitor</code> (see [[visitor pattern]]) method to the <code>Point</code> class:


:<source lang="aspectj">
:<syntaxhighlight lang="aspectj">
aspect VisitAspect {
aspect VisitAspect {
void Point.acceptVisitor(Visitor v) {
void Point.acceptVisitor(Visitor v) {
Line 35: Line 40:
}
}
}
}
</syntaxhighlight>
</source>


;[[Pointcut]]s: Allow a programmer to specify [[join point]]s (well-defined moments in the execution of a program, like method call, object instantiation, or variable access). All pointcuts are expressions ([[Aspect-oriented software development#Quantification and obliviousness|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 <code>Point</code> whose name begins with <code>set</code>:
;[[Pointcut]]s: Allow a programmer to specify [[join point]]s (well-defined moments in the execution of a program, like method call, object instantiation, or variable access). All pointcuts are expressions ([[Aspect-oriented software development#Quantification and obliviousness|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 <code>Point</code> whose name begins with <code>set</code>:


:<source lang="aspectj">
:<syntaxhighlight lang="aspectj">
pointcut set() : execution(* set*(..) ) && this(Point);
pointcut set() : execution(* set*(..) ) && this(Point);
</syntaxhighlight>
</source>


;[[Advice (programming)|Advices]]: Allow a programmer to specify code to run at a join point matched by a [[pointcut]]. The actions can be performed ''before'', ''after'', or ''around'' the specified [[join point]]. Here, the advice refreshes the display every time something on <code>Point</code> is set, using the pointcut declared above:
;[[Advice (programming)|Advices]]: Allow a programmer to specify code to run at a join point matched by a [[pointcut]]. The actions can be performed ''before'', ''after'', or ''around'' the specified [[join point]]. Here, the advice refreshes the display every time something on <code>Point</code> is set, using the pointcut declared above:


:<source lang="aspectj">
:<syntaxhighlight lang="aspectj">
after () : set() {
after () : set() {
Display.update();
Display.update();
}
}
</syntaxhighlight>
</source>


AspectJ also supports limited forms of pointcut-based static checking and aspect reuse (by inheritance). See the [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide] for a more detailed description of the language.
AspectJ also supports limited forms of pointcut-based static checking and aspect reuse (by inheritance). See the [http://www.eclipse.org/aspectj/doc/released/progguide/index.html AspectJ Programming Guide] for a more detailed description of the language.
Line 67: Line 72:


==History and contributors==
==History and contributors==
[[Gregor Kiczales]] started and led the [[Xerox PARC]] 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]] team members 12 and 13) were the original compiler and weaver engineers, [[Mik Kersten]] implemented the IDE integration and started the [http://eclipse.org/ajdt Eclipse AJDT] project with [[Adrian Colyer]] (current lead of the [http://eclipse.org/aspectj AspectJ project]) and [[Andrew Clement]] (current compiler engineer).
[[Gregor Kiczales]] started and led the [[Xerox PARC]] 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]] team members 12 and 13) were the original compiler and weaver engineers, [[Mik Kersten]] implemented the IDE integration and started the [http://eclipse.org/ajdt Eclipse AJDT] project with [[Adrian Colyer]] and [[Andrew Clement]]. After Adrian Colyer, Andrew Clement took over as project lead and main contributor for AspectJ. AJDT has since been retired as a separate project and taken over into the Eclipse AspectJ umbrella project to streamline maintenance. However, both AspectJ and AJDT are still maintained in separate source repositories.

In 2021, [[Alexander Kriegisch]] joined the project, first as a contributor, then as a committer and maintainer. Since March 2021, he is basically the sole maintainer. Since 2024, he also is formally the AspectJ and AJDT project lead.


The [[AspectBench Compiler]] was developed and is maintained as a joint effort of the [[Programming Tools Group]] at the [[Oxford University Computing Laboratory]], the [[Sable Research Group]] at [[McGill University]], and the Institute for [[BRICS Institute|Basic Research in Computer Science (BRICS)]].
The [[AspectBench Compiler]] was developed and is maintained as a joint effort of the [[Programming Tools Group]] at the [[Oxford University Computing Laboratory]], the [[Sable Research Group]] at [[McGill University]], and the Institute for [[BRICS Institute|Basic Research in Computer Science (BRICS)]].


===AspectWerkz===
===AspectWerkz===
AspectWerkz is a dynamic, lightweight and high-performance [[Aspect-oriented programming|AOP/AOSD]] framework for [[Java (programming language)|Java]]. It has been merged with the AspectJ project, which supports AspectWerkz functionality since AspectJ 5.
AspectWerkz was a dynamic, lightweight and high-performance [[Aspect-oriented programming|AOP/AOSD]] framework for [[Java (programming language)|Java]]. It has been merged with the AspectJ project,<ref>{{Cite web |date=2006-07-12 |title=AspectJ and AspectWerkz to Join Forces |url=http://aspectwerkz.codehaus.org/index-merge.html|url-status=dead|archive-url=https://web.archive.org/web/20060712004603/http://aspectwerkz.codehaus.org/index-merge.html |access-date=2024-03-19 |website=Aspectwerkz|archive-date=July 12, 2006}}</ref> 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.
[[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]]s. It utilizes bytecode modification to [[Aspect weaver|weave]] classes at project build-time, class load time, as well as [[Run time (program lifecycle phase)|runtime]]. It uses standardized {{clarify-span|JVM level APIs|date=September 2013}}. 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.
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]]s. It utilizes bytecode modification to [[Aspect weaver|weave]] classes at project build-time, class load time, as well as [[Run time (program lifecycle phase)|runtime]]. It uses standardized {{clarify span|JVM level APIs|date=September 2013}}. 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 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.
Line 88: Line 95:


==References==
==References==
{{reflist}}
{{refbegin}}
{{refbegin}}
*{{citation
* {{citation
| first1 = Ramnivas
| first1 = Ramnivas
| last1 = Laddad
| last1 = Laddad
Line 98: Line 106:
| pages = 550
| pages = 550
| isbn = 978-1-933988-05-4
| isbn = 978-1-933988-05-4
| url =
}}
}}
*{{citation
* {{citation
| first1 = Russ
| first1 = Russ
| last1 = Miles
| last1 = Miles
Line 111: Line 118:
| url = http://oreilly.com/catalog/9780596006549/
| url = http://oreilly.com/catalog/9780596006549/
}}
}}
*{{citation
* {{citation
| first1 = Adrian
| first1 = Adrian
| last1 = Colyer
| last1 = Colyer
Line 128: Line 135:
| url = http://www.informit.com/store/product.aspx?isbn=0321245873
| url = http://www.informit.com/store/product.aspx?isbn=0321245873
}}
}}
*{{citation
* {{citation |first1 = Joseph D.
| first1 = Joseph D.
|last1 = Gradecki
| last1 = Gradecki
|first2 = Nicholas
| first2 = Nicholas
|last2 = Lesiecki
|title = Mastering AspectJ: Aspect-Oriented Programming in Java
| last2 = Lesiecki
|date = March 7, 2003
| title = Mastering AspectJ: Aspect-Oriented Programming in Java
| date = March 7, 2003
|edition = 1st
|publisher = [[John Wiley & Sons|Wiley]]
| edition = 1st
|pages = [https://archive.org/details/masteringaspectj00grad/page/456 456]
| publisher = [[John Wiley & Sons|Wiley]]
| pages = 456
|isbn = 978-0-471-43104-6
|url = https://archive.org/details/masteringaspectj00grad/page/456
| isbn = 978-0-471-43104-6
|url-access = registration
| url = http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471431044.html
}}
}}
{{refend}}
{{refend}}
Line 145: Line 152:
== External links ==
== External links ==
* [https://web.archive.org/web/20170811190325/http://www.eclipse.org/ajdt/ AJDT]
* [https://web.archive.org/web/20170811190325/http://www.eclipse.org/ajdt/ AJDT]
* Aspect bench : http://www.sable.mcgill.ca/abc
* Aspect bench : https://web.archive.org/web/20170816093700/http://www.sable.mcgill.ca/abc/
* [http://eclipse.org/aspectj AspectJ Home Page]
* [https://web.archive.org/web/20170805180224/http://www.eclipse.org/aspectj/ AspectJ Home Page]
* [https://web.archive.org/web/20060706114810/http://aspectwerkz.codehaus.org/ AspectWerkz Project homepage]
* [https://web.archive.org/web/20060706114810/http://aspectwerkz.codehaus.org/ AspectWerkz Project homepage]
* [http://www.ibm.com/developerworks/java/library/j-aspectj Improve modularity with aspect-oriented programming]
* [http://www.ibm.com/developerworks/java/library/j-aspectj Improve modularity with aspect-oriented programming]
* [http://java2novice.com/spring/aop-and-aspectj-introduction/ Spring AOP and AspectJ Introduction]
* [http://java2novice.com/spring/aop-and-aspectj-introduction/ Spring AOP and AspectJ Introduction]
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html The AspectJ<sup>TM</sup> Programming Guide]
* [http://www.eclipse.org/aspectj/doc/released/progguide/index.html The AspectJ Programming Guide]
* Xerox has {{US patent|6467086}} for AOP/AspectJ, but published AspectJ source code under the [http://www.eclipse.org/legal/cpl-v10.html Common Public License], which grants some patent rights.
* Xerox has {{US patent|6467086}} for AOP/AspectJ, but published AspectJ source code under the [http://www.eclipse.org/legal/cpl-v10.html Common Public License], which grants some patent rights.



Latest revision as of 04:05, 21 March 2024

AspectJ
Paradigmaspect-oriented
DeveloperEclipse Foundation
First appeared2001 (2001)
Stable release
1.9.22.1[1] Edit this on Wikidata / 11 May 2024; 6 months ago (11 May 2024)
Implementation languageJava
OSCross-platform
LicenseEclipse Public License
Filename extensionsaj
Websitewww.eclipse.org/aspectj/
Major implementations
The AspectJ Development Tools for Eclipse

AspectJ is an aspect-oriented programming (AOP) extension for the Java programming language, created at PARC. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. 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

[edit]

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 methods
Allow a programmer to add methods, fields, or interfaces to existing classes from within the aspect. This example adds an acceptVisitor (see visitor pattern) method to the Point class:
aspect VisitAspect {
  void Point.acceptVisitor(Visitor v) {
    v.visit(this);
  }
}
Pointcuts
Allow a programmer to specify join points (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. 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();
}

AspectJ also supports limited forms of pointcut-based static checking and aspect reuse (by inheritance). See the AspectJ Programming Guide for a more detailed description of the language.

AspectJ compatibility and implementations

[edit]

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, 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 language features like generics and annotations, and integrated annotation-style pure-java aspects from AspectWerkz.

The Eclipse project supports both command-line and Ant interfaces. A related Eclipse project has steadily improved the Eclipse IDE support for AspectJ (called AspectJ Development Tools (AJDT)) and other providers of crosscutting structure. IDE support for emacs, NetBeans, and JBuilder 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 the 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. A sister Spring project, Spring Roo, automatically maintains AspectJ inter-type declarations as its principal code generation output.

History and contributors

[edit]

Gregor Kiczales started and led the Xerox PARC 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 team members 12 and 13) were the original compiler and weaver engineers, Mik Kersten implemented the IDE integration and started the Eclipse AJDT project with Adrian Colyer and Andrew Clement. After Adrian Colyer, Andrew Clement took over as project lead and main contributor for AspectJ. AJDT has since been retired as a separate project and taken over into the Eclipse AspectJ umbrella project to streamline maintenance. However, both AspectJ and AJDT are still maintained in separate source repositories.

In 2021, Alexander Kriegisch joined the project, first as a contributor, then as a committer and maintainer. Since March 2021, he is basically the sole maintainer. Since 2024, he also is formally the AspectJ and AJDT project lead.

The AspectBench Compiler was developed and is maintained as a joint effort of the Programming Tools Group at the Oxford University Computing Laboratory, the Sable Research Group at McGill University, and the Institute for Basic Research in Computer Science (BRICS).

AspectWerkz

[edit]

AspectWerkz was a dynamic, lightweight and high-performance AOP/AOSD framework for Java. It has been merged with the AspectJ project,[2] 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 annotations. It utilizes bytecode modification to weave classes at project build-time, class load time, as well as runtime. It uses standardized JVM level APIs[clarify]. 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. The LGPL-style license allows the use of AspectWerkz 2.0 in both commercial and open source projects.

See also

[edit]

References

[edit]
  1. ^ "Release 1.9.22.1". 11 May 2024. Retrieved 20 May 2024.
  2. ^ "AspectJ and AspectWerkz to Join Forces". Aspectwerkz. 2006-07-12. Archived from the original on July 12, 2006. Retrieved 2024-03-19.
[edit]