《计算机应用》唯一官方网站 ›› 2022, Vol. 42 ›› Issue (6): 1702-1707.DOI: 10.11772/j.issn.1001-9081.2021061403
• 2021年全国开放式分布与并行计算学术年会(DPCS 2021)论文 • 上一篇
收稿日期:
2021-08-05
修回日期:
2021-09-08
接受日期:
2021-10-20
发布日期:
2022-01-10
出版日期:
2022-06-10
通讯作者:
张杨
作者简介:
苏珊(1995—),女,河北石家庄人,硕士研究生,主要研究方向:软件重构基金资助:
Shan SU, Yang ZHANG(), Dongwen ZHANG
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.Supported by:
摘要:
基于启发式和机器学习的代码坏味检测方法已被证明具有一定的局限性,且现有的检测方法大多集中在较为常见的代码坏味上。针对这些问题,提出了一种深度学习方法来检测过紧的耦合、分散的耦合和散弹式修改这三种与耦合度相关检测较为少见的代码坏味。首先,提取三种代码坏味需要的度量并对得到的数据进行处理;之后,构建卷积神经网络(CNN)与注意力(Attention)机制相结合的深度学习模型,引入的注意力机制可以对输入的度量特征进行权重的分配。从21个开源项目中提取数据集,在10个开源项目中对检测方法进行了验证,并与CNN模型进行对比。实验结果表明:过紧的耦合和分散的耦合在所提模型中取得了更好的结果,相应代码坏味的查准率分别达到了93.61%和99.76%;而散弹式修改在CNN模型中有更好的结果,相应代码坏味查准率达到了98.59%。
中图分类号:
苏珊, 张杨, 张冬雯. 基于深度学习的耦合度相关代码坏味检测方法[J]. 计算机应用, 2022, 42(6): 1702-1707.
Shan SU, Yang ZHANG, Dongwen ZHANG. Coupling related code smell detection method based on deep learning[J]. Journal of Computer Applications, 2022, 42(6): 1702-1707.
度量 | 定义 |
---|---|
CINT | 被检测方法调用其他类中方法的数量 |
CDISP | 判定一个方法耦合分散度的指标 |
CC | 其他类中调用被检测方法的方法数量 |
CM | 与被检测方法有联系的类的数量 |
MAXNESTING | 被检测方法嵌套层次结构中最多层的层数 |
表1 代码坏味度量
Tab. 1 Metrics of code smell
度量 | 定义 |
---|---|
CINT | 被检测方法调用其他类中方法的数量 |
CDISP | 判定一个方法耦合分散度的指标 |
CC | 其他类中调用被检测方法的方法数量 |
CM | 与被检测方法有联系的类的数量 |
MAXNESTING | 被检测方法嵌套层次结构中最多层的层数 |
项目名称 | 项目领域 | NOC | NOM | LOC |
---|---|---|---|---|
argouml | UML图绘制 | 1 953 | 17 466 | 160 354 |
axion | gradle管理插件 | 35 | 313 | 1 096 |
Emmagee | 性能测试工具 | 9 | 58 | 907 |
fullsync | 文件同步工具 | 139 | 806 | 3 900 |
heritrix3 | 爬虫工具包 | 555 | 4 722 | 41 972 |
hsqldb | 数据库 | 659 | 12 915 | 227 069 |
ipscan | ip端口扫描 | 184 | 933 | 6 584 |
javacc | 词法分析器 | 180 | 1 487 | 20 861 |
jGroups | 群组通信工具 | 251 | 1 935 | 13 199 |
jparsec | 解析jQuery | 237 | 1 274 | 7 387 |
jspwiki | Wiki系统 | 30 | 2 243 | 21 296 |
keystore | 数据证书工具 | 272 | 1 593 | 21 215 |
marauroa | 服务器端框架 | 231 | 1 866 | 19 044 |
picocontainer | 微核心容器 | 1 005 | 6 862 | 48 468 |
quartz | 分布式框架 | 465 | 4 585 | 41 749 |
QuickServer | 服务器端组件 | 165 | 1 699 | 16 633 |
roller | 博客服务器 | 549 | 5 040 | 47 848 |
squirrel | 数据库工具 | 192 | 1 428 | 8 922 |
xalan | xslt处理器 | 964 | 10 359 | 188 637 |
xerces | xml解析器 | 838 | 10 717 | 142 249 |
you-jextractor | 下载工具 | 76 | 646 | 2 711 |
表2 训练集所涉项目
Tab. 2 Projects for training set
项目名称 | 项目领域 | NOC | NOM | LOC |
---|---|---|---|---|
argouml | UML图绘制 | 1 953 | 17 466 | 160 354 |
axion | gradle管理插件 | 35 | 313 | 1 096 |
Emmagee | 性能测试工具 | 9 | 58 | 907 |
fullsync | 文件同步工具 | 139 | 806 | 3 900 |
heritrix3 | 爬虫工具包 | 555 | 4 722 | 41 972 |
hsqldb | 数据库 | 659 | 12 915 | 227 069 |
ipscan | ip端口扫描 | 184 | 933 | 6 584 |
javacc | 词法分析器 | 180 | 1 487 | 20 861 |
jGroups | 群组通信工具 | 251 | 1 935 | 13 199 |
jparsec | 解析jQuery | 237 | 1 274 | 7 387 |
jspwiki | Wiki系统 | 30 | 2 243 | 21 296 |
keystore | 数据证书工具 | 272 | 1 593 | 21 215 |
marauroa | 服务器端框架 | 231 | 1 866 | 19 044 |
picocontainer | 微核心容器 | 1 005 | 6 862 | 48 468 |
quartz | 分布式框架 | 465 | 4 585 | 41 749 |
QuickServer | 服务器端组件 | 165 | 1 699 | 16 633 |
roller | 博客服务器 | 549 | 5 040 | 47 848 |
squirrel | 数据库工具 | 192 | 1 428 | 8 922 |
xalan | xslt处理器 | 964 | 10 359 | 188 637 |
xerces | xml解析器 | 838 | 10 717 | 142 249 |
you-jextractor | 下载工具 | 76 | 646 | 2 711 |
方法 | CINT | CDISP | MAXNESTING | INTENSIVE |
---|---|---|---|---|
exit | 0.38 | 16 | 3 | 1 |
setTool | 1 | 1 | 2 | 0 |
setTime | 1 | 1 | 2 | 0 |
unlock | 0.18 | 11 | 3 | 1 |
表3 过紧的耦合训练数据集
Tab. 3 Training set of Intensive Coupling
方法 | CINT | CDISP | MAXNESTING | INTENSIVE |
---|---|---|---|---|
exit | 0.38 | 16 | 3 | 1 |
setTool | 1 | 1 | 2 | 0 |
setTime | 1 | 1 | 2 | 0 |
unlock | 0.18 | 11 | 3 | 1 |
项目名称 | 项目领域 | NOC | NOM | LOC |
---|---|---|---|---|
ArtOfIllusion | 3D动画 | 492 | 6 766 | 103 586 |
FreePlane | 思维导图 | 787 | 6 938 | 124 937 |
jasperreports | 报表工具 | 2 890 | 23 055 | 202 308 |
Jdeodorant | 代码结构分析 | 391 | 4 265 | 84 726 |
jEdit | 文本编辑器 | 584 | 7 418 | 104 771 |
jfreechart | 图表绘制类库 | 713 | 6 953 | 70 227 |
pmd | 代码检查工具 | 2 194 | 10 105 | 51 296 |
elasticsearch | 搜索服务器 | 3 356 | 31 160 | 198 869 |
netty | Java开源框架 | 2 458 | 27 183 | 212 343 |
omega | 辅助翻译工具 | 631 | 4 543 | 39 153 |
表4 测试集所涉项目
Tab. 4 Projects for test set
项目名称 | 项目领域 | NOC | NOM | LOC |
---|---|---|---|---|
ArtOfIllusion | 3D动画 | 492 | 6 766 | 103 586 |
FreePlane | 思维导图 | 787 | 6 938 | 124 937 |
jasperreports | 报表工具 | 2 890 | 23 055 | 202 308 |
Jdeodorant | 代码结构分析 | 391 | 4 265 | 84 726 |
jEdit | 文本编辑器 | 584 | 7 418 | 104 771 |
jfreechart | 图表绘制类库 | 713 | 6 953 | 70 227 |
pmd | 代码检查工具 | 2 194 | 10 105 | 51 296 |
elasticsearch | 搜索服务器 | 3 356 | 31 160 | 198 869 |
netty | Java开源框架 | 2 458 | 27 183 | 212 343 |
omega | 辅助翻译工具 | 631 | 4 543 | 39 153 |
模型 | 标签 | 查准率 | 查全率 | |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.90 | 99.95 |
1 | 89.44 | 99.73 | 94.30 | |
Attention-CNN | 0 | 100.00 | 99.94 | 99.97 |
1 | 93.61 | 100.00 | 96.70 |
表5 过紧的耦合检测结果 ( %)
Tab. 5 Results of detection of Intensive Coupling
模型 | 标签 | 查准率 | 查全率 | |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.90 | 99.95 |
1 | 89.44 | 99.73 | 94.30 | |
Attention-CNN | 0 | 100.00 | 99.94 | 99.97 |
1 | 93.61 | 100.00 | 96.70 |
模型 | 标签 | 查准率 | 查全率 | |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.99 | 99.99 |
1 | 99.04 | 100.00 | 99.52 | |
Attention-CNN | 0 | 100.00 | 100.00 | 100.00 |
1 | 99.76 | 99.76 | 99.76 |
表6 分散的耦合检测结果 ( %)
Tab. 6 Results of detection of Dispersed Coupling
模型 | 标签 | 查准率 | 查全率 | |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.99 | 99.99 |
1 | 99.04 | 100.00 | 99.52 | |
Attention-CNN | 0 | 100.00 | 100.00 | 100.00 |
1 | 99.76 | 99.76 | 99.76 |
模型 | 标签 | 查准率 | 查全率 | F1 |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.99 | 99.99 |
1 | 98.59 | 100.00 | 99.45 | |
Attention-CNN | 0 | 100.00 | 99.92 | 99.96 |
1 | 95.66 | 100.00 | 97.78 |
表7 散弹式修改检测结果 ( %)
Tab. 7 Results of detection of Shotgun Surgery
模型 | 标签 | 查准率 | 查全率 | F1 |
---|---|---|---|---|
CNN | 0 | 100.00 | 99.99 | 99.99 |
1 | 98.59 | 100.00 | 99.45 | |
Attention-CNN | 0 | 100.00 | 99.92 | 99.96 |
1 | 95.66 | 100.00 | 97.78 |
模型 | 过紧的耦合 | 分散的耦合 | 散弹式修改 |
---|---|---|---|
CNN | 130.49 | 150.85 | 61.21 |
Attention-CNN | 131.68 | 157.60 | 69.58 |
表8 三种代码坏味的时间开销 ( s)
Tab. 8 Time consumption of three code smells
模型 | 过紧的耦合 | 分散的耦合 | 散弹式修改 |
---|---|---|---|
CNN | 130.49 | 150.85 | 61.21 |
Attention-CNN | 131.68 | 157.60 | 69.58 |
1 | MENS T, TOURWE T. A survey of software refactoring[J]. IEEE Transactions on Software Engineering, 2004, 30(2): 126-139. 10.1109/tse.2004.1265817 |
2 | FOWLER M, BECK K, BRANT J, et al. Refactoring: Improving the Design of Existing Code[M]. Boston: Addison-Wesley Professional, 1999: 71-76. |
3 | APRIL A, ABRAN A. Software Maintenance Management: Evaluation and Continuous Improvement [M]. Hoboken: John Wiley & Sons, 2012: 1-5. |
4 | YOSHIDA N, KINOSHITA M, IIDA H. A cohesion metric approach to dividing source code into functional segments to improve maintainability[C]// Proceedings of the 16th European Conference on Software Maintenance and Reengineering. Piscataway: IEEE, 2012: 365-370. 10.1109/csmr.2012.45 |
5 | PALOMBA F, BAVOTA G, DI PENTA M, et al. Mining version histories for detecting code smells[J]. IEEE Transactions on Software Engineering, 2015, 41(5): 462-489. 10.1109/tse.2014.2372760 |
6 | SALES V, TERRA R, MIRANDA L F, et al. Recommending move method refactorings using dependency sets[C]// Proceedings of the 20th Working Conference on Reverse Engineering. Piscataway: IEEE, 2013: 232-241. 10.1109/wcre.2013.6671298 |
7 | MÄNTYLÄ M V, LASSENIUS C. Subjective evaluation of software evolvability using code smells: an empirical study[J]. Empirical Software Engineering, 2006, 11(3): 395-431. 10.1007/s10664-006-9002-8 |
8 | MAIGA A, ALI N, BHATTACHARYA N, et al. Support vector machines for anti-pattern detection[C]// Proceedings of the 27th IEEE/ACM International Conference on Automated Software Engineering. Piscataway: IEEE, 2012: 278-281. 10.1145/2351676.2351723 |
9 | KREIMER J. Adaptive detection of design flaws[J]. Electronic Notes in Theoretical Computer Science, 2005, 141(4): 117-136. 10.1016/j.entcs.2005.02.059 |
10 | FONTANA F A, MÄNTYLÄ M V, ZANONI M, et al. Comparing and experimenting machine learning techniques for code smell detection[J]. Empirical Software Engineering, 2016, 21(3): 1143-1191. 10.1007/s10664-015-9378-4 |
11 | DI NUCCI D, PALOMBA F, TAMBURRI D A, et al. Detecting code smells using machine learning techniques: are we there yet? [C]// Proceedings of the 2018 IEEE 25th International Conference on Software Analysis, Evolution and Reengineering. Piscataway: IEEE, 2018: 612-621. 10.1109/saner.2018.8330266 |
12 | BENGIO Y, COURVILLE A, VINCENT P. Representation learning: a review and new perspectives[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2013, 35(8): 1798-1828. 10.1109/tpami.2013.50 |
13 | GUO X L, SHI C Y, JIANG H. Deep semantic-based feature envy identification[C]// Proceedings of the 11th Asia-Pacific Symposium on Internetware. New York: ACM, 2019: No.19. 10.1145/3361242.3361257 |
14 | 卜依凡,刘辉,李光杰. 一种基于深度学习的上帝类检测方法[J]. 软件学报, 2019, 30(5): 1360-1374. |
BU Y F, LIU H, LI G J. God class detection approach based on deep learning[J]. Journal of Software, 2019, 30(5): 1360-1374. | |
15 | KESSENTINI W, KESSENTINI M, SAHRAOUI H, et al. A cooperative parallel search-based software engineering approach for code-smells detection[J]. IEEE Transactions on Software Engineering, 2014, 40(9): 841-861. 10.1109/tse.2014.2331057 |
16 | FU S Z, SHEN B J. Code bad smell detection through evolutionary data mining[C]// Proceedings of the 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement. Piscataway: IEEE, 2015: 1-9. 10.1109/esem.2015.7321194 |
17 | VIDAL S, VAZQUEZ H, DIAZ-PACE J A, et al. JSpIRIT: a flexible tool for the analysis of code smells[C]// Proceedings of the 34th International Conference of the Chilean Computer Science Society. Piscataway: IEEE, 2015: 1-6. 10.1109/sccc.2015.7416572 |
18 | HADJ-KACEM M, BOUASSIDA N. A hybrid approach to detect code smells using deep learning[C]// Proceedings of the 13th International Conference on Evaluation of Novel Approaches to Software Engineering. Setúbal: SciTePress, 2018:137-146. 10.5220/0006709801370146 |
19 | KIM D K. Finding bad code smells with neural network models[J]. International Journal of Electrical and Computer Engineering, 2017, 7(6): 3613-3621. 10.11591/ijece.v7i6.pp3613-3621 |
20 | DAS A K, YADAV S, DHAL S. Detecting code smells using deep learning[C]// Proceedings of the 2019 IEEE Region 10 Conference. Piscataway: IEEE, 2019: 2081-2086. 10.1109/tencon.2019.8929628 |
21 | LANZA M, MARINESCU R. Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems[M]. Berlin: Springer, 2006: 115-167. |
22 | CHAWLA N V, BOWYER K W, HALL L O, et al. SMOTE: synthetic minority over-sampling technique[J]. Journal of Artificial Intelligence Research, 2002, 16: 321-357. 10.1613/jair.953 |
23 | BAHDANAU D, CHO K, BENGIO Y. Neural machine translation by jointly learning to align and translate [EB/OL]. [2020-12-08]. . 10.3115/v1/w14-4009 |
[1] | 任炜, 白鹤翔. 基于全局与局部标签关系的多标签图像分类方法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1383-1390. |
[2] | 杨先凤, 赵家和, 李自强. 融合字注释的文本分类模型[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1317-1323. |
[3] | 王利娥, 李小聪, 刘红翼. 融合知识图谱和差分隐私的新闻推荐方法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1339-1346. |
[4] | 陈学勤, 陶涛, 张钟旺, 王一蕾. 融合成对编码方案及二维卷积神经网络的长短期会话推荐算法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1347-1354. |
[5] | 谢新林, 肖毅, 续欣莹. 基于神经网络架构搜索的肺结节分类算法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1424-1430. |
[6] | 陈代丽, 许国良. 基于注意力机制学习域内变化的跨域行人重识别方法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1391-1397. |
[7] | 庄屹, 赵海涛. 面向三维点云单目标跟踪的提案聚合网络[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1407-1416. |
[8] | 屈震, 李堃婷, 冯志玺. 基于有效通道注意力的遥感图像场景分类[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1431-1439. |
[9] | 李默, 芦天亮, 谢子恒. 基于代码图像合成的Android恶意软件家族分类方法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1490-1499. |
[10] | 王艺霏, 于雷, 滕飞, 宋佳玉, 袁玥. 基于长-短时序特征融合的资源负载预测模型[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1508-1515. |
[11] | 张晔, 刘蓉, 刘明, 陈明. 基于多通道注意力机制的图像超分辨率重建网络[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1563-1569. |
[12] | 邱永茹, 姚光乐, 冯杰, 崔昊宇. 基于半监督学习的单幅图像去雨算法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1577-1582. |
[13] | 胡鹤轩, 隋华超, 胡强, 张晔, 胡震云, 马能武. 基于图注意力网络与双阶注意力机制的径流预报模型[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1607-1615. |
[14] | 鲁永帅, 唐英杰, 马鑫然. 基于深度特征融合的无纺布低对比度浆丝缺陷检测方法[J]. 《计算机应用》唯一官方网站, 2022, 42(5): 1440-1446. |
[15] | 陈浩杰, 范江亭, 刘勇. 深度强化学习解决动态旅行商问题[J]. 《计算机应用》唯一官方网站, 2022, 42(4): 1194-1200. |
阅读次数 | ||||||
全文 |
|
|||||
摘要 |
|
|||||