RefDiff: Detecting Refactorings in Version Histories (MSR 2017)

RefDiff: Detecting Refactorings in Version Histories (MSR 2017)

Refactoring is a well-known technique that is widely adopted by software engineers to improve the design and enable the evolution of a system. Knowing which refactoring operations were applied in a code change is a valuable information to understand software evolution, adapt software components, merge code changes, and other applications. In this paper, we present RefDiff, an automated approach that identifies refactorings performed between two code revisions in a git repository. RefDiff employs a combination of heuristics based on static analysis and code similarity to detect 13 well-known refactoring types. In an evaluation using an oracle of 448 known refactoring operations, distributed across seven Java projects, our approach achieved precision of 100% and recall of 88%. Moreover, our evaluation suggests that RefDiff has superior precision and recall than existing state-of-the-art approaches.

13beaa3b7239eca3319d54c6a9f3a85a?s=128

ASERG, DCC, UFMG

May 21, 2017
Tweet

Transcript

  1. RefDiff: Detecting Refactorings in Version Histories Danilo Silva, Marco Tulio

    Valente Universidade Federal de Minas Gerais Belo Horizonte, Brazil
  2. Introduction • Software components are in constant change • One

    important kind of change is refactoring 2
  3. Introduction • Knowledge of the refactoring operations applied is a

    valuable information – Analyze software evolution – Study refactoring practice – Review and merge code 3
  4. Problem: Finding refactoring activity is a non- trivial task 4

  5. Problem: Finding refactoring activity is a non- trivial task Documentation?

    • Refactorings are rarely documented 5
  6. Problem: Finding refactoring activity is a non- trivial task Instrumenting

    refactoring engines? • Refactorings are not always performed using automated support 6
  7. Problem: Finding refactoring activity is a non- trivial task Source

    code analysis? • Viable, but current approaches have precision and recall issues – Refactoring Miner: 63% precision – Ref-Finder: 35% precision and 24% recall 7
  8. PROPOSED SOLUTION 8

  9. RefDiff 9 • A refactoring detection approach – Employs a

    combination of heuristics based on static analysis and code similarity – 13 well-known refactoring types – TF-IDF based similarity index
  10. RefDiff: Overview 10 Version before Version after Input

  11. RefDiff: Overview 11 Version before Version after Source Code Analysis

    Types, methods, and fields }
  12. RefDiff: Overview 12 Version before Version after Relationship Analysis Rename

    Extract Move
  13. Relationships 13

  14. Relationship Example: Rename Method 14

  15. Relationship Example: Rename Method 15 names of mb and ma

    should be different
  16. Relationship Example: Rename Method 16 mb and ma are in

    “the same” class
  17. Relationship Example: Rename Method 17 the similarity index between mb

    and ma should be greater than a threshold
  18. Computing Similarity 18 • Source code represented as a multiset

    (or bag) of tokens • Similarity index based on Information Retrieval techniques (TF-IDF)
  19. Calibration of Thresholds 19 • Oracle of known refactorings in

    10 commits of a public dataset (Silva et al., 2016) • Thresholds from 0.1 to 0.9 by 0.1 increments • We choose the value that optimize the F1 score
  20. Calibration Results 20

  21. EVALUATION 21

  22. Evaluation: Precision and Recall 22 • Oracle of known refactorings

    applied by students – 7 open-source systems – 448 refactoring relationships • Compare RefDiff’s precison and recall with – Refactoring Miner – Refactoring Crawler – Ref-Finder
  23. Evaluation: Precision and Recall 23

  24. Conclusion 24 • RefDiff has better precision and recall than

    other approaches • Execution time is acceptable (1.96s per commit)
  25. Future Work 25 • Extended evaluation of RefDiff using actual

    refactorings applied in open-source systems
  26. THANK YOU! https://github.com/aserg-ufmg/RefDiff

  27. Evaluation: Precision and Recall 27

  28. Evaluation: Execution Time 28

  29. Evaluation: Execution Time 29 • We analyzed each commit between

    January 1, 2017 and March 27, of 10 Java repositories – 1990 commits • We compared execution time with Refactoring Miner
  30. Evaluation: Execution Time 30 Approach Avg. time (s) Total time(s)

    RefDiff 1.96 3,893 Ref. Miner 0.89 1,779
  31. Computing Similarity: Example 31

  32. Computing Similarity: Example 32

  33. Computing Similarity: Example 33

  34. Computing Similarity 34 token frequency in entity e inverse document

    frequency of the token in the collection weighted Jaccard coefficient