Milen Kovachev
Milen Kovachev

Reputation: 5361

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

Upvotes: 7

Views: 3280

Answers (1)

David V
David V

Reputation: 11699

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

Upvotes: 14

Related Questions