AspectJ Figures Demo Instructions

Setup

Reset

Script

·         Show Figure editor running

·         Inspect Point.java

·         Use joinpoint probe or Eclipse search to find calls

call(void figures.Canvas.updateHistory())

·         Describe places that it’s called

·         create aspect (defines a special class that can crosscut other classes)

·         aspect HistoryUpdating

·         write pointcut (has name and parameters)

pointcut moves():

    execution(void Line.setP1(Point)) ||

    execution(void Line.setP2(Point));

·         write after advice (runs “on the way back out”)

after() returning: move() {
   <runs after each move> }

·         extend advice to Point setters (multi-class)

call(void FigureElement+.set*(..))

·         capture context & use interface

move(FigureElement fe): this(fe) &&..

·         Show structure, note that SlothfulPoint is now included

·         Run & show effect

 

·         Show Point.moveBy history violoation

·         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";

·         Write before advice that does precondition checking on Points.

before(int newValue):
    set(int Point.*) && args(newValue) {
    if (newValue < 0) {
        throw new IAE("too small");
    }
}