基于大语言模型的长方法分解
作者:
通讯作者:

姜艳杰,E-mail:yanjiejiang@pku.edu.cn

中图分类号:

TP311

基金项目:

国家自然科学基金(62172037, 62232003); 中国博士后科学基金(2023M740078)


Large Language Model-Based Decomposition of Long Methods
Author:
  • 摘要
  • | |
  • 访问统计
  • |
  • 参考文献 [39]
  • |
  • 相似文献 [20]
  • | | |
  • 文章评论
    摘要:

    长方法及其他类型的代码坏味阻碍了软件应用程序达到最佳的可读性、可重用性和可维护性. 因此, 人们对长方法的自动检测和分解进行了广泛的研究. 虽然这些方法极大地促进了分解, 但其解决方案往往与最优方案存在很大差异. 为此, 调研公开真实长方法数据集中的可自动化部分, 探讨了长方法的分解情况, 并基于调研结果, 提出了一种基于大语言模型的新方法(称为 Lsplitter), 用于自动分解长方法. 对于给定的长方法, Lsplitter会根据启发式规则和大语言模型将该方法分解为一系列短方法. 然而, 大语言模型经常会拆分出相似的方法, 针对大语言模型的分解结果, Lsplitter利用基于位置的算法, 将物理上连续且高度相似的方法合并成一个较长的方法. 最后对这些候选结果进行排序. 对真实Java项目中的2849个长方法进行了实验, 结果表明, 相较传统结合模块化矩阵的方法, Lsplitter的命中率提升了142%, 相较纯基于大语言模型的方法, 命中率提升了7.6%.

    Abstract:

    Long methods, along with other types of code smells, prevent software applications from reaching their optimal readability, reusability, and maintainability. Consequently, automated detection and decomposition of long methods have been widely studied. Although these approaches have significantly facilitated the decomposition, their solutions often differ significantly from the optimal ones. To address this, the automatable portion of the publicly available dataset containing real-world long methods is investigated. Based on the findings of this investigation, a new method (called Lsplitter) based on large language models (LLMs) is proposed in this study for automatically decomposing long methods. For a given long method, the Lsplitter decomposes the method into a series of shorter methods according to heuristic rules and LLMs. However, LLMs often split out similar methods. In response to the decomposition results of LLMs, Lsplitter utilizes a location-based algorithm to merge physically contiguous and highly similar methods into a longer method. Finally, these candidate results are ranked. Experiments are conducted on 2 849 long methods in real Java projects. The experimental results show that compared with the traditional methods combined with a modularity matrix, the hit rate of Lsplitter is improved by 142%, and compared with the methods purely based on LLMs, the hit rate is improved by 7.6%.

    参考文献
    [1] Fowler M, Beck K. Refactoring: Improving the Design of Existing Code. 2nd ed., Boston: Addison-Wesley Professional, 2018.
    [2] Chatzigeorgiou A, Manakos A. Investigating the evolution of code smells in object-oriented systems. Innovations in Systems and Software Engineering, 2014, 10(1): 3–18.
    [3] Danphitsanuphan P, Suwantada T. Code smell detecting tool and code smell-structure bug relationship. In: Proc. of the 2012 Spring Congress on Engineering and Technology. Xi’an: IEEE, 2012. 1–5. [doi: 10.1109/SCET.2012.6342082]
    [4] Hamza H, Counsell S, Hall T, Loizou G. Code smell eradication and associated refactoring. In: Proc. of the 2nd Conf. on European Computing Conf. Malta: WSEAS, 2008. 102–107.
    [5] Opdyke WF. Refactoring object-oriented frameworks [Ph.D. Thesis]. Champaign: University of Illinois at Urbana-Champaign, 1992.
    [6] Fowler M. Refactoring: Improving the Design of Existing Code. 2nd ed., Berkeley: Addison-Wesley Professional, 2018.
    [7] McConnell S. Code Complete: A Practical Handbook of Software Construction. 2nd ed., Redmond: Microsoft Press, 2004.
    [8] Haefliger S, von Krogh G, Spaeth S. Code reuse in open source software. Management Science, 2008, 54(1): 180–193.
    [9] Murphy-Hill E, Parnin C, Black AP. How we refactor, and how we know it. IEEE Trans. on Software Engineering, 2012, 38(1): 5–18.
    [10] Bazhenov IO, Lubkin IA. Methodology of software code decomposition analysis. In: Proc. of the 2018 Dynamics of Systems, Mechanisms and Machines. Omsk: IEEE, 2018. 1–5. [doi: 10.1109/Dynamics.2018.8601441]
    [11] Maruyama K. Automated method-extraction refactoring by using block-based slicing. In: Proc. of the 2001 Symp. on Software Reusability: Putting Software Reuse in Context. Toronto: ACM, 2001. 31–40. [doi: 10.1145/375212.375233]
    [12] Xu S, Sivaraman A, Khoo SC, Xu J. GEMS: An extract method refactoring recommender. In: Proc. of the 28th Int’l Symp. on Software Reliability Engineering. Toulouse: IEEE, 2017. 24–34. [doi: 10.1109/ISSRE.2017.35]
    [13] Shahidi M, Ashtiani M, Zakeri-Nasrabadi M. An automated extract method refactoring approach to correct the long method code smell. Journal of Systems and Software, 2022, 187: 111221.
    [14] Yamanaka J, Hayase Y, Amagasa T. Recommending extract method refactoring based on confidence of predicted method name. arXiv: 2108.11011, 2021.
    [15] Cui D, Wang QQ, Wang SQ, Chi JL, Li JN, Wang L, Li QS. REMS: Recommending extract method refactoring opportunities via multi-view representation of code property graph. In: Proc. of the 31st Int’l Conf. on Program Comprehension. Melbourne: IEEE, 2023. 191–202. [doi: 10.1109/ICPC58990.2023.00034]
    [16] Xu HR, Kim YJ, Sharaf A, Awadalla HH. A paradigm shift in machine translation: Boosting translation performance of large language models. In: Proc. of the 12th Int’l Conf. on Learning Representations. OpenReview.net, 2024.
    [17] Yao BW, Jiang M, Bobinac T, Yang DY, Hu JJ. Benchmarking machine translation with cultural awareness. In: Proc. of the Findings of the Association for Computational Linguistics. Miami: ACL, 2024. 13078–13096. [doi: 10.18653/v1/2024.findings-emnlp.765]
    [18] Shi YC, Ma HH, Zhong WL, Tan QY, Mai GC, Li X, Liu TM, Huang JZ. ChatGraph: Interpretable text classification by converting ChatGPT knowledge to graphs. In: Proc. of the 2023 IEEE Int’l Conf. on Data Mining Workshops. Shanghai: IEEE, 2023. 515–520. [doi: 10.1109/ICDMW60847.2023.00073]
    [19] Kurisinkel LJ, Chen NF. LLM based multi-document summarization exploiting main-event biased monotone submodular content extraction. arXiv: 2310.03414, 2023.
    [20] Liu C, Bao XL, Zhang HY, Zhang N, Hu HB, Zhang XH, Yan M. Improving ChatGPT prompt for code generation. arXiv: 2305.08360, 2023.
    [21] Ahmed T, Devanbu P. Few-shot training LLMs for project-specific code-summarization. In: Proc. of the 37th IEEE/ACM Int’l Conf. on Automated Software Engineering. Rochester: ACM, 2022. 177. [doi: 10.1145/3551349.3559555]
    [22] Sobania D, Briesch M, Hanna C, Petke J. An analysis of the automatic bug fixing performance of ChatGPT. In: Proc. of the 2023 IEEE/ACM Int’l Workshop on Automated Program Repair. Melbourne: IEEE, 2023. 23–30. [doi: 10.1109/APR59189.2023.00012]
    [23] Xia CS, Zhang LM. Automated program repair via conversation: Fixing 162 out of 337 bugs for $0.42 each using ChatGPT. In: Proc. of the 33rd ACM SIGSOFT Int’l Symp. on Software Testing and Analysis. Vienna: ACM, 2024. 819–831. [doi: 10.1145/3650212.3680323]
    [24] Yuan ZQ, Liu JW, Zi QC, Liu MW, Peng X, Lou YL. Evaluating instruction-tuned large language models on code comprehension and generation. arXiv:2308.01240, 2023.
    [25] Pomian D, Bellur A, Dilhara M, Kurbatova Z, Bogomolov E, Bryksin T, Dig D. Together we go further: LLMs and IDE static analysis for extract method refactoring. arXiv:2401.15298, 2024.
    [26] Chen XP, Hu X, Huang Y, et al. Deep learning-based software engineering: Progress, challenges, and opportunities. Science China Information Sciences, 2025, 68(1): 111102.
    [27] Fernandes S, Aguiar A, Restivo A. LiveRef: A tool for live refactoring Java code. In: Proc. of the 37th IEEE/ACM Int’l Conf. on Automated Software Engineering. Rochester: ACM, 2022. 161. [doi: 10.1145/3551349.3559532]
    [28] Tsantalis N, Chatzigeorgiou A. Identification of extract method refactoring opportunities for the decomposition of methods. Journal of Systems and Software, 2011, 84(10): 1757–1782.
    [29] Sharma T. Identifying extract-method refactoring candidates automatically. In: Proc. of the 5th Workshop on Refactoring Tools. Rapperswil: ACM, 2012. 50–53. [doi: 10.1145/2328876.2328883]
    [30] Silva D, Terra R, Valente MT. JExtract: An eclipse plug-in for recommending automated extract method refactorings. arXiv:1506.06086, 2015.
    [31] Marinescu R. Detection strategies: Metrics-based rules for detecting design flaws. In: Proc. of the 20th IEEE Int’l Conf. on Software Maintenance. Chicago: IEEE, 2004. 350–359. [doi: 10.1109/ICSM.2004.1357820]
    [32] Lanza M, Marinescu R. Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-oriented Systems. Berlin, Heidelberg: Springer, 2006. [doi: 10.1007/3-540-39538-5]
    [33] Moha N, Guéhéneuc YG, Duchien L, Le Meur AF. DECOR: A method for the specification and detection of code and design smells. IEEE Trans. on Software Engineering, 2010, 36(1): 20–36.
    [34] Yoshida N, Kinoshita M, Iida H. A cohesion metric approach to dividing source code into functional segments to improve maintainability. In: Proc. of the 16th European Conf. on Software Maintenance and Reengineering. Szeged: IEEE, 2012. 365–370. [doi: 10.1109/CSMR.2012.45]
    [35] Charalampidou S, Ampatzoglou A, Avgeriou P. Size and cohesion metrics as indicators of the long method bad smell: An empirical study. In: Proc. of the 11th Int’l Conf. on Predictive Models and Data Analytics in Software Engineering. Beijing: ACM, 2015. 8. [doi: 10.1145/2810146.2810155]
    [36] Charalampidou S, Arvanitou EM, Ampatzoglou A, Avgeriou P, Chatzigeorgiou A, Stamelos I. Structural quality metrics as indicators of the long method bad smell: An empirical study. In: Proc. of the 44th Euromicro Conf. on Software Engineering and Advanced Applications. Prague: IEEE, 2018. 234–238. [doi: 10.1109/SEAA.2018.00046]
    [37] Liu H, Jin JH, Xu ZF, Zou YZ, Bu YF, Zhang L. Deep learning based code smell detection. IEEE Trans. on Software Engineering, 2021, 47(9): 1811–1837.
    [38] Silva D, Tsantalis N, Valente MT. Why we refactor? confessions of GitHub contributors. In: Proc. of the 24th ACM SIGSOFT Int’l Symp. on Foundations of Software Engineering. Seattle: ACM, 2016. 858–870. [doi: 10.1145/2950290.2950305]
    [39] Cossette BE, Walker RJ. Seeking the ground truth: A retroactive study on the evolution and migration of software libraries. In: Proc. of the 20th Int’l Symp. on the Foundations of Software Engineering. Cary: ACM, 2012. 55. [doi: 10.1145/2393596.2393661]
    引证文献
    网友评论
    网友评论
    分享到微博
    发 布
引用本文

徐子懋,姜艳杰,张宇霞,刘辉.基于大语言模型的长方法分解.软件学报,2025,36(6):2501-2514

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

京公网安备 11040202500063号