1 Software Engineering Laboratory Department of Computer Science
プログラムで多用される 動詞と目的語の関係を利用した メソッド名提案ツール 井上研究室 鬼塚 勇弥 1 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
背景 識別子に不適切な命名がされていると プログラムの理解に時間がかかる[1] 適切な名前をつけることが求められる 本研究ではメソッド名の命名に着目する [1] D. Lawrie, C. Morrell, H. Feild, and D. Binkley, What's in a name? a study of identiers, Proceedings of the 14 th IEEE International Conference on Program Comprehension(ICPC '06), pp. 312, 2006. Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 2
動詞-目的語関係の辞書生成手法 • 動詞-目的語関係をソースコード中のメソッド から取り出す[2] – 出力は<動詞(V), 直接目的語(DO), 間接目的語 (IO)>の三つ組 – 事前に定義された三つ組抽出パターンに従う No. return method arg class 抽出三つ組 1 void v 1 + n 2 n 3 n 4 <v 1, n 3, n 4> (v 1, v 2, …: 動詞 n 1, n 2, …: 名詞) 動詞-目的語関係辞書 ・・・ 三つ組抽出パターン Javaソースコード集合 V DO IO add product stock close database - ・・・ [2] Y. Hayase, Y. Kashima, Y. Manabe, and K. Inoue, “Building domain specific dictionaries of verb-object relation from source code”, Proceedings of the 15 th European Conference 4 on Software Maintenance and Reengineering(CSMR '11), pp. 93 -100, 2011. Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
ツールの処理の流れ Step 1: 目的語の 候補を抽出 public class hoge { String huga; public void … クラス名: hoge フィールド: String, huga 返り値の型: void … ソースコード中の 目的語候補 辞書検索で得られた情報 記述中のソースコード Step 2: 辞書検索 V DO IO DO条件 IO条件 add product stock フィールド クラス V DO IO add product stock delete product stock フィールド close database - … … … … 動詞 – 目的語関係の辞書 add. Product() delete. Product() … 生成されたメソッド名 の集合 Step 3: メソッド名生成 メソッド名候補リスト delete. Product() … add. Product() Step 4: 並び替え … 提示するメソッド名候補リスト Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 6
Step 1. 目的語の候補を抽出 • カーソルがある場所か ら参照可能な名詞を目 的語の候補として抽出 ① インポートクラス名と その親クラス名 ② 定義クラス名と その親クラス名 ③ フィールド変数の 型名と名前 ④ 返り値の型名 package test. codeassist; ① import java. util. Array. List; public class Stock ② extends Abstract. Stock { Product p; ③ void set. Product(Product arg) { p = arg; } カーソル位置 ④ public static void I } クラス名: Stock フィールド: Product 返り値の型: void … Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 7
実装 • 提案手法は統合開発環境Eclipse上に実装 – Eclipseのコード補完機能を利用 12 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
課題作成方法 public class Stock extends Abstract. Stock { Product. List products; /** This method is. . . */ public static void initialize() { // initialize list 課題とするメソッドの名前 課題の動詞を含んだ for (Product p : products) { 完成 課題以外のメソッドと とそのコメントを削除 p. delete(); そのコメントを削除 } } /** this method is is. . . */ */ public static void delete. Product(String id) { Product product = my. Product. List. find. By. Id(id); product. delete(); } } } 14 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
正解基準 • 正解基準を 2通り用意 – メソッド名全体が一致 – メソッド名のうち動詞が一致 • 処理内容を表す動詞部分が重要なため 17 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
- Slides: 21