1 - Software Engineering Laboratory

Download Report

Transcript 1 - Software Engineering Laboratory

スライスに基づく凝集度を用いたメソッド 抽出支援手法の実験的評価 ○山口 佳久

1

,吉田 則裕

2

,後藤 祥

1

,井上 克郎

1 1 大阪大学 2 奈良先端科学技術大学院大学

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1

研究概要 メソッド抽出リファクタリング支援手法が有効かを調 査するための基準を提案 オープンソースソフトウェア上でメソッド抽出が行われ た範囲を特定する基準を提案 メソッド抽出が行われた範囲と,支援手法を適用し て得られるメソッド抽出候補を比較

2 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

リファクタリング 外部から見た動作を保ったまま,内部構造を整 理する作業 メソッド抽出リファクタリング

複数の機能を持つ長いメソッドの一部を,メソッドとし て抽出する作業 保守性の向上 メソッド抽出

3 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

メソッド抽出リファクタリングの難しさ メソッド抽出する範囲をどのように定めるか?

public String statement(){ Enumeration rentals = _rentals.elements(); int renterPoints = 0; While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; } double totalAmount = 0; String result = "Rental Record\n"; While (rentals.hasMoreElements()){ Rental each = (Rental)rentals.nextElement(); double thisAmount = each.getCharge(); result = result + each.getMovie().getTitle() + "\t" + String.valueOf(this) + "\n"; totalAmount = totalAmount + thisAmount; ・・・ メソッド抽出候補1 メソッド抽出候補 メソッド抽出候補 どこを 1 3( 2( ( 繰り返し処理 初期化 初期化 + ) ) 繰り返し処理 つの処理として捉えるか ??

非熟練者は判断することが困難 )

4 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

既存研究におけるメソッド抽出支援 メソッド抽出リファクタリングのための凝集度メトリクスを 提案 [1]

凝集度 ソースコードの機能的なまとまり度合いを表す指標 3 つの凝集度メトリクスを使用 FTightness FCoverage 協調度 : 大 FOverlap 協調度 : 小 [1] 後藤ら,”差分を含む類似メソッドの集約支援ツール” ,情報処理学会論文誌,vol. 54,No.2, 2013.

5 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

プログラムスライスを用いた凝集度メトリクス

1 2 3 4 5 6 7 8 9 } int permutation(int a, int b) { int i; int result = 1; for (i = 0; i < b; i++) { result = result * a; a = a – 1; } return result; すべてのスライスの 積集合 SL

a

SL

b

SL

result

SL

int

| | | | | | | | | | | | | | | |

6 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

プログラムスライスを用いた凝集度メトリクス

1 2 3 4 5 6 7 8 9 } int permutation(int a, int b) { int i; int result = 1; for (i = 0; i < b; i++) { result = result * a; a = a – 1; } return result; SL

a

SL

b

SL

result

SL

int

| | | | | | | | | | | | | | | | 1

FTightness

1 ( 𝑉 スライスの積集合に含まれる文の数 ( メソッドの文の数 ) ) 𝑉 : スライスの数

7 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

凝集度を使用したメソッド抽出リファクタリング 凝集度の高いコード片の抽出を推薦する

public String statement(){ Enumeration rentals = _rentals.elements(); int renterPoints = 0; While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); FTightness 高 if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else FTightness 高 FOverlap 高 rentalPoints++; } double totalAmount = 0; String result = "Rental Record\n"; While (rentals.hasMoreElements()){ Rental each = (Rental)rentals.nextElement(); double thisAmount = each.getCharge(); result = result + each.getMovie().getTitle() + "\t" + String.valueOf(this) + "\n"; totalAmount = totalAmount + thisAmount; ・・・

8 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

問題提起 メソッド抽出リファクタリングにおける,凝集度メトリク スの定量的な評価尺度が提案されていない

どのメトリクスを用いるべきか判断が困難

メトリクスの閾値を決定するのが困難

9 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

研究目的 評価方法を定める 提案する評価方法と評価基準を,リファクタリング事 例に適用

オープンソースソフトウェアからリファクタリング事例を収集 収集した事例を 有用なメソッド抽出リファクタリング として 適合率と再現率を計測

10 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

アプローチ 凝集度メトリクスに対する適合率及び再現率の定 義

適合率 : 推薦されたコード片における,有用なメソッド抽 出候補の割合 再現率:有用なメソッド抽出リファクタリングにおける,推 薦された有用なメソッド抽出候補の割合 推薦されたコード片の集合 有用なメソッド抽出リファクタリングの集合 推薦された有用なメソッド抽出候補の集合

11 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

アプローチ 凝集度メトリクスに対する適合率及び再現率の定 義

適合率 : 推薦されたコード片における,有用なメソッド抽 出候補の割合 再現率:有用なメソッド抽出リファクタリングにおける,推 薦された有用なメソッド抽出候補の割合 推薦されたコード片の集合 有用なメソッド抽出リファクタリングの集合 推薦された有用なメソッド抽出候補の集合

12 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

アプローチ 有用なメソッド抽出リファクタリング基準の提案

行の削除,追加が行われたメソッドと新規に追加されたメ ソッドの類似度を定義

13 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

提案する評価手法の手順 手順 1 :コード片間の一致率の計測 手順 2 :適合率と再現率の計測

14 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

手順 1 :コード片間の一致率の計測 メソッド抽出範囲間の重複度合い

CF1 と CF2 の和集合 行数 :9 推薦されたコード片 (CF1) CF1 と CF2 の積集合 行数 :6 有用なメソッド抽出 リファクタリング (CF2) Iterator it2 = c.getAddressIterator(); while (it2.hasNext()) { AddressModel model = (AddressModel) it2.next(); Address adr = new AddressImpl(); adr.setCity(model.getCity()); adr.setPostalCode(model.getZipPostalCode()); adr.setPostBox(model.getPoBox()); adr.setRegion(model.getStateProvinceCounty()); adr.setStreet(model.getStreet()); adr.setLabel(model.getLabel()); exportContact.addAddress(adr); } コード片間の一致率 = 𝐶𝐹1 と 𝐶𝐹2 の積集合 𝐶𝐹1 と 𝐶𝐹2 の和集合 = 2 3

15 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

手順 2 :適合率と再現率の計測

適合率の計測 有用なメソッド抽出候補 0.7

3 一致率 0.6

1 0.8

2 0.7

3 0.3

4 0.4

5 推薦されたコード片

適合率 = 有用なメソッド抽出候補の数

2

推薦されたコード片の数

= 5

16 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

手順 2 :適合率と再現率の計測

再現率の計測 リファクタリング 1 0.7

1 0.1

1 0.8

1 リファクタリング 2 0.7

2 0.3

2 推薦されたコード片 リファクタリング 3 0.1

3 0.2

3 0.3

3 0.7

3 一致率 1 2 3 1

再現率

: 有用なメソッド抽出リファクタリング

= 推薦された有用なメソッド抽出リファクタリングの数

2

有用なメソッド抽出リファクタリングの数

= 3

17 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

実験手順 手順1:メソッド抽出が行われる前のソースコードに, 支援手法を適用 手順2:得られたメソッド抽出候補と,メソッド抽出 事例を比較

提案した評価基準を用いて比較 変化させる値 凝集度をフィルタリングする閾値 メソッド抽出事例の類似度

18 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

正解集合の収集方法

public String statement(){ Enumeration rentals = _rentals.elements(); int renterPoints = 0; While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; } double totalAmount = 0; String result = "Rental Record\n"; While (rentals.hasMoreElements()){ Rental each = (Rental)rentals.nextElement(); double thisAmount = each.getCharge(); result = result + each.getMovie().getTitle() + "\t" + String.valueOf(this) + "\n"; totalAmount = totalAmount + thisAmount; ・・・ public String statement(){ Enumeration rentals = _rentals.elements(); rentalPoints = getRentalPoints(); double totalAmount = 0; String result = "Rental Record\n"; While (rentals.hasMoreElements()){ Rental each = (Rental)rentals.nextElement(); double thisAmount = each.getCharge(); result = result + each.getMovie().getTitle() + "\t" + String.valueOf(this) + "\n"; totalAmount = totalAmount + thisAmount; ・・・ protected int getRenterPoints(){ int renterPoints = 0; Enumeration rentals = _rentals.elements(); While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; } return renterPoints;

19

}

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

正解集合の収集方法

} Enumeration rentals = _rentals.elements(); int renterPoints = 0; While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; int renterPoints = 0; Enumeration rentals = _rentals.elements(); While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; } return renterPoints;

20 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

正解集合の収集方法

} Enumeration rentals = _rentals.elements(); int renterPoints = 0; While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; int renterPoints = 0; Enumeration rentals = _rentals.elements(); While (rentals.hasMoreElements()) { Rental each = (Rental)rentals.nextElement(); if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) rentalPoints = renterPoints + 2; else rentalPoints++; } return renterPoints; Enumeration rentals rentals = = _rentals.elements() _rentals.elements(); … Int renterPoints rentarPoints = = 0 0; … 共通部分の割合を求める

