Software Engineering Laboratory Department of Computer Science Graduate
類似するコーディングパターンの 利用状況調査ツールの提案 〇小笠原康貴 神田哲也 井上克郎 大阪大学 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
類似するパターンの例 br = new Buffered. Reader(); while(br. ready()){ String line = br. read. Line(); System. out. println(line); } Buffered. Reader/ready/read. Line br = new Buffered. Reader(); while((line = br. read. Line()) != null){ System. out. println(line); } Buffered. Reader/read. Line この二つの実装は,どちらを使えばよいか? 6 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
提案ツールのアイデア br = new Buffered. Reader(); while(br. ready()){ String line = br. read. Line(); System. out. println(line); } br = new Buffered. Reader(); while((line = br. read. Line()) != null){ System. out. println(line); } • これらのコーディングパターンは,br. ready() の有無を調べることで分別可能 • キーワード検索を応用した検索手法を利用 9 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
提案ツールの手法 • • キーワード検索の不一致結果を利用 コードブロック中の複数のキーワードの有無を用いて, 記述されているコーディングパターンを判別 Buffered. Reader: 有 ready: 有 read. Line: 有 Buffered. Reader: 有 ready: 無 read. Line: 有 br = new Buffered. Reader(); while(br. ready()){ String line = br. read. Line(); } br = new Buffered. Reader(); while((line = br. read. Line()) != null){ } 10 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
提案ツールの概要 利用者 検索クエリを記述 調査したいコーディングパターン br = new Buffered. Reader(); while(br. ready()){ String line = br. read. Line(); } br. close(); Buffered. Reader ready read. Line close 10% Buffered. Reader read. Line close 90% 検索クエリ 入力 出力 リポジトリ ツール コードブロックのグループ 12 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
手法の手順 STEP 1: 検索クエリの記述 STEP 2: コードブロックの抽出 STEP 3: 検索クエリによるコードブロックの分別 13 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
STEP 1: 検索クエリの記述 • 既知のコーディングパターンから注目したいキーワードを 複数選んで記述 – キーワード間はセミコロンで区切る • 特殊な入力については後述 br = new Buffered. Reader(); while(br. ready()){ String line = br. read. Line(); } br. close(); 検索クエリの記述 Buffered. Reader; ready; read. Line; close; 既知のコーディングパターン 14 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
STEP 2: コードブロックの抽出 • 検索対象となるコードブロックの抽出を行う – 構文解析による抽出 15 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
STEP 3: コードブロックの分別 16 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
同名メソッドの区別 • トークンを用いてインスタンス名を置換 – 同名メソッドを区別できる $aにbrが割り当てられる $a=Buffered. Reader; $a. read. Line; $a. close; 検索クエリ File file = new File(“~"); File. Reader fr = new File. Reader(file); Buffered. Reader br = new Buffered. Reader(fr); String str = br. read. Line(); fr. close(); インスタンス名が異なるため,検索に一致しない 17 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
必須条件の指定 • 必須条件を指定する-eオプション入力 – 関心の無い検索対象を除外できる 〇 $a=Buffered. Reader; -e $a. read. Line; -e $a. close; × × br = new Buffered. Reader(fr); br. read. Line(); br. close(); br = new Buffered. Reader(fr); br. close(); 18 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
提案ツールの入力画面 19 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
ツールの出力結果 キーワード列 グループの割合 コードブロック 22 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
コードブロックの分別結果 A B C C execute. Query() next() close() 5個 9個 2個 D D execute. Query() next() 1個 • 類似するコーディングパターンを分別して提示することができた • グループC,Dは少数派であったが,確認した所get. Stringの記 述の代わりにget. Int, get. Booleanの記述があった 23 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
利用状況の確認 A B • AとBは同一の処理だが異なる実装 • Aはtomcat,Bはwebloggerから検出 ⇒ソフトウェアによって実装が統一されている 24 Department of Computer Science, Graduate School of Information Science and Technology, Osaka University
- Slides: 25