Xtract is an IntelliJ IDEA plugin that recommends Extract Method refactorings using Pre-trained Language Models(PLM), Explainable AI (XAI), and Large Language Models (LLMs).
Unlike traditional recommendation tools that only identify potential refactoring opportunities, Xtract provides complete recommendations following the W3B criterion (Which, Where, Why, and Benefits).
- Overview
- Features
- Demonstration
- Architecture
- Installation & Setup
- Citation
- License
Software systems continuously evolve, increasing their structural complexity and making refactoring an essential activity for maintaining software quality.
Although several automated refactoring recommendation tools have been proposed, most of them generate incomplete recommendations, making it difficult for developers to understand, trust, and adopt the suggested refactorings.
Xtract addresses this problem by combining Machine Learning, Explainable Artificial Intelligence, and Large Language Models to recommend Extract Method refactorings directly inside IntelliJ IDEA.
The recommendation follows the W3B criterion, informing developers:
✔ Which refactoring should be applied
✔ Where it should be applied
✔ Why it is recommended
✔ Which benefits are expected
Note The current plugin interface displays the Which, Where and Why dimensions. The Benefits dimension is already supported by the recommendation engine but is not yet exposed in the graphical interface.
- IntelliJ IDEA plugin fully integrated into the IDE.
- Automatic recommendation of Extract Method refactorings.
- Method classification using a trained Random Forest model.
- Candidate fragment ranking using a fine-tuned CodeBERT model.
- Explainable predictions based on Explainable AI (XAI).
- Consensus-based explanation generated from multiple explanation techniques.
- Natural language explanations generated using GPT.
- Recommendations organized according to the W3B criterion.
A demonstration video showing the execution and recommendation process of Xtract is available on Zenodo.
🎥 Demonstration Video
https://doi.org/10.5281/zenodo.21459888
The video illustrates:
- Selection of a Java method;
- Execution of the recommendation process;
- Visualization of the recommended code fragment;
- Refactoring Recommendation generated by Xtract.
The architecture of Xtract is organized into three modular layers that separate user interaction, recommendation generation, and natural language explanation.
The User Interface layer integrates Xtract into IntelliJ IDEA, allowing developers to request recommendations directly from the IDE. The Recommendation Engine orchestrates the recommendation process by extracting software metrics, identifying candidate fragments, applying Machine Learning models, and generating explainable predictions. Finally, the LLM-based Explanation Service synthesizes the outputs of previous stages into natural language recommendations following the W3B criterion.
Before running Xtract, make sure the following software is installed:
- Java 21
- IntelliJ IDEA Community 2025.1
- Gradle
- Git
bash git clone https://github.com/Advanse-Lab/xtract-plugin-intellij.git cd xtract-plugin-intellij
At the current development stage, Xtract is executed directly from the IntelliJ IDEA development environment using the IntelliJ Platform SDK.
To run the plugin:
- Open the project in IntelliJ IDEA.
- Allow Gradle to import the project dependencies.
- Wait until indexing is complete.
- Run the IntelliJ Plugin configuration (typically Run Plugin or runIde).
- A new IntelliJ IDEA instance will be launched with the Xtract plugin installed.
Note
Future releases will provide a packaged plugin that can be installed directly through IntelliJ IDEA without requiring the development environment.
After launching the IntelliJ instance:
- Open a Java project.
- Select the method to be analyzed.
- Right-click on the selected method.
- Choose Analysis for Refactoring Opportunities.
- Select Extract Method.
- Review the recommendation generated by Xtract.
This project is licensed under the MIT License.
See the LICENSE file for complete license information.
