Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify the IntelliJ getter and setter code generation?

In IntelliJ you can generate getter and setter methods for your Java class fields. The problem I have is that by our code conventions private fields need to start with an underscore, for example:

private String _name;

IntelliJ will generated 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

like image 587
Milen Kovachev Avatar asked Dec 07 '15 16:12

Milen Kovachev


1 Answers

Open IntelliJ Preferences (Command + , on Mac).

Navigate through:

Editor
-- Code Style
---- Java

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

enter image description here

like image 95
David V Avatar answered Sep 20 '22 19:09

David V