21 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

実験対象

jEdit プロジェクト プロジェクト概要 種類:テキストエディタ 開発期間 :2002 年 4 月 12 日~ 2012 年 1 月 30 日 LOC:177,945 類似度 1.0

0.9

以上 1.0

未満 0.8

以上 0.9

未満 0.7

以上 0.8

未満 0.6

以上 0.7

未満 メソッド数 8 6 7 11 11

22 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

FOverlap メトリクスの適合率・再現率

FOverlap

1 0,9 0,8 0,7 0,6

Precision(

) Recall(

)

0,5 0,4 0,3 0,2 0,1 0 0 0,2 0,4 0,6 凝集度をフィルタリングする閾値 0,8 1 FOverlap メトリクスは,閾値が 0 や 0.9

の時,適合率が高くなる傾向にある .

再現率は高い値を維持している

23 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

FCoverage の適合率・再現率

FCoverage

1 0,9 0,8 0,7 0,6

Precision(

) Recall(

)

0,5 0,4 0,3 0,2 0,1 0 0 1 0,2 0,4 0,6 凝集度をフィルタリングする閾値 0,8 FCoverage メトリクスは,閾値が 0.3

のとき適合率が最も高い

24 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

FTightness メトリクスの適合率・再現率

FTightness

1 0,9 0,8 0,7 0,6

