Excessively long methods, loaded with multiple responsibilities, are challenging to understand, debug, reuse, and maintain. The solution lies in the widely recognized Extract Method refactoring. While the application of this refactoring is supported in modern IDEs, recommending which code fragments to extract has been the topic of many research tools. However, they often struggle to replicate real-world developer practices, resulting in recommendations that do not align with what a human developer would do in real life. To address this issue, we introduce EM-Assist, an IntelliJ IDEA plugin that uses LLMs to generate refactoring suggestions and subsequently validates, enhances, and ranks them. Finally, EM-Assist uses the IntelliJ IDE to apply the user-selected recommendation. In our extensive evaluation of 1,752 real-world refactorings that actually took place in open-source projects, EM-Assist's recall rate was 53.4% among its top-5 recommendations, compared to 39.4% for the previous best-in-class tool that relies solely on static analysis. Moreover, we conducted a usability survey with 18 industrial developers and 94.4% gave a positive rating.
翻译:过长的方法体承载多重职责,会导致代码难以理解、调试、复用和维护。业界公认的解决方案是广泛采用的提取方法重构。虽然现代集成开发环境已支持该重构操作,但如何推荐待提取的代码片段始终是众多研究工具的核心课题。现有工具往往难以复现实践中的开发者行为模式,导致生成的推荐方案与人类开发者的实际实践存在偏差。为解决这一问题,我们提出EM-Assist——一款基于大语言模型生成重构建议,并对其进行验证、优化与排序的IntelliJ IDEA插件。最终,该插件通过IntelliJ集成开发环境执行用户选定的重构方案。在对开源项目中实际发生的1,752次重构案例进行大规模评估后,EM-Assist在前五项推荐中的召回率达到53.4%,而此前仅依赖静态分析的最佳工具仅达到39.4%。此外,我们对18位工业界开发者开展的可用性调查显示,94.4%的参与者给出了积极评价。