Abstract
Refactoring is a common software engineering practice that improves code quality without altering program behavior. Although tools like ReExtractor+, RefactoringMiner, and RefDiff have been developed to detect refactorings automatically, they rely on complex rule definitions and static analysis, making them difficult to extend and generalize to other programming languages. In this paper, we investigate the viability of using foundation models for refactoring detection, implemented in a tool named RefModel. We evaluate Phi4-14B, and Claude 3.5 Sonnet on a dataset of 858 single-operation transformations applied to artificially generated Java programs, covering widely-used refactoring types. We also extend our evaluation by including Gemini 2.5 Pro and o4-minihigh, assessing their performance on 44 real-world refactorings extracted from four open-source projects. These models are compared against RefactoringMiner, RefDiff, and ReExtractor+. RefModel is competitive with, and in some cases outperform, traditional tools. In real-world settings, Claude 3.5 Sonnet and Gemini 2.5 Pro jointly identified 97% of all refactorings, surpassing the best-performing static-analysis-based tools. The models showed encouraging generalization to Python and Golang. They provide natural language explanations and require only a single sentence to define each refactoring type.
Introduction
Refactoring—the process of improving code structure without changing its external behavior—is a cornerstone of software maintenance. To track these changes, developers have traditionally relied on tools like RefactoringMiner or RefDiff. However, these industry-standard tools are "rule-heavy," relying on complex Abstract Syntax Tree (AST) matching and manual definitions that are difficult to write, maintain, and port to new programming languages.
This paper explores a shift in how we detect code refactorings: moving away from rigid, hand-crafted rules toward the flexible reasoning of Large Language Models (LLMs). The researchers introduced RefModel, a framework that treats refactoring detection as a classification and explanation task for foundation models. The central question is whether thousands of lines of complex static analysis logic can be replaced with simple natural language prompts.
Methodology: Natural Language as Specification
The core innovation of RefModel is its use of foundation models to "understand" code intent. Instead of hard-coded rules, the model is provided with the "before" and "after" versions of a code snippet (or a git diff) and a list of refactoring types defined in plain English.
To ensure precision, the researchers employed a metaprompting strategy, using OpenAI’s o4-mini-high to refine and optimize the instructions given to other models. This approach makes adding support for a new refactoring type trivial, as it requires only a single sentence of English rather than hundreds of lines of AST-matching code.
Experimental Design
The study evaluated a range of models, including Microsoft’s Phi4-14B (run locally), Anthropic’s Claude 3.5 Sonnet, Google’s Gemini 2.5 Pro, and OpenAI’s o4-mini-high. These were benchmarked against three distinct datasets:
- Synthetic Java Dataset: 858 single-operation transformations generated using JDolly and Eclipse JDT to test 10 common refactoring types in a controlled environment.
- Real-World Java Dataset: 44 refactorings manually extracted from five prominent open-source projects, including Spring Boot and Apache Gobblin.
- Cross-Language Dataset: 20 transformations in Python and Golang to test the models' ability to generalize beyond Java without specialized training.
Key Results
RefModel demonstrated performance that is competitive with, and in many cases superior to, traditional static analysis tools. The results suggest that LLMs offer a more scalable and language-agnostic way to detect refactorings.
Key findings include:
- Superior Recall: In real-world Java projects, Gemini 2.5 Pro and o4-mini-high both reached 93.8% recall, outperforming the best traditional tool, RefactoringMiner (88.6%). When used together, Claude 3.5 Sonnet and Gemini 2.5 Pro correctly identified 97% of all refactorings.
- Zero-Shot Generalization: In Python and Golang tests, Gemini 2.5 Pro detected 100% of refactorings, while Phi4-14B reached 80%. Traditional tools often require years of development to support new languages to this degree.
- Viability of Small Models: Even the 14-billion parameter Phi4 model achieved a respectable ~79% recall, suggesting that refactoring detection can be performed locally on standard hardware.
Discussion and Limitations
Despite the high recall, the study identified a "Context Achilles' Heel." Models occasionally struggle when a refactoring depends on information outside the provided code snippet. For example, if a method is "Pulled Up" to a parent class that is not included in the diff, the model might misclassify it as a simple "Move Method."
Furthermore, while recall was high, precision was lower for some models (Phi4 at 56.4% on synthetic data) because they occasionally hallucinated refactoring names or struggled with subtle naming conflicts. Future work involves using Retrieval-Augmented Generation (RAG) to feed the model relevant parts of the codebase that aren't in the immediate diff.
Conclusion
RefModel represents a significant step toward language-agnostic refactoring detection. By leveraging the reasoning capabilities of foundation models, developers can achieve high detection accuracy with minimal manual configuration. While traditional tools remain faster for specific, well-defined tasks, the flexibility and explanatory power of LLMs provide a powerful new tool for code review and software evolution analysis.
Summary updated