1 / 21

AspectScope による アスペクト指向プログラ ミングの支援

AspectScope による アスペクト指向プログラ ミングの支援. 数理・計算科学専攻 千葉研究室 堀江 倫大 指導教員 : 千葉 滋. モジュラープログラミング. 全体をモジュールに分割 モジュール(=クラス)の (インタフェースの)仕様を確定 仕様だけを見てプログラミング クラスの仕様: シグネチャ + メソッドの振る舞い 仕様は変えない 情報隠蔽 内部実装は仕様を満たしていれば自由に変えてよい. AOP は モジュラープログラミングができない. よくある批判 アスペクトが仕様と実装の一貫性を壊す可能性がある

Download Presentation

AspectScope による アスペクト指向プログラ ミングの支援

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AspectScope によるアスペクト指向プログラミングの支援 数理・計算科学専攻 千葉研究室 堀江 倫大 指導教員: 千葉 滋

  2. モジュラープログラミング • 全体をモジュールに分割 • モジュール(=クラス)の (インタフェースの)仕様を確定 • 仕様だけを見てプログラミング • クラスの仕様: シグネチャ + メソッドの振る舞い • 仕様は変えない • 情報隠蔽 • 内部実装は仕様を満たしていれば自由に変えてよい

  3. AOP はモジュラープログラミングができない • よくある批判 • アスペクトが仕様と実装の一貫性を壊す可能性がある • 他のモジュールの実装を、仕様を無視して変更できてしまう • AOP の obliviousness の負の側面 • 元のクラスの実装は改変されない • 仕様だけを見てプログラミングできない • あちこちの実装を見る必要がある • モジュール内部の実装 • そのモジュールに影響をおよぼしていそうなアスペクトの実装

  4. 50 100 例:リファクタリング • 契約のためのアスペクトを定義 • 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(); }}

  5. 多重線の x 座標は 0 以上 100 以下 の範囲内に制限される + + 直線の両端の x 座標は 0 以上 100 以下、 y 座標は 0 以上 50 以下に制限される Shape のサブクラスから呼び出されたとき のみ、 0 < x < 100 に制限される アスペクトにより仕様と実装が食い違う • コールグラフ中のメソッド全体に食い違いの影響が及ぶ • ポイントカットが指定したメソッドだけではない x 軸方向に dx, y 軸方向に dyだけ 直線を移動させる 点の x 座標を設定する x 軸方向に dx、y 軸方向にdy だけ多重線を移動する 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+)

  6. 開発ツール: AspectScope • AOPでのモジュラープログラミングを支援する • アスペクトの中に、実装の変更だけでなく、それに合わせた仕様の更新も記述させる • 変更部分を説明した追加 javadoc コメント • メソッドごとに、それぞれの抽象化に合わせ異なるコメントを記述可能 • ツールが更新後の仕様を表示 • 元の javadoc コメント • アスペクトが追加した javadoc コメント • 変更点を知らせるテキストエディタのマーカー、アウトラインビュー

  7. Eclipse プラグインとして開発 • エディタ、ビューを拡張

  8. アスペクトが追加した javadoc 更新後の仕様の表示 • AspectScope のテキストエディタ • マーカー: 仕様が変わっている箇所を示す • javadoc コメント: 更新後のメソッドの振る舞い

  9. outline ビュー • クラスの中で定義されたメソッドとフィールドの列挙 • アスペクトによって変更されていたらアイコン()を表示する • ソースコードを見る必要はない UndoCmdAspect によって拡張

  10. メソッドの抽象化に沿ったコメントの追加 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 if the caller is the subclasses of Shape 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)

  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 段前の呼び出し階層 • 同様の処理を行うメソッド Line moveBy csg.figures Point Line Arrow Rectangle … Rectangle moveBy Point setX Triangle moveBy Contract

  13. comment アドバイス • AspectScope 独自のアドバイス • メソッドに元々コメントがない場合、comment アドバイスを利用してコメントを織り込む • execution ポイントカットのみ指定可能 • 不要になったら unweave 可能 • (例) Line.getDistance メソッドへのコメントの織り込み class Line { int getDistance(Point p) { : } : } /** Returns the distance from this line */ comment() : execution(int Line.getDistance(Point)) {}

  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>.”

  16. ロギングアスペクト • 呼び出し側に仕様変更を反映させる必要は必ずしもない • ロギングはプログラムのセマンティクスを変更しない 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 アドバイスを利用することを検討

More Related