How to stop IDEA from reformatting my code when refactoring?

When refactoring code (ex: Refactor -> Rename), IntelliJ IDEA 14.x also repackages (reformatts) my code to fit into the 80-column limit.

Example: here is the code before refactoring: enter image description here

Refactoring: enter image description here

... and the code is wrapped again after pressing Enter : enter image description here

What's most annoying in this regard, even Java classes that are not currently open in the editor (but refactored) are reformatted, which increases the likelihood that formatting changes will be immediately propagated in my VCS.

What I want to achieve:

  • keep the original print size in 80 columns, but still
  • IDEA retains the original formatting when renaming variables / classes / methods.

How do I achieve this?

+7
java intellij-idea intellij-14
source share
2 answers

Since I do not use automatic formatting and basically wrap my long lines manually, I figured out another solution.

In the section “File → Settings → Editor → Code Style → Java → Wrapper and Brackets” I completely turned off automatic packaging (that is, set everything to “Do not wrap” if necessary, except for the class, method and field annotations, which are set to "Wrap always" by default).

The disadvantage of this approach is that now IDEA sometimes unwraps long lines during refactoring, but this is easier to define.

0
source share

If you perform the actual “Refactoring → Rename”, for example, using SHIFT + F6 , you edit every file that has a link to this variable name , regardless of whether they are currently open, the editor doesn’t matter if you change then, all edited files are edited, and any VCS will consider their changes.

The reformatting behavior of the entire file during refactoring was in Idea for a long time, and all errors that were filed against this behavior were constantly fixed in an unassigned state. Here is one example .

I doubt that this behavior will change; I hope that this is not so.

If you want ridiculously long variable names, you need to either turn off the right margin or make it ridiculously long. Or change any configuration, as a result of which things will be formatted differently.

Personally, I asked all the relevant ALWAYS things so that I do not have something formatted in one direction, but something formatted in a different way. Consistency is most important in a large code base.

Idea's VCS tools are extremely powerful and unmatched in any other IDE. You can easily see what has changed and exclude them from any commits or fix them as you want.

The idea has a checkbox for commit for all supported version control systems.

0
source share

All Articles