Atomic refactoring in IntelliJ IDEA: Bending IDE to our will

Day 2 /  / Track 3  /  RU /

Software programming includes changing not only functionality of the program, but also its structure, keeping the semantics intact; this process is usually called refactoring. There's always a risk of actually changing the semantics during refactoring if the developer makes a mistake in the process. Further testing isn't always able to detect this regression in time. Besides, the developers are often afraid of such regression and so avoid using refactoring even in cases when it can be really useful.

But we can often divide the refactoring process into atomic steps, or transactions; after each step the semantics is saved. The smaller these steps, the shorter the "broken" condition of the program, the lesser is the possibility of an error. Sometimes the process can even be brought to perfection: each command you give to a development environment modifies the code, keeping the semantics intact. In this case the possibility of an error is practically reduced to zero.

We'll see via examples how to achieve this during the Java code refactoring in IntelliJ IDEA and how to make your environment do atomic refactoring if it resists.

Tagir Valeev

Tagir Valeev is a software developer in JetBrains s.r.o. Currently he improves support of Java features in IntelliJ IDEA developing new inspections and intention actions. Tagir is actively interested in static code analysis and when time permits, develops an open-source library called StreamEx which enhances standard Java 8 Stream API.