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, when using a synthetic corpus used by other researchers, EM-Assist consistently suggests the correct refactoring among its top-5 recommendations, achieving a 60.6% recall rate, surpassing existing tools with a 52.2% recall rate. When replicating 1,615 real-world refactorings that actually took place in open-source projects, EM-Assist’s recall rate was 48.9%, compared to 23.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.

The source code, datasets, and distribution of the plugin are available on GitHub (https://github.com/llm-refactoring/llm-refactoring-plugin). The plugin is available to install on JetBrains Marketplace (https://plugins.jetbrains.com/plugin/23403-llm-powered-extract-method). A demonstration video and screencast is on YouTube (https://www.youtube.com/watch?v=3E6KsHAg3js).