Journal of Computer Applications ›› 2022, Vol. 42 ›› Issue (6): 1702-1707.DOI: 10.11772/j.issn.1001-9081.2021061403

• National Open Distributed and Parallel Computing Conference 2021 (DPCS 2021) • Previous Articles    

Coupling related code smell detection method based on deep learning

Shan SU, Yang ZHANG(), Dongwen ZHANG   

  1. School of Information Science and Engineering,Hebei University of Science and Technology,Shijiazhuang Hebei 050018,China
  • Received:2021-08-05 Revised:2021-09-08 Accepted:2021-10-20 Online:2022-01-10 Published:2022-06-10
  • Contact: Yang ZHANG
  • About author:SU Shan,born in 1995,M. S. candidate. Her research interestsinclude software refactoring.
    ZHANG Dongwen,born in 1964,Ph. D.,professor. Her researchinterests include intelligent software,software refactoring
  • Supported by:
    National Natural Science Foundation of China(61440012);Key Basic Research Project of Hebei Fundamental Research Plan(18960106D)

基于深度学习的耦合度相关代码坏味检测方法

苏珊, 张杨(), 张冬雯   

  1. 河北科技大学 信息科学与工程学院,石家庄 050018
  • 通讯作者: 张杨
  • 作者简介:苏珊(1995—),女,河北石家庄人,硕士研究生,主要研究方向:软件重构
    张冬雯(1964—),女,河北石家庄人,教授,博士,CCF 会员,主要研究方向:智能软件、软件重构。
  • 基金资助:
    国家自然科学基金资助项目(61440012);河北省基础研究计划重点基础专项(18960106D)

Abstract:

Heuristic and machine learning based code smell detection methods have been proved to have limitations, and most of these methods focus on the common code smells. In order to solve these problems, a deep learning based method was proposed to detect three relatively rare code smells which are related to coupling, those are Intensive Coupling, Dispersed Coupling and Shotgun Surgery. First, the metrics of three code smells were extracted, and the obtained data were processed. Second, a deep learning model combining Convolutional Neural Network (CNN) and attention mechanism was constructed, and the introduced attention mechanism was able to assign weights to the metric features. The datasets were extracted from 21 open source projects, and the detection methods were validated in 10 open source projects and compared with CNN model. Experimental results show that the proposed model achieves the better performance with the code smell precisions of 93.61% and 99.76% for Intensive Coupling and Dispersed Coupling respectively, and the CNN model achieves the better results with the code smell precision of 98.59% for Shotgun Surgery.

Key words: code smell, coupling, deep learning, Convolutional Neural Network (CNN), attention mechanism

摘要:

基于启发式和机器学习的代码坏味检测方法已被证明具有一定的局限性,且现有的检测方法大多集中在较为常见的代码坏味上。针对这些问题,提出了一种深度学习方法来检测过紧的耦合、分散的耦合和散弹式修改这三种与耦合度相关检测较为少见的代码坏味。首先,提取三种代码坏味需要的度量并对得到的数据进行处理;之后,构建卷积神经网络(CNN)与注意力(Attention)机制相结合的深度学习模型,引入的注意力机制可以对输入的度量特征进行权重的分配。从21个开源项目中提取数据集,在10个开源项目中对检测方法进行了验证,并与CNN模型进行对比。实验结果表明:过紧的耦合和分散的耦合在所提模型中取得了更好的结果,相应代码坏味的查准率分别达到了93.61%和99.76%;而散弹式修改在CNN模型中有更好的结果,相应代码坏味查准率达到了98.59%。

关键词: 代码坏味, 耦合, 深度学习, 卷积神经网络, 注意力机制

CLC Number: