public class A public B m 1 public
コーディングパターン抽出処理 public class A { public B m 1() { } public B m 2() { } } 入力 ソースコード (*. java) ソースコードの正規化 メソッドに分割 public B m 1() { … public B m 1() { } … } メソッド集合 メソッド内の正規化 A. m 1 IF A. m 1 B. m 2 LOOP A. m 2 IF END-LOOP B. m 2 LOOP A. m 2 END-LOOP B. m 2 END-IF LOOP A. m 2 END-LOOP END-IF END-IF 要素データベース 出力 シーケンシャル パターンマイニング SES 2009 コーディングパターン検出ツール コーディングパターン 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 4
メソッド内の正規化(1/2) • メソッド中から特徴列を抽出する処理 – 1つのメソッドから1つの特徴列を抽出 • 特徴とは? – メソッド呼び出し – 制御構造 • 条件分岐 • 繰り返し処理 SES 2009 int sample. Method(int x, int y) { int result = x * y; while ( result < 100 ) { method. Call(); result = result * 2; } if ( is. Debug. Mode() ) { print. Verbose(result); } else { print. Simple(result); } return result; } 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 5
パターンマイニング • シーケンシャルパターンマイニング • マイニング例 – 条件 • パターン長: 4以上,サポート値: 2以上 is. Debug. Mode() IF print. Verbose() ELSE print. Simple() END-IF 特徴列A method. Call 1() IF print. Verbose() END-IF method. Call 2() is. Debug. Mode() IF print. Verbose() END-IF method. Call 1() 特徴列B 特徴列C SES 2009 is. Debug. Mode() method. Call 3() print. Verbose() LOOP print() END-LOOP 特徴列D 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 8
パターンマイニング(結果) is. Debug. Mode() IF print. Verbose() END-IF パターン長: 4 サポート値: 2 instanceof is. Debug. Mode() IF print. Verbose() ELSE print. Simple() END-IF 特徴列A method. Call 1() IF print. Verbose() END-IF method. Call 2() is. Debug. Mode() IF print. Verbose() END-IF method. Call 1() 特徴列B 特徴列C SES 2009 is. Debug. Mode() method. Call 3() print. Verbose() LOOP print() END-LOOP 特徴列D 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 9
コーディングパターン例 … Iterator it = list. iterator(); while( it. has. Next() ) { Item item = (Item)it. next(); if (item. is. Active()) { item. deactivate(); } } … ~ イディオム ~ イテレータ … for( Iterator it = list. iterator(); it. has. Next(); ) { Item item = (Item)it. next(); if (item. is. Enabled()) { item. set. Inabled(false); } } … ソースコード上のインスタンス SES 2009 iterator() has. Next() LOOP next() has. Next() END-LOOP コーディングパターン 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 11
コーディングパターン例 ~ アプリケーション固有の機能実装 ~ public void reverse. Action(Figure figure) { set. Undo. Activity(create. Undo. Activity()); List l = Collections. Factory. current(). create. List(); l. add(figure); l. add(((Decorator. Figure)figure). peel. Decoration()); get. Undo. Activity(). set. Affected. Figures( new Figure. Enumerator(l)); … } public void execute() { super. execute(); set. Undo. Activity(create. Undo. Activity()); get. Undo. Activity(). set. Affected. Figures(view(). selection()); Figure. Enumeration fe = get. Undo. Activity(). get. Affected. Figures(); … } ソースコード上のインスタンス SES 2009 Undo機能の実装 JHot. Draw(Ver. 5. 4 b 1) create. Undo. Activity() set. Undo. Activity() get. Undo. Activity() set. Affected. Figures() コーディングパターン 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 12
コーディングパターンのメトリクス ~パターンの密度~ LOOP a() b() END-LOOP LENpat • パターンインスタンスの密度( DENinst)の平均 コーディングパターン v() LOOP a() b() w() x() END-LOOP y() z() DENinst = LENpat / LENinst DENinst = 4 / 6 LENinst – LENpat • コーディングパターンの要素数 – LENinst • インスタンス開始要素から, インスタンス終了要素までの要素数 インスタンス SES 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 16
コーディングパターンのメトリクス ~パターンの分散~ • パターンインスタンスのパッケージ間の分散 度合 RAD = 0 RAD = 1 RAD = 2 pkg 0 2 1 pkg ファイルA ファイルC ファイルA ファイルB パターンインスタンス SES 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 17
メトリクスの関連性分析 1. オープンソースソフトウェアからコーディングパターンを 抽出 – パターンマイニングの設定 • 10 ≦ インスタンス数 • 4 ≦ パターン長 2. コーディングパターンのメトリクスを計測 3. メトリクスの関連性の分析 Name 調査対象のソフトウェア Version LOC JHot. Draw 7. 0. 9 j. Edit #Pattern 90166 375 4. 3 pre 10 168335 2902 Apache Tomcat 6. 0. 14 313479 8782 Sable. CC 3. 2 35388 450 SES 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 19
非繰り返し要素の割合と制御構造要素の割合 ~Apache Tomcatの場合~ • パターン長: 24(最長) • サポート値(インスタンス数): 12 • 「is. Debug. Enabled(), IF, debug(), END-IF」 の繰り返し SES 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 21
パターンの分類とメトリクスの関係 • ライブラリの利用法に関連するパターン – ソフトウェア全体に登場 – Sable. CCでは 29. 3%がイテレータに関連 (例)イテレータの利用 SES 2009 (JHot. Draw) 2009/09/09 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 22
- Slides: 22