Download presentation
Presentation is loading. Please wait.
Published byJulian Parks Modified over 9 years ago
1
AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan
2
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
3
Observer pattern using an aspect A simple figure editor Invoke when updated
4
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 }}
5
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); }
6
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); }
7
Criticism In AOP, modular reasoning is difficult. No indication of the aspect in 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
8
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 viewJavadoc pane
9
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
10
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
11
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?
12
An experienced developer will… First, check the module interfaces of: 1. moveBy in Line 2. 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 …….. ……………
13
So, show arrow icons… In the view of the module interfaces of: the moveBy in Line the setX and the setY in Point
14
On the source code editor You can also see this module interface on the source code editor.
15
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 by DisplayUpdate setY ……..…… …..extended by DisplayUpdate
16
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 are indicated here. AJDT editor Problem
17
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)
18
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 see when refactoring moveBy!
19
Call pointcut in AspectScope (also get & set pointcut) An arrow icon is shown in the Line class. Line is the callee class aspect DisplayUpdate { : after(): call(void Line.moveBy(..)) { Display.update(); }} class Rect { : line.moveBy(dx, dy); : } caller class Line { : void moveBy(int dx, int dy){ : }} callee
20
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
21
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(); }
22
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 AspectScope. Enables an extension only effective to a particular module.
23
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 aspects Shows arrow icons where developers will look. It enables modular reasoning
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.