aspectscope: an outline viewer for aspectj programs michihiro horie, shigeru chiba tokyo institute...

23
AspectScope: An Outline Viewe r for AspectJ Prog rams Michihiro Horie, Shigeru Ch iba Tokyo Institute of Technolo gy, Japan

Upload: julian-parks

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

Observer pattern using an aspect A simple figure editor Invoke when updated

TRANSCRIPT

Page 1: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

AspectScope: An Outline Viewer for AspectJ Programs

Michihiro Horie, Shigeru ChibaTokyo Institute of Technology, Japan

Page 2: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Aspect-Oriented Programming allows developers to combine a module to an

aspect without explicit method calls Logging, access authentication etc.

Problem: Difficult to understand relationships between

classes and aspects Must understand a whole system to understand

one class

Page 3: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Observer pattern using an aspect A simple figure editor

Invoke when updated

Page 4: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Observer pattern in AspectJ When the setX method and the setY method in

Point and the moveBy method in Shape are called, the advice body is executed.

aspect DisplayUpdate { pointcut change() : call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Shape+.moveBy(int,int));

after() returning : change() { Display.update(); // an advice body }}

Page 5: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Refactoring: Let’s use accessors Stop directly accessing the fields in Point. Use accessors.

public void moveBy(int dx, int dy) { p1.x += dx; p1.y += dy; p2.x += dx; p2.y += dy;}

public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }

Page 6: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Five display updates

This refactoring causes display flickers.

The DisplayUpdate aspect is executed at five points. a call to the moveBy calls to the setters

public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }

Page 7: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Criticism In AOP, modular reasoning is difficult.

No indication of the aspectin the implementation of moveBy

Whole program analysis is needed. To understand the program behavior,

we must investigate all the aspects and classes.

public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy); }

No indication at the source level

Page 8: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

AspectScope enables to find all the five join points

By only looking at module interfaces An Eclipse plugin for AspectJ

two panels: the outline view and the javadoc pane

Outline view Javadoc pane

Page 9: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

The outline view of AspectScope

lists methods and fields declared in a given class It shows an arrow icon

if the method/field is advised by an aspect.

extende by the DisplayUpdate aspect

Shows the spec. of module interfaces

Page 10: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

The javadoc pane of AspectScope

It displays the javadoc comments of a selected member, such as a method or a field Shows the comments taken from an aspect

if the member is advised by the aspect.

• From the pointcut definition

• From the advice definition

• From the implementation of setX()

• An English translation of the pointcut

Shows the comments on module interfaces

setX

Page 11: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Why does AspectScope… show join point indicators

in the view of module interfaces?

Because developers will look at the module interfaces

When they are doing modular programming.

What does the developer look at when they are refactoring the figure editor?

Page 12: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

An experienced developer will…

First, check the module interfaces of: 1. moveBy in Line2. the setX and the setY in Point

because she will change moveBy to use setX and setY.

Then, edit the body of moveBy.

public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); :}

moveBy …….………………setX ……..……………setY ……..……………

Page 13: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

So, show arrow icons…

In the view of the module interfaces of: the moveBy in Line the setX and the setY in Point

Page 14: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

On the source code editor

You can also see this module interfaceon the source code editor.

Page 15: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Easy to find all the five join points

By only looking at the module interfaces of moveBy, setX and setY.

public void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); p1.setY(p1.getY() + dy); p2.setX(p2.getX() + dx); p2.setY(p2.getY() + dy);}

moveBy ………….…….extrended by DisplayUpdate

setX …………....…….extended byDisplayUpdate

setY ……..………..extended byDisplayUpdate

Page 16: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

AJDT does not show there! It shows arrow icons in the source editor

The source code at the caller site if the pointcut is call

pointcut change() : call(void Point.setX(int)) || call(void Point.setY(int)) || call(void Shape+.moveBy(int,int));

The 4 of 5 join points areindicated here.

AJDT editor

Problem

Page 17: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Where is the missing join point?

It is in the source code of another class! The caller/client method The developer must look at that as well.

If there is no aspect, they would not look at them. This is far from modular programming.

caller (client)

callee (target)

Page 18: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Call pointcut in AJDT(also get & set pointcut) An arrow icons is shown in the Rect class.

Rect is the caller class

class Rect { : line.moveBy(dx, dy); :} caller

class Line { : void moveBy(int dx, int dy){ :}} callee

aspect DisplayUpdate { : after(): call(void Line.moveBy(..)) { Display.update(); }}

Never seewhen refactoringmoveBy!

Page 19: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Call pointcut in AspectScope(also get & set pointcut) An arrow icon is shown in the Line class.

Line is the callee classaspect DisplayUpdate { : after(): call(void Line.moveBy(..)) { Display.update(); }}class Rect {

: line.moveBy(dx, dy); :} caller

class Line { : void moveBy(int dx, int dy){ :}} callee

Page 20: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

An essential difference in the abstraction AspectScope

Outline view (module interfaces). Developers will look at module interfaces when refactoring.

Effects of aspects are always shown at the callee site.

AJDT Source code editor

Developers must look at the body of the caller methods as well as callee ones.

Effects of aspects may shown at the caller site.

Or, the source editor at the callee site

Page 21: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

The revised DisplayUpdate

So the developer will be able to write the correct aspect.

The update method is invoked only when the setX, setY, and moveBy method is called as a top-level call. No need to modify on the moveBy method itself

after() returning : change() && !cflowbelow(change()) { Display.update(); }

Page 22: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Related Work Aspect-Aware Interface [Kiczales et al. 2005]

It shares basic ideas with AspectScope. Conceptual framework for modular reasoning.

These paper does not mention call, get, and set pointcuts. No javadoc comments. AspectScope is a tool based on the AAI idea.

Classbox/J [Bergel et al. 2005] Similar to the interpretation of aspects by AspectScop

e. Enables an extension only effective to a particular mo

dule.

Page 23: AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan

Conclusion AspectScope:

A programming tool for AspectJ An outline viewer of a class It shows the outline of a class woven with an aspect

Declared methods and fields javadoc comments for the methods and fields extended by a

spects Shows arrow icons where developers will look.

It enables modular reasoning