How can I change the code generation of getter and setter IntelliJ?

In IntelliJ, you can generate getter and setter methods for fields in a Java class. The problem is that in our code conventions, private fields must begin with an underscore, for example:

private String _name; 

IntelliJ will generate the following getter and setter methods for this field:

 public String get_reportName() { return _reportName; } public void set_reportName(String _reportName) { this._reportName = _reportName; } 

I would like it to rather generate:

 public String getReportName() { return _reportName; } public void setReportName(String reportName) { _reportName = reportName; } 

Can I somehow customize the generation code to achieve this?

thanks

+5
source share
1 answer

Open IntelliJ settings (Command +, on Mac).

Go through:

 Editor -- Code Style ---- Java 

Select the Code Generation tab. In the Name prefix: section Name prefix: place an underscore in the Field: text box. Now this should work for you. (At least in IntelliJ 15, where I experienced it).

enter image description here

+10
source

Source: https://habr.com/ru/post/1237587/


All Articles