Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable naming code style in IntelliJ

Tags:

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.

like image 463
Christopher Perry Avatar asked Apr 03 '13 18:04

Christopher Perry


People also ask

How do I add code style to IntelliJ?

Apply a predefined code stylePress Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. To configure a scheme for new projects, go to File | New Projects Setup | Settings/Preferences for New Projects | Editor | Code Style. Select the language for which you want to configure the code style.

How do I fix code style in IntelliJ?

In the editor, select a code fragment you want to reformat. Before reformatting, you can take a look at the code style settings that are applied to the selected code: press Alt+Enter and click Adjust code style settings. From the main menu, select Code | Reformat Code or press Ctrl+Alt+L .

What is IntelliJ code style?

Code style scheme settings are automatically applied every time IntelliJ IDEA generates, refactors, or reformats your code. The IDE comes with two pre-defined schemes: the Project scheme and the Default scheme. In the Project scheme, the settings that you configure apply only to your current project.


1 Answers

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.

like image 149
CrazyCoder Avatar answered Sep 19 '22 20:09

CrazyCoder