引用本文:徐子懋,姜艳杰,张宇霞,刘辉.基于大语言模型的长方法分解.软件学报,2025,36(6):2501-2514
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览 2140次   下载 2497 本文二维码信息
码上扫一扫!
分享到: 微信 更多
基于大语言模型的长方法分解
徐子懋1, 姜艳杰2, 张宇霞1, 刘辉1
1.北京理工大学 计算机学院, 北京 100081;2.北京大学 计算机学院, 北京 100871
摘要:
长方法及其他类型的代码坏味阻碍了软件应用程序达到最佳的可读性、可重用性和可维护性. 因此, 人们对长方法的自动检测和分解进行了广泛的研究. 虽然这些方法极大地促进了分解, 但其解决方案往往与最优方案存在很大差异. 为此, 调研公开真实长方法数据集中的可自动化部分, 探讨了长方法的分解情况, 并基于调研结果, 提出了一种基于大语言模型的新方法(称为 Lsplitter), 用于自动分解长方法. 对于给定的长方法, Lsplitter会根据启发式规则和大语言模型将该方法分解为一系列短方法. 然而, 大语言模型经常会拆分出相似的方法, 针对大语言模型的分解结果, Lsplitter利用基于位置的算法, 将物理上连续且高度相似的方法合并成一个较长的方法. 最后对这些候选结果进行排序. 对真实Java项目中的2849个长方法进行了实验, 结果表明, 相较传统结合模块化矩阵的方法, Lsplitter的命中率提升了142%, 相较纯基于大语言模型的方法, 命中率提升了7.6%.
关键词:  长方法  重构  大语言模型  分解
DOI:10.13328/j.cnki.jos.007329
分类号:
基金项目:国家自然科学基金(62172037, 62232003); 中国博士后科学基金(2023M740078)
Large-language-model-based Decomposition of Long Methods
XU Zi-Mao1, JIANG Yan-Jie2, ZHANG Yu-Xia1, LIU Hui1
1.School of Computer Science and Technology, Beijing Institute of Technology, Beijing 100081, China;2.School of Computer Science, Peking University, Beijing 100871, China
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%.
Key words:  long method  refactoring  LLM  decomposition

引用本文:
【打印本页】   【下载PDF全文】   查看/发表评论  【EndNote】   【RefMan】   【BibTex】
←前一篇|后一篇→ 过刊浏览    高级检索
本文已被:浏览次   下载  
分享到: 微信 更多
摘要:
关键词:  
DOI:
分类号:
基金项目:
Abstract:
Key words: