基于预训练模型和多层次信息的代码坏味检测方法
作者:
通讯作者:

张杨,E-mail:zhangyang@hebust.edu.cn

中图分类号:

TP311

基金项目:

国家自然科学基金(62172037); 河北省自然科学基金重点项目(18960106D); 河北省高等学校科学研究计划重点项目(ZD2019093)


Code Smell Detection Approach Based on Pre-training Model and Multi-level Information
Author:
  • 摘要
  • | |
  • 访问统计
  • |
  • 参考文献 [55]
  • |
  • 相似文献 [20]
  • | | |
  • 文章评论
    摘要:

    目前已有的代码坏味检测方法仅依赖于代码结构信息和启发式规则, 对嵌入在不同层次代码中的语义信息关注不够, 而且现有的代码坏味检测方法准确率还有进一步提升的空间. 针对该问题, 提出一种基于预训练模型和多层次信息的代码坏味检测方法DeepSmell, 首先采用静态分析工具提取程序中的代码坏味实例和多层次代码度量信息, 并对代码坏味实例进行标记; 然后通过抽象语法树解析并获取源代码中与代码坏味相关的层次信息, 将其中的文本信息与度量信息相结合生成数据样本; 最后使用BERT预训练模型将文本信息转化为词向量, 应用GRU-LSTM模型获取层次信息之间潜在的语义关系, 并结合CNN模型与注意力机制检测代码坏味. 在实验中, 选取JUnit、Xalan和SPECjbb2005等24个大型实际应用程序构建训练集和测试集, 并对特征依恋、长方法、数据类和上帝类等4种代码坏味进行检测. 实验结果表明, DeepSmell与目前已有的检测方法相比在平均查全率和F1值上分别提高了9.3%和10.44%, 同时保持了较高的查准率, DeepSmell可以有效地实现代码坏味检测.

    Abstract:

    Most of the existing code smell detection approaches rely on code structure information and heuristic rules, while pay little attention to the semantic information embedded in different levels of code, and the accuracy of code smell detection approaches is not high. To solve this problem, this study proposes a novel approach DeepSmell based on a pre-trained model and multi-level metrics. Firstly, the static analysis tool is used to extract code smell instances and multi-level code metric information in the source program and mark these instances. Secondly, the level information that relate to code smells in the source code are parsed and obtained through the abstract syntax tree. The textual information composed of the level information is combined with code metric information to generate the data set. Finally, text information is converted into word vectors using the BERT pre-training model. The GRU-LSTM model is applied to obtain the potential semantic relationship among the identifiers, and the CNN model is combined with attention mechanism to code smell detection. The experiment tested four kinds of code smells including feature envy, long method, data class, and god class on 24 open source programs such as JUnit, Xalan, and SPECjbb2005. The results show that DeepSmell improves the average recall and F1 by 9.3% and 10.44% respectively compared with existing detection methods, and maintains a high level of precision at the same time.

    参考文献
    [1] Mayvan BB, Rasoolzadegan A, Jafari AJ. Bad smell detection using quality metrics and refactoring opportunities. Journal of Software: Evolution and Process, 2020, 32(8): e2255. [doi: 10.1002/smr.2255]
    [2] Fowler M. Refactoring: Improving the Design of Existing Code. AddisonWesley, 1999. 16–50.
    [3] Palomba F, Bavota G, Di Penta M, Fasano F, Oliveto R, De Lucia A. On the diffuseness and the impact on maintainability of code smells: A large scale empirical investigation. In: Proc. of the 40th Int’l Conf. on Software Engineering. Gothenburg: ACM, 2018. 482.
    [4] Fokaefs M, Tsantalis N, Stroulia E, Chatzigeorgiou A. JDeodorant: Identification and application of extract class refactorings. In: Proc. of the 33rd Int’l Conf. on Software Engineering. Honolulu: ACM, 2011. 1037−1039.
    [5] Marinescu C, Marinescu R, Mihancea PF, Ratiu D, Wettel R. iPlasma: An integrated platform for quality assessment of object-oriented design. In: Proc. of the 21st IEEE Int’l Conf. on Software Maintenance. Budapest: ICSM, 2005. 77–80.
    [6] Nongpong K. Integrating “code smells” detection with refactoring tool support [Ph.D. Thesis]. Milwaukee: University of Wisconsin-Milwaukee, 2012. 106–112.
    [7] Fontana FA, Mäntylä MV, Zanoni M, Marino A. Comparing and experimenting machine learning techniques for code smell detection. Empirical Software Engineering, 2016, 21(3): 1143–1191. [doi: 10.1007/s10664-015-9378-4]
    [8] Pecorelli F, Palomba F, Di Nucci D, De Lucia A. Comparing heuristic and machine learning approaches for metric-based code smell detection. In: Proc. of the 27th Int’l Conf. on Program Comprehension (ICPC). Montreal: IEEE, 2019. 93–104.
    [9] 马赛, 董东. 基于潜在语义分析的Large Class检测. 计算机科学, 2017, 44(S1): 495–498. [doi: 10.11896/j.issn.1002-137X.2017.6A.110]
    Ma S, Dong D. Detection of Large Class based on latent semantic analysis. Computer Science, 2017, 44(S1): 495–498 (in Chinese with English abstract). [doi: 10.11896/j.issn.1002-137X.2017.6A.110]
    [10] 王曙燕, 张一权, 孙家泽. 基于BP神经网络的代码坏味检测. 计算机工程, 2020, 46(10): 216–222, 230. [doi: 10.19678/j.issn.1000-3428.0055862]
    Wang SY, Zhang YQ, Sun JZ. Detection of bad smell in code based on BP neural network. Computer Engineering, 2020, 46(10): 216–222, 230 (in Chinese with English abstract). [doi: 10.19678/j.issn.1000-3428.0055862]
    [11] Liu H, Xu ZF, Zou YZ. Deep learning based feature envy detection. In: Proc. of the 33rd ACM/IEEE Int’l Conf. on Automated Software Engineering. Montpellier: ACM, 2018. 385–396.
    [12] Tiwari O, Joshi RK. Functionality based code smell detection and severity classification. In: Proc. of the 13th Innovations in Software Engineering Conf. on Formerly Known as India Software Engineering Conf. Jabalpur: ACM, 2020. 14.
    [13] 张生栋, 吴海涛, 高建华. 利用主轴因子法的严重性代码异味相关性分析. 小型微型计算机系统, 2021, 42(4): 853–860.
    Zhang SD, Wu HT, Gao JH. Correlation analysis of code smells with severity by principal axis factor method. Journal of Chinese Computer Systems, 2021, 42(4): 853–860 (in Chinese with English abstract).
    [14] 位欢欢. 基于层次和代码变更的两阶异味重构推荐策略 [硕士学位论文]. 上海: 上海师范大学, 2020.
    Wei HH. A recommendation strategy for two-order odor reconstruction based on hierarchy and code change [MS. Thesis]. Shanghai: Shanghai Normal University, 2020 (in Chinese with English abstract).
    [15] Wang Y, Yu H, Zhu ZL, Zhang W, Zhao YL. Automatic software refactoring via weighted clustering in method-level networks. IEEE Transactions on Software Engineering, 2018, 44(3): 202–236. [doi: 10.1109/TSE.2017.2679752]
    [16] 孟繁祎, 王莹, 于海, 朱志良. 复杂软件系统的重构技术: 现状、问题与展望. 计算机科学, 2020, 47(12): 1–10. [doi: 10.11896/jsjkx.200800067]
    Meng FY, Wang Y, Yu H, Zhu ZL. Refactoring of complex software systems research: Present, problem and prospect. Computer Science, 2020, 47(12): 1–10 (in Chinese with English abstract). [doi: 10.11896/jsjkx.200800067]
    [17] Moha N, Gueheneuc YG, Duchien L, Le Meur AF. DECOR: A method for the specification and detection of code and design smells. IEEE Transactions on Software Engineering, 2010, 36(1): 20-36. [doi: 10.1109/TSE.2009.50]
    [18] Terra R, Valente MT, Miranda S, Sales V. JMove: A novel heuristic and tool to detect move method refactoring opportunities. Journal of Systems and Software, 2018, 138: 19–36. [doi: 10.1016/j.jss.2017.11.073]
    [19] Fard AM, Mesbah A. JSNOSE: Detecting JavaScript code smells. In: Proc. of the 13th IEEE Int’l Working Conf. on Source Code Analysis and Manipulation (SCAM). 2013. 116–125.
    [20] Fernandes E, Oliveira J, Vale G, Paiva T, Figueiredo E. A review-based comparative study of bad smell detection tools. In: Proc. of the 20th Int’l Conf. on Evaluation and Assessment in Software Engineering. Limerick: ACM, 2016. 18.
    [21] 张杨, 邵帅, 张冬雯. 基于下推自动机的细粒度锁自动重构方法. 软件学报, 2021, 32(12): 3710–3727. http://www.jos.org.cn/1000-9825/6132.htm
    Zhang Y, Shao S, Zhang DW. Automated refactoring approach for fine-grained lock based on pushdown automaton. Ruan Jian Xue Bao/Journal of Software, 2021, 32(12): 3710–3727 (in Chinese with English abstract). http://www.jos.org.cn/1000-9825/6132.htm
    [22] Zhang Y, Li LX, Zhang DW. A survey of concurrency-oriented refactoring. Concurrent Engineering, 2020, 28(4): 319–330. [doi: 10.1177/1063293X20958932]
    [23] Khomh F, Vaucher S, Guéhéneuc YG, Sahraoui H. BDTEX: A GQM-based Bayesian approach for the detection of antipatterns. Journal of Systems and Software, 2011, 84(4): 559–572. [doi: 10.1016/j.jss.2010.11.921]
    [24] Amal A, Hamoud A. Code smell detection using feature selection and stacking ensemble: An empirical investigation. Information Software Technology. 2021, 138: 106648.
    [25] Kreimer J. Adaptive detection of design flaws. Electronic Notes in Theoretical Computer Science, 2005, 141(4): 117–136. [doi: 10.1016/j.entcs.2005.02.059]
    [26] Amorim L, Costa E, Antunes N, Fonseca B, Ribeiro M. Experience report: Evaluating the effectiveness of decision trees for detecting code smells. In: Proc. of the 26th Int’l Symp. on Software Reliability Engineering. Gaithersbury: IEEE, 2015. 261–269.
    [27] Nucci DD, Palomba F, Tamburri DA, Serebrenik A, De Lucia A. Detecting code smells using machine learning techniques: Are we there yet? In: Proc. of the 25th Int’l Conf. on Software Analysis, Evolution and Reengineering. Campobasso: IEEE, 2018. 612–621.
    [28] Guggulothu T. Code smell detection using multilabel classification approach. arXiv: 1902.03222, 2019.
    [29] Maiga A, Ali N, Bhattacharya N, Sabané A, Guéhéneuc YG, Antoniol G, Aïmeur E. Support vector machines for anti-pattern detection. In: Proc. of the 27th IEEE/ACM Int’l Conf. on Automated Software Engineering. Essen: ACM, 2012. 278–281.
    [30] 王继娜, 陈军华, 高建华. 基于排序损失的ECC多标签代码异味检测方法. 计算机研究与发展, 2021, 58(1): 178–188. [doi: 10.7544/issn1000-1239.2021.20190836]
    Wang JN, Chen JH, Gao JH. ECC multi-label code smell detection method based on ranking loss. Journal of Computer Research and Development, 2021, 58(1): 178–188 (in Chinese with English abstract). [doi: 10.7544/issn1000-1239.2021.20190836]
    [31] Liu H, Jin JH, Xu ZF, Zou YZ, Bu YF, Zhang L. Deep learning based code smell detection. IEEE Transactions on Software Engineering, 2021, 47(9): 1811–1837. [doi: 10.1109/TSE.2019.2936376]
    [32] 卜依凡, 刘辉, 李光杰. 一种基于深度学习的上帝类检测方法. 软件学报, 2019, 30(5): 1359-1374. http://www.jos.org.cn/1000-9825/5724.htm
    Bu YF, Liu H, Li GJ. God class detection approach based on deep learning. Ruan Jian Xue Bao/Journal of Software, 2019, 30(5): 1359-1374 (in Chinese with English abstract). http://www.jos.org.cn/1000-9825/5724.htm
    [33] Das AK, Yadav S, Dhal S. Detecting code smells using deep learning. In: Proc. of the 2019 IEEE Region 10 Conf. (TENCON). Kochi: IEEE, 2019. 2081–2086.
    [34] Guo XL, Shi CY, Jiang H. Deep semantic-based feature envy identification. In: Proc. of the 11th Asia-Pacific Symp. on Internetware. Fukuoka: ACM, 2019. 19.
    [35] Singh R, Bindal A, Kumar A. Long method and long parameter list code smells detection using functional and semantic characteristics. International Journal of Recent Technology and Engineering, 2020, 8(6): 2223–2232. [doi: 10.35940/ijrte.E5888.038620]
    [36] Fang CR, Liu ZX, Shi YY, Huang J, Shi QK. Functional code clone detection with syntax and semantics fusion learning. In: Proc. of the 29th ACM SIGSOFT Int’l Symp. on Software Testing and Analysis. New York: ACM, 2020. 516–527.
    [37] 刘弋, 吴毅坚, 彭鑫, 闫亚东. 基于图模型和孤立森林的上帝类检测方法. 软件学报, 2021. http://www.jos.org.cn/1000-9825/6373.htm
    Liu Y, Wu YJ, Peng X, Yan YD. God class detection approach based on graph model and isolation forest. Ruan Jian Xue Bao/Journal of Software (in Chinese with English abstract), 2021. http://www.jos.org.cn/1000-9825/6373.htm
    [38] Devlin J, Chang MW, Lee K, Toutanova. BERT: Pre-training of deep bidirectional transformers for language understanding. In: Proc. of the 2019 Conf. of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. Minneapolis: Association for Computational Linguistics, 2018. 4171–4186.
    [39] Chung J, Gulcehre C, Cho K, Bengio Y. Empirical evaluation of gated recurrent neural networks on sequence modeling. In: Proc. of the NIPS 2014 Workshop on Deep Learning. 2014.
    [40] Pennington J, Socher R, Manning C. GloVe: Global vectors for word representation. In: Proc. of the 2014 Conf. on Empirical Methods in Natural Language Processing. Doha: ACL, 2014. 1532–1543.
    [41] Mikolov T, Sutskever I, Chen K, Corrado GS, Dean J. Distributed representations of words and phrases and their compositionality. In: Proc. of the 27th Annual Conf. on Neural Information Processing Systems 2013. Lake Tahoe, 2013. 3111–3119.
    [42] Vaswani A, Shazeer N, Parmar N, Uszkoreit J, Jones L, Gomez AN, Kaiser Ł, Polosukhin I. Attention is all you need. In: Proc. of the 31st Int’l Conf. on Neural Information Processing Systems. Long Beach: Curran Associates Inc. , 2017. 6000–6010.
    [43] Marinescu R. Measurement and quality in object-oriented design. In: Proc. of the 21st IEEE Int’l Conf. on Software Maintenance. Budapest: IEEE, 2005. 701–704.
    [44] Trifu A, Marinescu R. Diagnosing design problems in object oriented systems. In: Proc. of the 12th Working Conf. on Reverse Engineering. Pittsburgh: IEEE, 2005. 1–10.
    [45] Cheng HT, Koc L, Harmsen J, Shaked T, Chandra T, Aradhye H, Anderson G, Corrado G, Chai W, Ispir M, Anil R, Haque Z, Hong LC, Jain V, Liu XB, Shah H. Wide & deep learning for recommender systems. In: Proc. of the 1st Workshop on Deep Learning for Recommender Systems. Boston: ACM, 2016. 7–10.
    [46] Guo HF, Tang RM, Ye YM, Li ZG, He XQ. DeepFM: A factorization-machine based neural network for CTR prediction. In: Proc. of the 26th Int’l Joint Conf. on Artificial Intelligence. Melbourne, 2017. 1725–1731.
    引证文献
    网友评论
    网友评论
    分享到微博
    发 布
引用本文

张杨,东春浩,刘辉,葛楚妍.基于预训练模型和多层次信息的代码坏味检测方法.软件学报,2022,33(5):1551-1568

复制
分享
文章指标
  • 点击次数:1794
  • 下载次数: 5298
  • HTML阅读次数: 2740
  • 引用次数: 0
历史
  • 收稿日期:2021-08-06
  • 最后修改日期:2021-10-09
  • 在线发布日期: 2022-01-28
  • 出版日期: 2022-05-06
文章二维码
您是第19710135位访问者
版权所有:中国科学院软件研究所 京ICP备05046678号-3
地址:北京市海淀区中关村南四街4号,邮政编码:100190
电话:010-62562563 传真:010-62562533 Email:jos@iscas.ac.cn
技术支持:北京勤云科技发展有限公司

京公网安备 11040202500063号