We present a Live Refactoring Environment that helps software developers improve the quality of their software systems by identifying, suggesting, and applying several refactorings in real-time. This tool supports the following refactorings:
- Extract Method: It allows to extract code from a very long method into a new, more straightforward, and more understandable method;
- Extract Class: It allows to filter classes whose methods share more similarities and transform them into new classes;
- Extract Variable: It allows to find non-void calls that should be later extracted to a new variable;
- Move Method: It allows to move a new method to the class that uses that method the most, and turn the code of the original method into a reference to the new method in the other class;
- Introduce Parameter Object: It allows to replace a repeating group of parameters with an object;
- Replace Inheritance with Delegation: It allows to create a field and put a superclass object in it, delegating methods to the superclass object, and getting rid of the inheritance;
- String Comparison: It allows to replace the ``=='' operator, when comparing strings, with method equals().
This refactoring environment was developed for Java code on the IntelliJ IDE, and it focuses on analyzing specific quality attributes to detect particular code smells, such as the Long Method, Duplicated Code, or Long Classes. By identifying different smells, this environment selects and applies possible refactoring methods capable of mitigating each smell.
At the moment, the code quality metrics considered by our tool are:
File Metrics | Class Metrics | Method Metrics |
---|---|---|
Number of Lines of Code, Number of Comments, Number of Classes, Number of Methods, Average Number of Long Methods, Average Lack of Cohesion, Average Cyclomatic Complexity | Number of Fields, Number of Public Fields, Number of Methods, Number of Long Methods, Class Lack of Cohesion, Average Cyclomatic Complexity | Number of Parameters, Number of Lines of Code, Number of Comments, Number of Statements, Method Lack of Cohesion, Cyclomatic Complexity, Halstead Complexity Metrics, Maintainability Degree |
To use this tool, we need to install it on IntelliJ IDE by following the next steps:
- Launch the IntelliJ IDE;
- Select your IDE's preferences. There you will find the “Plugins” menu;
- Select the option of “Install Plugin from Disk” (see the following image);
- Search the folder where you place the plugin distribution and select its .zip folder depending of your IntelliJ IDE version (LiveRef-2021.zip or LiveRef-2022.zip);
- Then, IntelliJ will install the plugin.
- There is a menu on the top bar called “Live Refactoring”. In this menu, there are several options;
- To start the analysis of the code open in the text editor, users need to select the option “Start Analysis”;
- After the analysis starts, the possible refactorings are shown in the text editor. These are painted with different colors within a range between green and red. Green represents code that doesn’t need to be immediately refactored, and red represents code with less quality that should be refactored as soon as possible;
- By selecting a color in a given line of code, users have access to a menu called “Refactoring Menu”, which shows all the refactorings related to that line of code. The color presented next to the code is the color of the worst refactoring found on that line. In this menu, the user can verify all the refactorings in descending order of severity and check all the lines of code associated with it;
- Then, if users want to perform a refactoring, they need to select the respective refactoring and click on the “Refactor” button on that menu;
- After this action, the refactoring is automatically applied to the code, and the tool starts a new analysis.
- The tool will start automatically after opening a project. But, you can stop/start it using the “Live Refactoring” menu;
- After the analysis starts, the possible refactorings are shown in the text editor. These are painted with different colors within a range between green and red. Green represents code that doesn’t need to be immediately refactored, and red represents code with less quality that should be refactored as soon as possible;
- By selecting a color in a given line of code, users have access to a menu called “Refactoring Menu”, which shows all the refactorings related to that line of code. The color presented next to the code is the color of the worst refactoring found on that line. In this menu, the user can verify all the refactorings in descending order of severity and check all the lines of code associated with it;
- Then, if users want to perform a refactoring, they need to select the respective refactoring and click on the “Refactor” button on that menu;
- After this action, the refactoring is automatically applied to the code, and the tool starts a new analysis.
Here you can find a demonstration video that summarizes the main actions of this tool.
-
Folder LiveRefactoring contains the source code of our Live Refactoring Environment for IntelliJ IDE 2021 or any other older version;
-
Folder LiveRefactoring-2022 contains the source code of our Live Refactoring Environment for IntelliJ IDE 2022;
-
Folder Experiments contains the main artifacts used by the participants of our empirical experiments and the main results collected from them.