AspectJ Demo Script - JavaOne 2002
1. Intro (Eclipse)
- Show what it's like to use for
- Finding and capturing crosscutting modularity in your system
- Navigate crosscutting structure
- Using build configurations to facilitate the development process
- Tools
- Run the FigureEditor and describe sample system.
2. Refactor crosscutting concern into an aspect (Eclipse)
- Write declare or aspect to find calls to Canvas.updateHistory()
declare warning: !within(Enforcement) && call(void Canvas.updateHistory(..)):
"";
- Navigate all places where it's called
- Write "after returning" advice to capture this functionality
after() returning: call(void FigureElement+.set*(..))
{
Canvas.updateHistory();
}
- Navigate resulting crosscutting structure
- Explain that I had missed putting the update on SlothfulPoint
3. Show declare error (Eclipse)
- Want to make sure that sets of private fields of classes implementing
FigureElement only happen from within the set methods
declare warning:
set(private * FigureElement+.*) &&
!(withincode(* FigureElement+.set*(..)) ||
withincode(FigureElement+.new(..))):
"should only assign to fields from set methods";
- Compile and navigate places where it is violated
- Fix violations
4. Show precondition checking (Eclipse)
- Write before advice that does precondition checking on Points.
before(int newValue): set(int Point.*) &&
args(newValue) {
if (newValue < 0) {
throw new
IllegalArgumentException("too small");
}
}
- Write violation in figures.Main.main(..):
Point p = new Point(-10, 0);
- Run, when error thrown navigate to place of violation and fix violation.
5. Show build configurations (JBuilder)
- Launched with Ship.java and "Release.lst" selected and compiled.
- Run
- Select "Debug.lst", compile, and run again
- Show debug window, menu, and method tracing
7. Show crosscutting navigation in other tools
- Emacs: navigate from Ship.fire to EnsureShipIsAlive using inline
annotation
- AJDoc: navigate back again
- AJBrowser Screenshot
- NetBeans 3.3.1 Screenshot: navigate from Enforcement to Point