Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
1. Aspect-oriented
Programming
Prof. Dr. Ralf Lämmel
Universität Koblenz-Landau
Software Languages Team
https://github.com/101companies/101repo/tree/master/languages/AspectJ/aspectJSamples
Non-101samples available here:
http://101companies.org/wiki/
Contribution:aspectJ
See special
copyright message
at the end of the
slide deck.
2. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Elevator pitch
Suppose you need to implement some tracing (aka logging)
functionality in your app. Chances are that code needs to be
scattered allover the app; see below. Can we do better than this.
Yes, use AOP!
See copyright notice
elsewhere in this deck.
3. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
class Point {
void set(int x, int y) {
TraceSupport.traceEntry("Point.set");
this.x = x; this.y = y;
TraceSupport.traceExit("Point.set");
}
}
class TraceSupport {
static int TRACELEVEL = 0;
static protected PrintStream stream = null;
static protected int callDepth = -1;
static void init(PrintStream _s) {stream=_s;}
static void traceEntry(String str) {
if (TRACELEVEL == 0) return;
callDepth++;
printEntering(str);
}
static void traceExit(String str) {
if (TRACELEVEL == 0) return;
callDepth--;
printExiting(str);
}
}
TraceSupport
Many classes (objects)
interact with the trace
facility.
Tracing without AOP
See copyright notice
elsewhere in this deck.
4. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Logging is a crosscutting concern.
These concerns donât fit into traditional modules.
Other examples:
⢠Error handling
⢠Synchronization
⢠Security
⢠Power management
⢠Memory management
⢠Performance optimizations
Costs of tangled code:
⢠Difficult to understand
⢠Difficult to change
⢠Increases with size of system
⢠Increases maintenance costs
⢠Very difficult to get rid of, if at all
See copyright notice
elsewhere in this deck.
5. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Aspect-Oriented Programming
⢠Crosscutting concerns
â ⌠are inherent to complex systems.
â ⌠serve important purposes.
â ⌠have a natural structure.
â ⌠can be captured in new kinds of modules.
â ⌠require designated language and tool support.
An aspect is a well-modularized crosscutting concern.
See copyright notice
elsewhere in this deck.
6. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Tracing with AOP
414
aspect PointTracing {
pointcut trace():
within(com.bigboxco.boxes.*) &&
execution(* *(..));
before(): trace() {
TraceSupport.traceEntry(tjp);
}
after(): trace() {
TraceSupport.traceExit(tjp);
}
}
class Point {
void set(int x, int y) {
this.x = x; this.y = y;
}
}
The classes (objects) do not to
contain code that anticipates the
interaction with the trace facility.
An aspect in the
AspectJ language
â which is a Java
extension
See copyright notice
elsewhere in this deck.
7. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Aspects â benefits in design and coding
⢠Objects no longer responsible for using the trace facility.
⢠Trace aspect encapsulates that tracing responsibility.
⢠Changing the tracing concern affects one module.
⢠Removing tracing from the design is trivial.
See copyright notice
elsewhere in this deck.
8. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
AspectJ â an implementation of AOP
⢠Well-integrated extension to Java
⢠A general-purpose AOP language
⢠Compiles to JVM-compatible .class files
⢠Semantics relies on load-time weaving
⢠IDE support for Eclipse et al.: AJDT
⢠Freely available implementation
⢠Invented in the 90-ties at XEROX Parc
⢠Now maintained and used by IBM
⢠Other major AOP implementations for Java:
â JBoss
â AspectWerkz
See copyright notice
elsewhere in this deck.
9. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Logistics
Recommended working environment for AspectJ
Recent Eclipse
AJDT (includes AspectJ compiler)
Use Eclipse UPDATE to install AJDT.
Eclipse/AspectJ tips:
Make sure weaving is enabled.
Make use of IDE hints to study weaving.
11. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Scenario
⢠Report when âmainâ method is called.
⢠Report when execution is completed.
âHello Worldâ of AspectJ
DEMO
See package helloworld
12. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Scenario
⢠Refuse negative withdrawal.
⢠Refuse negative deposits.
⢠Refuse negative balance.
A safer account class
420
DEMO
See package accounts
14. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
operations that move elements
factory methods
Display
*
2Point
getX()
getY()
setX(int)
setY(int)
moveBy(int, int)
Line
getP1()
getP2()
setP1(Point)
setP2(Point)
moveBy(int, int)
Figure
makePoint(..)
makeLine(..)
FigureElement
moveBy(int, int)
A simple ďŹgure editor
See copyright notice
elsewhere in this deck.
15. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A simple ďŹgure editor
class Line implements FigureElement{
private Point p1, p2;
Point getP1() { return p1; }
Point getP2() { return p2; }
void setP1(Point p1) { this.p1 = p1; }
void setP2(Point p2) { this.p2 = p2; }
void moveBy(int dx, int dy) { ... }
}
class Point implements FigureElement {
private int x = 0, y = 0;
int getX() { return x; }
int getY() { return y; }
void setX(int x) { this.x = x; }
void setY(int y) { this.y = y; }
void moveBy(int dx, int dy) { ... }
}
See copyright notice
elsewhere in this deck.
16. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A crosscutting concern: ďŹgure updating
⢠Figures are collections of figure elements.
⢠The latter move frequently.
⢠Displays show figures.
⢠Displays need to be updated when moves happen.
See copyright notice
elsewhere in this deck.
17. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Join points along the execution of method call
(Move a line, and in turns its points)
a Line
a Point
returning or throwing
dispatch
dispatch
a method call
returning or throwing
a method execution
returning or throwing
a method execution
myObject.moveBy(2, 2)
myObject.p1.moveBy(2, 2)
See copyright notice
elsewhere in this deck.
18. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Join-point terminology
⢠Several kinds of join points
â method & constructor call
â method & constructor execution
â field get & set
â exception handler execution
â static & dynamic initialization
a Line
dispatch
method call
join points
method
execution join
points
See copyright notice
elsewhere in this deck.
19. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The language construct
âpointcutâ
⢠Pointcuts provide a means to identify join points.
⢠A pointcut is a kind of predicate on join points that:
â can match or not match any given join point, and
â optionally, pulls out some of the values at that join point.
⢠Example:
call(void Line.setP1(Point))
⢠Meaning:
Matches if the join point is a method call with this signature.
See copyright notice
elsewhere in this deck.
20. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pointcuts compose like predicates, using &&, || and !.
Example:
Meaning:
Composition of pointcuts
Matches whenever a Line receives a
âvoid setP1(Point)â or âvoid setP2(Point)â method call.
a âvoid Line.setP2(Point)â call
or
a âvoid Line.setP1(Point)â call
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
See copyright notice
elsewhere in this deck.
21. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Anonymous and named pointcuts
⢠Pointcuts can be named â for reuse.
⢠Example:
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
See copyright notice
elsewhere in this deck.
22. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
After advice:
actions to be taken after computation at join point
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
after() returning: move() {
<code here runs after each move>
}
See copyright notice
elsewhere in this deck.
23. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A simple aspect for
display updating
aspect DisplayUpdating {
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
after() returning: move() {
Display.update();
}
}
See copyright notice
elsewhere in this deck.
24. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Tangled code without an aspect
⢠Update calls are tangled through the code.
⢠Discipline of updating must be checked by full inspection.
⢠BTW, âweavingâ effectively results in this code.
class Line {
private Point p1, p2;
Point getP1() { return p1; }
Point getP2() { return p2; }
void setP1(Point p1) {
this.p1 = p1;
Display.update();
}
void setP2(Point p2) {
this.p2 = p2;
Display.update();
}
}
See copyright notice
elsewhere in this deck.
25. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pointcuts â some elaborations
⢠Crosscutting multiple classes
⢠Crosscutting based on interface signatures
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int));
pointcut move():
call(void FigureElement.moveBy(int, int)) ||
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int));
See copyright notice
elsewhere in this deck.
26. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pick up values at join point
Example: the target of a join point
Variable fe is bound to type by pointcut declaration.
Variable fe is bound to value at join point.
Advice can access value.
pointcut move(FigureElement fe):
target(fe) &&
(call(void FigureElement.moveBy(int, int)) ||
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int)));
after(FigureElement fe) returning: move(fe) {
<fe is bound to the figure element>
}
parameter
mechanism
See copyright notice
elsewhere in this deck.
27. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pick up values at join point
Example: the arguments of an intercepted method
Variables x and y are bound to type by pointcut declaration.
Variables x and y are bound to values at join point.
Advice can access arguments.
pointcut move(int x, int y):
args(x, y) &&
call(void FigureElement.moveBy(int, int)
See copyright notice
elsewhere in this deck.
28. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Recall: the earlier aspect
for display updating
aspect DisplayUpdating {
pointcut move():
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point));
after() returning: move() {
Display.update();
}
}
See copyright notice
elsewhere in this deck.
29. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A revision of the aspect
for display updating
aspect DisplayUpdating {
pointcut move(FigureElement fe):
target(fe) &&
(call(void FigureElement.moveBy(int, int)) ||
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int)));
after(FigureElement fe) returning: move(fe) {
Display.update(fe);
}
}
See copyright notice
elsewhere in this deck.
30. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Intermediate summary
⢠A design concern is crosscutting (CC) if:
â involves several objects or operations, and
â implemented w/o AOP leads to distant code locations
⢠doing the same thing
⢠doing a coordinated single thing
⢠Expected benefits of aspectual modularization of CC:
â Good modularity, even in the presence of crosscutting concerns
⢠less tangled code, more natural code, smaller code
⢠easier to maintain and to evolve
⢠easier to reason about, debug, change
⢠more reusable
⢠more possibilities for generalization, plug and play
See copyright notice
elsewhere in this deck.
31. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pointcuts contâd
call(void Point.setX(int))
method/constructor call join points (actual method call)
execution(void Point.setX(int))
method/constructor execution join points (actual running method)
initialization(Point)
object initialization join points
staticinitialization(Point)
class initialization join points (as the class is loaded)
See copyright notice
elsewhere in this deck.
32. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pointcuts contâd
⢠Field reference (âright valueâ)
Example:
get( int Point.x )
Meaning: match if field x of type int of an object of class
Point is referenced in right-value manner.
⢠Assignment (âleft valueâ)
Example:
set( int Point.x )
Meaning: match if field x of type int of an object of class
Point is referenced in left-value manner.
See copyright notice
elsewhere in this deck.
33. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pointcuts contâd
this( TypeName )
within( TypeName )
withincode( MemberSignature )
any join point at which
currently executing object is an instance of type name
currently executing code is contained within type name
currently executing code is specified methods or constructors
See copyright notice
elsewhere in this deck.
34. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
AspectJ -- How does it work?
Two kinds of classes:
a) Classes compiled by AspectJ
b)Classes not compiled by AspectJ
Two weaving approaches:
a) Generated bytecode contains aspects.
b)Preexisting bytecode is transformed.
36. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Controlling actions at join point
⢠before before proceeding at join point
⢠after returning a value at join point
⢠after throwing a throwable at join point
⢠after returning at join point either way
⢠around on arrival at join point gets explicit
control over when&if computation proceeds
See copyright notice
elsewhere in this deck.
37. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
An example to illustrate before/after/around
âContract checkingâ
⢠Pre-conditions
âcheck whether parameter is valid
⢠Post-conditions
âcheck whether values were set
⢠Condition enforcement
âforce parameters to be valid
See copyright notice
elsewhere in this deck.
38. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Before advice: assert preconditions
aspect BoundPointPreCondition {
before(int newX):
call(void Point.setX(int)) && args(newX) {
assert newX >= MIN_X;
assert newX <= MAX_X;
}
before(int newY):
call(void Point.setY(int)) && args(newY) {
assert newY >= MIN_Y;
assert newY <= MAX_Y;
}
}
See copyright notice
elsewhere in this deck.
39. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Pick up values at join point
Example: the arguments of an matched call
before(int newX):
call(void Point.setX(int)) && args(newX) {
assert newX >= MIN_X;
assert newX <= MAX_X;
}
Pointcut parameter,
as used previously,
see âtargetâ.
Bind parameter to
arguments of
matched call
See copyright notice
elsewhere in this deck.
40. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
After advice: assert postconditions
aspect BoundPointPostCondition {
after(Point p, int newX) returning:
call(void Point.setX(int)) &&
target(p) && args(newX) {
assert p.getX() == newX;
}
after(Point p, int newY) returning:
call(void Point.setY(int)) &&
target(p) && args(newY) {
assert p.getY() == newY;
}
}
See copyright notice
elsewhere in this deck.
41. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Around advice: make calls valid
aspect BoundPointEnforcement {
void around(int newX):
call(void Point.setX(int)) && args(newX) {
proceed( clip(newX, MIN_X, MAX_X) );
}
void around(int newY):
call(void Point.setY(int)) && args(newY) {
proceed( clip(newY, MIN_Y, MAX_Y) );
}
private int clip(int val, int min, int max) {
return Math.max(min, Math.min(max, val));
}
}
See copyright notice
elsewhere in this deck.
42. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Context of around advice
For each around advice with the signature
ReturnType around(T1 arg1, T2 arg2, âŚ)
there is a special method with the signature
ReturnType proceed(T1, T2, âŚ)
available only in around advice.
Meaning: ârun what would have ran if this advice had not been definedâ
See copyright notice
elsewhere in this deck.
44. Control-ďŹow-related pointcuts
cflow( Pointcut )
all join points in the dynamic control flow of any join
point picked out by Pointcut
cflowbelow( Pointcut )
all join points in the dynamic control flow below any
join point picked out by Pointcut
See copyright notice
elsewhere in this deck.
45. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A revision of the aspect for
display updating
aspect DisplayUpdating {
pointcut move(FigureElement fe):
target(fe) &&
(call(void FigureElement.moveBy(int, int)) ||
call(void Line.setP1(Point)) ||
call(void Line.setP2(Point)) ||
call(void Point.setX(int)) ||
call(void Point.setY(int)));
pointcut topLevelMove(FigureElement fe):
move(fe) && !cflowbelow(move(FigureElement));
after(FigureElement fe) returning: topLevelMove(fe) {
Display.update(fe);
}
}
See copyright notice
elsewhere in this deck.
47. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Another example:
Enforce factory methods makePoint and ...Line
class Figure {
public Line makeLine(Line p1, Line p2) { new Line... }
public Point makePoint(int x, int y) { new Point... }
...
}
aspect FactoryEnforcement {
pointcut illegalNewFigureElement():
(call(Point.new(..)) || call(Line.new(..)))
&& !withincode(* Figure.make*(..));
before(): illegalNewFigureElement() {
throw new Error("Use factory method instead.");
}
}
See copyright notice
elsewhere in this deck.
new is
rejected
We use
wildcards.
48. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
âCompile-time adviceâ
⢠Normally pointcuts define points in the actual execution of
the program to be affected by advice.
⢠We can also define a pointcut just to produce a compile-
time action (typically an error) for any code location that
matches with the pointcut.
See copyright notice
elsewhere in this deck.
49. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
âcompile-time adviceâ as an improvement
Compile error if factory methods are bypassed
class Figure {
public Line makeLine(Line p1, Line p2) { new Line... }
public Point makePoint(int x, int y) { new Point... }
...
}
aspect FactoryEnforcement {
pointcut illegalNewFigureElement():
(call(Point.new(..)) || call(Line.new(..)))
&& !withincode(* Figure.make*(..));
declare error: illegalNewFigureElement():
"Use factory method instead.";
}
}
Special kind
of advice
See copyright notice
elsewhere in this deck.
50. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
âcompile-time adviceâ as an improvement
Compile error if factory methods are bypassed
class Figure {
public Line makeLine(Line p1, Line p2) { new Line... }
public Point makePoint(int x, int y) { new Point... }
...
}
aspect FactoryEnforcement {
pointcut illegalNewFigureElement():
call(FigureElement+.new(..))
&& !withincode(* Figure.make*(..));
declare error: illegalNewFigureElement():
"Use factory method instead.";
}
}
Use
subtyping
wildcard
See copyright notice
elsewhere in this deck.
51. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Display updating with
compile-time factory check
DEMO
See package ďŹgures
53. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Inter-type declarations
⢠An orthogonal concept compared to advice.
⢠Purpose: add members to existing types:
â (static and instance) fields
â (static and instance) methods, virtual ones included
â âŚ
⢠Syntax: prefix member name by target class:
For instance:
public int Point.numbersOfPoints;
⢠New members are visible in aspect only.
See copyright notice
elsewhere in this deck.
54. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Scenario
⢠An object model for an expression language.
⢠The classes do not support any operations.
⢠Add operations for evaluation and pretty-printing.
Solving the expression problem
with inter-type declarations
DEMO
See package expressions
55. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
http://101companies.org/wiki/
Contribution:aspectJ
DEMO
56. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Summary
⢠More seriously:
⢠AOP helps avoiding code tangling.
⢠AOP helps with code modularization.
⢠AOP supports modularization of crosscutting concerns.
⢠Less seriously:
⢠AOP is an intriguing way to break encapsulation.
⢠AOP is all about tracing and logging.
⢠AOP has been obsoleted in Cobol.
57. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Byte-code transformation based
on API for byte-code engineering
(A technique for AOP language implementation)
⢠Approach:
âLoad .class file
âUse API to analyze and transform byte code.
âThen, either:
⢠Load result into JVM, or
⢠Save result into same or different .class file.
⢠BTW:
⢠This is a form of meta-programming!
⢠This is borderline reflection.
(We are using Java to transform byte code.)
Not covered in the
lecture. This is for
those interested.
58. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Scenario
⢠Add timing code to a method in an existing .class file.
⢠Update .class file itself; transformation is effective upon load.
This is demo-only subject. We donât go any deeper into it.
DEMO
Byte-code engineering
See package bcel
Not covered in the
lecture. This is for
those interested.
59. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Language extension â summary
⢠Pointcuts
â Pick out join points (âpoints in the execution of the programâ) and
values at those points (arguments, results, exceptions)
⢠Advice
â Additional action to take at join points in a pointcut
⢠Before
⢠After (returning or throwing)
⢠Around
⢠Inter-type declarations (aka âopen classesâ)
⢠Aspect
â A modular unit of crosscutting behavior
â A generalization of the class form of modular unit
â Comprised of declarations for:
⢠Advice
⢠Inter-types
⢠Pointcuts
⢠Fields, constructors, and methods
See copyright notice
elsewhere in this deck.
60. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Wildcards in pointcuts
⢠target(Point)
⢠target(graphics.geom.Point)
⢠target(graphics.geom.*) any type in graphics.geom
⢠target(graphics..*) any type in any sub-package of graphics
⢠call(void Point.setX(int))
⢠call(public * Point.*(..)) any public method on Point
⢠call(public * *(..)) any public method on any type
⢠call(void Point.setX(int))
⢠call(void Point.setY(*))
⢠call(void Point.set*(*))
⢠call(void set*(*)) any setter
⢠call(Point.new(int, int))
⢠call(new(..)) any constructor
â*âis
wild
card
â..âis
m
ulti-partwild
card
See copyright notice
elsewhere in this deck.
61. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Other AspectJ concepts
⢠Precedence among multiple aspects
⢠Pointcuts:
âInitialization
âExceptions
⢠Reflection for join point
⢠Abstract pointcuts
⢠Aspect inheritance
⢠Subtyping constraints
⢠...
See copyright notice
elsewhere in this deck.
62. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Further reading
⢠AspectJ/AOP tutorials
[1] Intro at eclipse.org
[2] The seminal âAspectJ overviewâ
[3] âI want my AOPâ (provides sources, too)
[4] âThe Paradoxical Success of AOPâ
⢠AspectJ sample code:
â Install AspectJ and go to doc/examples directory
Examples are included in the suite for the present lecture.
â Some additional pointers:
⢠http://www.aspectprogrammer.org/eclipseaspectj/
⢠http://mail.eclipse.org/aspectj/sample-code.html
⢠http://www.cs.wustl.edu/~mdeters/seminar/fall2002/notes/code/
⢠http://stderr.org/doc/aspectj-doc/examples/
63. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Copyright notice
This slide deck adopts a considerable amount of
slides from the following deck: Š 2004 âAspect-
Oriented Programming with AspectJâ˘â by Julie
Waterhouse, Mik Kersten, eclipse.org/aspectj,
IBM, UBC; http://kerstens.org/mik/publications/
aspectj-tutorial-oopsla2004.ppt. That deck has served
as an OOPSLA 2004 tutorial. Most of the slides
showed up in many other decks by the key
representatives of AspectJ. If you derive any work
from the present slide deck, you must keep the
copyright notice in tact. All remaining copyright, if
any, is with Ralf Lämmel.