利用LLM、IDE和语义嵌入实现自动化Move Method重构
Leveraging LLMs, IDEs, and Semantic Embeddings for Automated Move Method Refactoring
AI总结:
针对Move Method重构,提出MM-assist助手,结合LLM、IDE静态分析和语义嵌入,通过RAG和自一致性过滤幻觉,显著提升推荐准确率并获用户好评。
摘要:
MOVEMETHOD是一种标志性的重构。尽管有大量的研究工具推荐应该移动哪些方法以及移动到哪里,但这些推荐与专家开发者执行MOVEMETHOD的方式并不一致。鉴于大型语言模型(LLM)的广泛训练及其对代码自然性的依赖,它们应该能够专业地推荐在给定类中哪些方法被放错了位置,以及哪些类是更好的宿主。我们对2016年LLM推荐的形成性研究表明,LLM能给出专家级建议,但它们并不可靠:高达80%的建议是幻觉。我们引入了第一个完全由LLM驱动的MOVEMETHOD重构助手,它自动化了从推荐到执行的整个端到端生命周期。我们设计了新颖的解决方案,利用IDE的静态分析自动过滤LLM幻觉,并设计了一种新颖的工作流程,要求LLM自我一致、批判并排序重构建议。由于MOVEMETHOD重构需要全局性的、项目级别的推理,我们通过采用重构感知的检索增强生成(RAG)解决了LLM上下文大小有限的问题。我们的方法MM-assist协同结合了LLM、IDE、静态分析和语义相关性的优势。在我们全面的、多方法论的实证评估中,我们将MM-assist与之前最先进的方法进行了比较。MM-assist显著优于它们:(i)在其他研究人员广泛使用的基准上,我们的Recall@1和Recall@3提高了1.7倍;(ii)在来自开源软件的210个近期重构的语料库上,我们的召回率提高了至少2.4倍。最后,我们进行了一项用户研究,有30位经验丰富的参与者使用MM-assist重构他们自己的代码一周。他们对MM-assist的82.8%的推荐给予了积极评价。这表明MM-assist既有效又有用。
英文摘要:
MOVEMETHOD is a hallmark refactoring. Despite a plethora of research tools that recommend which methods to move and where, these recommendations do not align with how expert developers perform MOVEMETHOD. Given the extensive training of Large Language Models and their reliance upon naturalness of code, they should expertly recommend which methods are misplaced in a given class and which classes are better hosts. Our formative study of 2016 LLM recommendations revealed that LLMs give expert suggestions, yet they are unreliable: up to 80% of the suggestions are hallucinations. We introduce the first LLM fully powered assistant for MOVEMETHOD refactoring that automates its whole end-to-end lifecycle, from recommendation to execution. We designed novel solutions that automatically filter LLM hallucinations using static analysis from IDEs and a novel workflow that requires LLMs to be self-consistent, critique, and rank refactoring suggestions. As MOVEMETHOD refactoring requires global, projectlevel reasoning, we solved the limited context size of LLMs by employing refactoring-aware retrieval augment generation (RAG). Our approach, MM-assist, synergistically combines the strengths of the LLM, IDE, static analysis, and semantic relevance. In our thorough, multi-methodology empirical evaluation, we compare MM-assist with the previous state-of-the-art approaches. MM-assist significantly outperforms them: (i) on a benchmark widely used by other researchers, our Recall@1 and Recall@3 show a 1.7x improvement; (ii) on a corpus of 210 recent refactorings from Open-source software, our Recall rates improve by at least 2.4x. Lastly, we conducted a user study with 30 experienced participants who used MM-assist to refactor their own code for one week. They rated 82.8% of MM-assist recommendations positively. This shows that MM-assist is both effective and useful.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。