Precision(

) Recall(

)

0,5 0,4 0,3 0,2 0,1 0 0 1 0,2 0,4 0,6 凝集度をフィルタリングする閾値 0,8 FTightness は閾値を定めるとよい結果が 得られるなどの特徴を得られなかった.

25 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

類似度別 FOverlap の再現率

類似度別

FOVERLAP

RECALL

0,9 0,8 0,7 0,6 0,5 0,4 0,3 0,2 0,1 0 0 0 , 2 0 , 4 0 , 6 0 , 8 凝集度をフィルタリングする閾値 1 類似度 1.0

類似度 0.9

以上 類似度 0.8

以上 類似度 0.7

以上 類似度 0.6

以上 類似度が低いほど FOverlap メトリクスの再現率は高くなる

26 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

結果

FCoverage 凝集度をフィルタリングする閾値を特定することができれ ば,よい結果が得られる FOverlap 凝集度をフィルタリングする閾値を 0 , 0.9

にすれば,よい 結果が得られる 類似度を低くすれば,よい結果が得られる FTightness よい結果が得られなかった FCoverage , Foverlap が有用な結果が得られることがわ かった

27 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

まとめ メソッド抽出リファクタリングにおける,凝集度メトリク スの評価方法の提案 メソッド抽出リファクタリング事例の選出 提案する評価方法をリファクタリング事例に適用

FCoverage メトリクス及び FOverlap メトリクスが有用な ことを示す事例を確認できた

28 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University

今後の課題 大規模ソフトウェアにおけるリファクタリング事例への 適用 凝集度メトリクスの値と保守コストの関係性の調査 正解集合の改良

29 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University