Efficient feature envy detection and refactoring based on graph neural network

被引:1
作者
Yu, Dongjin [1 ]
Xu, Yihang [1 ]
Weng, Lehui [1 ]
Chen, Jie [1 ]
Chen, Xin [1 ]
Yang, Quanxin [1 ,2 ]
机构
[1] Hangzhou Dianzi Univ, Coll Comp Sci & Technol, Baiyang St, Hangzhou 310000, Zhejiang, Peoples R China
[2] Xuchang Univ, Sch Informat Engn, Xuchang, Peoples R China
基金
中国国家自然科学基金;
关键词
Code smell; Feature envy; Refactoring; Graph neural network; Metrics;
D O I
10.1007/s10515-024-00476-3
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
As one type of frequently occurring code smells, feature envy negatively affects class cohesion, increases coupling between classes, and thus hampers software maintainability. While progress has been made in feature envy detection, two challenges still persist. Firstly, existing approaches often underutilize method call relationships, resulting in suboptimal detection efficiency. Secondly, they lack the emphasis on feature envy refactoring, which is however the ultimate goal of feature envy detection. To address these challenges, we propose two approaches: SCG (SMOTE Call Graph) and SFFL (Symmetric Feature Fusion Learning). SCG transforms the feature envy detection problem into a binary classification task on a method call graph. It predicts the weights of edges, termed calling strength, to capture the strength of method invocations. Additionally, it converts the method-method call graph into a method-class call graph and recommends the smelly method to the external class with the highest calling strength. As a holistic approach focusing on refactoring feature envy directly, SFFL leverages four heterogeneous graphs to represent method-class relationships. Through Symmetric Feature Fusion Learning, it obtains representations for methods and classes. Link prediction is then employed to generate the refactored method-class ownership graph, which is regarded as the refactored results. Moreover, to address the limitations of existing metrics in accurately evaluating refactoring performance, we introduce three new metrics: precision2\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textit{precision}_2$$\end{document}, recall2\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textit{recall}_2$$\end{document} and F1-score2\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\textit{F}_1\text {-score}_2$$\end{document}. Extensive experiments on five open-source projects demonstrate the superiority of SCG and SFFL. The code and dataset used in our study are available at https://github.com/HduDBSI/SCG-SFFL.
引用
收藏
页数:49
相关论文
共 39 条
[21]   DACOS-A Manually Annotated Dataset of Code Smells [J].
Nandani, Himesh ;
Saad, Mootez ;
Sharma, Tushar .
2023 IEEE/ACM 20TH INTERNATIONAL CONFERENCE ON MINING SOFTWARE REPOSITORIES, MSR, 2023, :446-450
[22]   On the diffuseness and the impact on maintainability of code smells: a large scale empirical investigation [J].
Palomba, Fabio ;
Bavota, Gabriele ;
Di Penta, Massimiliano ;
Fasano, Fausto ;
Oliveto, Rocco ;
De Lucia, Andrea .
EMPIRICAL SOFTWARE ENGINEERING, 2018, 23 (03) :1188-1221
[23]  
Sales V, 2013, WORK CONF REVERSE EN, P232, DOI 10.1109/WCRE.2013.6671298
[24]   Bidirectional recurrent neural networks [J].
Schuster, M ;
Paliwal, KK .
IEEE TRANSACTIONS ON SIGNAL PROCESSING, 1997, 45 (11) :2673-2681
[25]   An automated extract method refactoring approach to correct the long method code smell [J].
Shahidi, Mahnoosh ;
Ashtiani, Mehrdad ;
Zakeri-Nasrabadi, Morteza .
JOURNAL OF SYSTEMS AND SOFTWARE, 2022, 187
[26]   QScored: A Large Dataset of Code Smells and Quality Metrics [J].
Sharma, Tushar ;
Kessentini, Marouane .
2021 IEEE/ACM 18TH INTERNATIONAL CONFERENCE ON MINING SOFTWARE REPOSITORIES (MSR 2021), 2021, :590-594
[27]   Code smell detection by deep direct-learning and transfer-learning? [J].
Sharma, Tushar ;
Efstathiou, Vasiliki ;
Louridas, Panos ;
Spinellis, Diomidis .
JOURNAL OF SYSTEMS AND SOFTWARE, 2021, 176 (176)
[28]  
Simon F, 2001, FIFTH EUROPEAN CONFERENCE ON SOFTWARE MAINTENANCE AND REENGINEERING, PROCEEDINGS, P30, DOI 10.1109/CSMR.2001.914965
[29]   JMove: A novel heuristic and tool to detect move method refactoring opportunities [J].
Terra, Ricardo ;
Valente, Marco Tulio ;
Miranda, Sergio ;
Sales, Vitor .
JOURNAL OF SYSTEMS AND SOFTWARE, 2018, 138 :19-36
[30]  
Tsantalis N, 2018, 2018 25TH IEEE INTERNATIONAL CONFERENCE ON SOFTWARE ANALYSIS, EVOLUTION AND REENGINEERING (SANER 2018), P4, DOI 10.1109/SANER.2018.8330192