一句话:用真实重构样本训练深度学习模型,并引入方法与类间耦合特征,大幅提升 Feature Envy 检测精度。
Feature Envy 是一种典型的代码异味,通常应通过重构消除。其检测难点在于传统方法准确率较低,而深度学习方法又缺乏高质量的大规模训练数据;虽然重构检测工具可发现真实样本,但结果中含大量假阳性噪声,会严重影响训练数据与模型性能。本文提出一组启发式规则和基于决策树的分类器,用于过滤当前先进重构检测工具报告中的假阳性,将过滤后的样本作为正例,并从同一项目中随机选取不同方法作为负例。基于这些真实样本,作者设计并训练了一个深度学习二分类模型,判断给定方法是否应移动到潜在目标类。该模型还利用了已有方法未使用的特征:方法与类之间的耦合(CBMC)以及方法与类之间的消息传递耦合(MCMC)。在真实开源项目上的评估表明,该方法显著优于现有最佳方法,精确率和召回率分别提升 38.5% 和 20.8%。
Feature envy is one of the well-recognized code smells that should be removed by software refactoring. A major challenge in feature envy detection is that traditional approaches are less accurate whereas deep learning-based approaches are suffering from the lack of high-quality large-scale training data. Although existing refactoring detection tools could be employed to discover real-world feature envy examples, the noise (i.e., false positives) within the resulting data could significantly influence the quality of the training data as well as the performance of the models trained on the data. To this end, in this paper, we propose a sequence of heuristic rules and a decision tree-based classifier to filter out false positives reported by state-of-the-art refactoring detection tools. The data after filtering serve as the positive items in the requested training data. From the same subject projects, we randomly select methods that are different from positive items as negative items. With the real-world examples (both positive and negative examples), we design and train a deep learning-based binary model to predict whether a given method should be moved to a potential target class. Different from existing models, it leverages additional features, i.e., coupling between methods and classes (CBMC) and the message passing coupling between methods and classes (MCMC) that have not yet been exploited by existing approaches. Our evaluation results on real-world open-source projects suggest that the proposed approach substantially outperforms the state of the art in feature envy detection, improving precision and recall by 38.5% and 20.8%, respectively.
@inproceedings{LiuLLNXWXZJ23,
title = {Deep Learning Based Feature Envy Detection Boosted by Real-World Examples},
author = {Bo Liu and Hui Liu and Guangjie Li and Nan Niu and Zimao Xu and Yifan Wang and Yunni Xia and Yuxia Zhang and Yanjie Jiang},
booktitle = {FSE},
year = {2023},
doi = {10.1145/3611643.3616353}
}