views:

117

answers:

3

How can you get IntelliJ to generate getter/setters on one line like this:

public String getAbc() { return abc; }

Instead of

public String getAbc() {
   return abc;
}

??

+3  A: 

You didn't mention what version of IDEA you are using, so I assume the recent 8 or 9.

Check your Code Style settings, under "Alignment and Braces". You should find a "Simple methods in one line" option there.

Noel Ang
We're 8.1.3. That didn't seem to work though..
Marcus
Did you try unchecking the related "Line breaks" box in the "Keep When Reformatting" group?
seh
The one-line setting tells IntelliJ to leave it that way on a reformat, but not to create it that way.
Chris Kessel
+3  A: 

There are no templates neither for getters nor for equals/hashcode. These are hardcoded in IDEA.

Source

EDIT:

You can see that in this IntelliJ Wishlist

davidrobles
A: 

I don't know why you want to do this, presumably for saving visual space. If so, just use IntelliJ's feature to fold trivial getters/setters and forget about how lines does it take. Folding feature can be found in

Settings -> IDE Settings -> Editor -> Code Folding -> Show code folding outline -> Simple property accessors

mindas