AspectScope による アスペクト指向プログラ ミングの支援
-
Upload
tallulah-alston -
Category
Documents
-
view
51 -
download
6
description
Transcript of AspectScope による アスペクト指向プログラ ミングの支援
1
AspectScope によるアスペクト指向プログラミングの支援
数理・計算科学専攻 千葉研究室
堀江 倫大指導教員 : 千葉 滋
2
モジュラープログラミング 全体をモジュールに分割 モジュール(=クラス)の
(インタフェースの)仕様を確定 仕様だけを見てプログラミング
クラスの仕様: シグネチャ + メソッドの振る舞い
仕様は変えない情報隠蔽
内部実装は仕様を満たしていれば自由に変えてよい
3
AOP はモジュラープログラミングができない よくある批判
アスペクトが仕様と実装の一貫性を壊す可能性がある
他のモジュールの実装を、仕様を無視して変更できてしまう
AOP の obliviousness の負の側面 元のクラスの実装は改変されない
仕様だけを見てプログラミングできない あちこちの実装を見る必要がある
モジュール内部の実装 そのモジュールに影響をおよぼしていそうなアスペクトの実装
4
例:リファクタリング 契約のためのアスペクトを定義
Point クラスの setX 、 setY メソッドの振る舞いを変更
事前条件により、図形エディタのウィンドウサイズ ( 0 < x < 100 、 0 < y < 50 ) 内に図形は描画されなければならない
aspect Contract { before(int x) : call(void Point.setX(int)) && args(x) && within(Shape+) { if (x < 0 || 100 < x) throw new IllegalArgumentException(); } before(int y) : call(void Point.setY(int)) && args(y) && within(Shape+) { if (y < 0 || 50 < y) throw new IllegalArgumentException();}}
50
100
×
5
アスペクトにより仕様と実装が食い違う
コールグラフ中のメソッド全体に食い違いの影響が及ぶ ポイントカットが指定したメソッドだけではない
class MultiLines extends Shape{ private List lines; : void moveBy(int dx, int dy) { for (Iterator it = lines.iterator(); it.hasNext();) ((Line) it).moveBy(dx, dy); }}
class Line extends Shape { private Point p1, p2; : void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); : }}
class Point extends .. { private int x, y; : void setX(int nx) { x = nx; }}
call(void Point.setX(int)) && within(Shape+)
x 軸方向に dx, y 軸方向に dyだけ直線を移動させる
直線の両端の x 座標は 0 以上 100 以下、y 座標は 0 以上 50 以下に制限される
+点の x 座標を設定する
Shape のサブクラスから呼び出されたときのみ、 0 < x < 100 に制限される
+
x 軸方向に dx 、 y 軸方向に dy だけ多重線を移動する
多重線の x 座標は 0 以上 100 以下の範囲内に制限される
+
6
開発ツール : AspectScope
AOP でのモジュラープログラミングを支援する アスペクトの中に、実装の変更だけでなく、それに合わせ
た仕様の更新も記述させる 変更部分を説明した追加 javadoc コメント メソッドごとに、それぞれの抽象化に合わせ異なるコメントを記
述可能 ツールが更新後の仕様を表示
元の javadoc コメント アスペクトが追加した javadoc コメント 変更点を知らせるテキストエディタのマーカー、アウトラ
インビュー
7
Eclipse プラグインとして開発 エディタ、ビューを拡張
8
更新後の仕様の表示 AspectScope のテキストエディタ
マーカー : 仕様が変わっている箇所を示す javadoc コメント : 更新後のメソッドの振る舞い
アスペクトが追加した javadoc
9
outline ビュー クラスの中で定義されたメソッドとフィールドの
列挙 アスペクトによって変更されていたらアイコン ( )
を表示する ソースコードを見る必要はない
UndoCmdAspect によって拡張
10
メソッドの抽象化に沿ったコメントの追加
class MultiLines { private List lines; : void moveBy(int dx, int dy) { for (Iterator it = lines.iterator(); it.hasNext();) ((Line) it).moveBy(dx, dy); }}
class Line { private Point p1, p2; : void moveBy(int dx, int dy) { p1.setX(p1.getX() + dx); : }}
class Point { private int x, y; : void setX(int nx) { x = nx; }}
call(void Poin.setX(int)) && within(Line)
The horizontal position of this line should be no fewer than 0, nor more than 100
The horizontal position of both the starting point and the end point should be no fewer than 0, nor more than 100
The set value x should be no fewer than 0, nor more than 100, only ifthe caller is the subclasses of Shape
11
アスペクトによる仕様の更新の記述 comment アノテーション
変更部分を説明する追加コメントの定義 アドバイスを定義するときに一緒に記述
/** @comment * The set value x should be no fewer than 0, nor more than 100 * * @comment (execution(void Line.moveBy(int, int))) * The horizontal position of both the starting point and the end * point should be no fewer than 0, nor more than 100 * * @comment (execution(void MultiLines.moveBy(int, int))) * The horizontal position of this line should be no fewer than 0, * nor more than 100 */before(int x) : call(void Point.setX(int)) && args(x) && within(Line) { … }
12
コメントを追加するメソッドの範囲指定 メソッドによって追加するコメントを変える
条件文なし
execution( method pattern ) 特定のメソッド
within( class pattern ) 特定のクラス内、パッケージ内のメソッド (例) within(* csg.figures.*)
caller( int ) n 段前の呼び出し階層 同様の処理を行うメソッド Rectangle
moveBy
TrianglemoveBy
PointsetX
Contract
PointLineArrowRectangle …
csg.figures
LinemoveBy
13
comment アドバイス AspectScope 独自のアドバイス メソッドに元々コメントがない場合、 comment
アドバイスを利用してコメントを織り込む execution ポイントカットのみ指定可能 不要になったら unweave 可能
(例) Line.getDistance メソッドへのコメントの織り込み
/** Returns the distance from this line */comment() : execution(int Line.getDistance(Point)) {}
class Line { int getDistance(Point p) { : } :}
14
実アプリケーションでの調査 目的
アスペクトの織り込みにより、仕様と実装の一貫性が本当にくずれているか
対象メソッドごとに異なる追加コメントを必要としているか
対象アプリケーション Web アプリケーション Health Watcher (HW)
[A. Rashid ら ‘ 07] クラス数 692 (LOC: 9,591) 、アスペクト数 25 (LOC:
1,989) アスペクトの使用方法は 5通り
デザインパターン、例外処理、永続化、トランザクション、ロギング
15
AspectScope の適用結果 記述したコメントの種類と追加された箇所の数
Observer パターンにおける追加コメントの例 setPassword:
“Calls <code>updateObserver</code> after setting the new password of the employee to update the Observer.”
executeCommand:“Updates the information of the employees by calling <code>updateObserver</code>.”
パターン 拡張したメソッド数
呼ばれる側
呼び出し 1 階層上
呼び出し2 階層上
呼び出し3 階層上
呼び出し6 階層上
呼び出し9 階層上
Observer
Command
Factory
State
17
3
0
15
17
0
NA
15
17
3
NA
14
0
0
NA
13
0
0
NA
10
0
0
NA
5
0
0
NA
2
16
ロギングアスペクト 呼び出し側に仕様変更を反映させる必要は必ず
しもない ロギングはプログラムのセマンティクスを変更しな
いアスペクト名
拡張したメソッド数
呼ばれる側
呼び出し1 階層上
呼び出し 2 階層上
HWLogging 2 1 (2) (1)
public synchronized static HealthWatcherFacade getInstance() { if (singleton == null) singleton = new HealthWatcherFacade(); return singleton;}
17
関連研究 :Aspect-Aware Interface (AAI)
AspectScope が基本とする考え方を最初に提案 アイデアを提示した論文 [G. Kiczales ら ‘ 05]
AOP には OOP とは異なる新しいインターフェースAAI が存在する
変更後の仕様の表現方法が異なる call 、 get 、 set ポイントカットの表現について具体的な言及は
ない メソッドの振る舞いの表現は扱っていない AspectScope は、 javadoc コメントを使って表現
18
関連研究 : AJDT ポイントカットによって選択されたジョインポイ
ントにマークを表示するのみ広範囲に広がるアスペクトの影響は表現できない
局所的な表示 (例) call ポイントカットの場合 caller にしか表示さ
れない callee には表示なし
caller callee
19
関連研究 : Open Module
AOP の能力を制限して、モジュラープログラミングを可能にしている クラス側からは、どこが拡張されるかが分かる Open Module に公開されたポイントカットしか、ア
スペクトは拡張できない
将来の機能拡張に備えてポイントカットを予め公開しておくのは難しい AOP の利点を損なう
module FigureModule { class Line; expose call(void Point.setX(int)) || call(void Point.setY(int));}
20
まとめ AspectScope:
AspectJ におけるモジュラープログラミングを支援 アスペクトの中に、実装の変更だけでなく、それに合
わせた仕様の更新も記述させる comment アノテーションによる仕様の追加 comment アドバイス
ツールが更新後の仕様を表示 テキストエディタにおける javadoc コメントの表示 エディタのマーカー、アウトラインビューが更新点を知らせる
Eclipse プラグインとして開発 M. Horie, S. Chiba.
“AspectScope: An OutlineView for AspectJ Programs”,Journal of Object Technology
21
今後の課題 コールグラフごとのコメントのモジュール化
現在は、ひとつのアドバイスに複数のコメントを羅列している
プログラムの改変に弱い構造 インターフェースに現れる冗長なコメントの集約
(例) setX 、 setY メソッドは moveBy メソッド内でそれぞれ 2回ずつ呼び出される
同じコメントが 2回ずつ表示されてしまう comment アドバイスを利用することを検討