Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put Space Between Auto-Generated Getters / Setters in Eclipse

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?

like image 892
Baxter Avatar asked May 02 '12 15:05

Baxter


People also ask

How do you create getters and setters in Eclipse?

Select "Javadoc -> Generate Getter/Setter Javadocs from Field Javadocs..." in the main menu of Eclipse or the context menu of the editor, and a dialog opens. The shortcut key is Ctrl+Shift+D. In the dialog select getters and setters for which you want to generate Javadocs and click "OK" button.

Can getter setter be static?

You can't make getter and setter methods static if you use any attributes or properties that aren't static.

Where do you put getters and setters?

The Java coding convention states that methods (getters and setters are methods) should be after constructors declarations. It just a convention and it exists to make code easier to read in general.


Video Answer


2 Answers

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.

like image 53
Gilbert Le Blanc Avatar answered Oct 02 '22 16:10

Gilbert Le Blanc


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

like image 44
Markus Pscheidt Avatar answered Oct 02 '22 14:10

Markus Pscheidt