13

I am using Eclipse EE IDE - Indigo. I filled in all my class variables and then right click on the page and select -> Source -> Generate Getters and Setters. This works fine but it puts the methods right on top of each other ex:

public String getValue1() {  
    return value1;  
}  
public void setValue1(String value1) {  
    $this.value1 = value1  
}  
public String getValue2() {  
    return value2;  
}  
public void setValue2(String value2) {  
    $this.value2 = value2
}  

Is there any way to tell Eclipse to put a space between the methods when auto-generating?

Baxter
  • 5,633
  • 24
  • 69
  • 105

4 Answers4

19

After the getters and setters have been created, select the newly created methods and "format" the code (Ctrl+Shift+F).

Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
8

Empty line between generated getter/setter method is depending on presence of empty line between properties itselt.

So if I select this :


    private int foo;
    private int bar;

there will be no space between getters/setters, but if I select this :


    private int foo;

    private int bar;

there will be one empty line between methods.

apocalypz
  • 1,180
  • 1
  • 8
  • 11
  • I find it very odd that Eclipse assumes a relation between empty lines in my fields any empty lines in my getters/setters. While I **always** want an empty line between methods, I don't necessarily want it between fields. – bkis Jun 03 '20 at 09:31
4

Let's say you have fields like this:

private int first;
private int second;
private int third;

If you are going to add your getters and setters after the third field, leave a space between second and third fields, like this:

private int first;
private int second;

private int third;

Now you are good to go. Generate it and then remove the empty line you added.

3

Yes. I tried this on Eclipse 3.7. It's a bit clunky, but it works.

  • Generate one getter or setter method using the right click option Source -> Generate Getters and Setters.

  • Manually add two blank lines after the method.

  • On the second blank line, use the right click option Source -> Generate Getters and Setters to generate the rest of the getters and setters.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111