Christopher Perry
Christopher Perry

Reputation: 39225

Variable naming code style in IntelliJ

I'm poking through the Code Style settings for Java in IntelliJ, looking for a way to specify variable naming conventions, and don't see anything. For instance, I have a requirement that all my class member variables start with m (I don't like this convention, but that's another issue), for example:

private final String mName;

vs

private final String name;

I want to run the formatter on existing files and have the variables reformat automatically. Is there a way to do this in IntelliJ? I see something for code generation, but nothing to reformat existing code. I've been Googling and looking through Settings and can't find anything.

Upvotes: 23

Views: 4867

Answers (1)

CrazyCoder
CrazyCoder

Reputation: 401975

You can only configure it for the new code that you will write:

prefix

This setting will affect refactorings like introduce field, getters and setters generation, etc.

Reformatting code doesn't rename the variables.

There is an inspection that will help you to find all such fields, but it will not rename them automatically: Instance field naming convention.

Probably SSR can help in this case.

Upvotes: 32

Related Questions