论文标题
使用基于路径的代码表示移动方法的建议重构
Recommendation of Move Method Refactoring Using Path-Based Representation of Code
论文作者
论文摘要
软件重构在提高代码质量中起着重要作用。最受欢迎的重构类型之一是移动方法重构。通常,当方法更多地取决于其他类的成员而不是其自己的原始类时,通常会应用。已经提出了几种方法来自动推荐移动方法重构。它们中的大多数是基于启发式方法,并且具有一定的局限性(例如,它们取决于指标和手动定义的阈值的选择)。在本文中,我们提出了一种方法,建议基于名为Code2Vec的代码的基于路径的表示方法进行重构,该代码能够捕获代码片段的句法结构和语义信息。我们使用此代码表示来训练机器学习分类器建议将方法移至更合适的类。我们在两个可公开可用的数据集上评估了该方法:一个手动编译的著名开源项目数据集和一个具有自动注入代码气味实例的合成数据集。结果表明,我们的方法能够推荐准确的重构机会,并胜过Jdeodorant和Jmove,这是该领域最先进的工具。
Software refactoring plays an important role in increasing code quality. One of the most popular refactoring types is the Move Method refactoring. It is usually applied when a method depends more on members of other classes than on its own original class. Several approaches have been proposed to recommend Move Method refactoring automatically. Most of them are based on heuristics and have certain limitations (e.g., they depend on the selection of metrics and manually-defined thresholds). In this paper, we propose an approach to recommend Move Method refactoring based on a path-based representation of code called code2vec that is able to capture the syntactic structure and semantic information of a code fragment. We use this code representation to train a machine learning classifier suggesting to move methods to more appropriate classes. We evaluate the approach on two publicly available datasets: a manually compiled dataset of well-known open-source projects and a synthetic dataset with automatically injected code smell instances. The results show that our approach is capable of recommending accurate refactoring opportunities and outperforms JDeodorant and JMove, which are state of the art tools in this field.