Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java coding style in Eclipse

Tags:

java

eclipse

For each method, I want to add a space between the method name and the right curly bracket. For example,

public void setName(String name) {
}

I want a space between ) and {. Is it possible to automatically set this in Eclipse or somewhere? It's annoying to add this space every time.

like image 834
user697911 Avatar asked May 12 '17 21:05

user697911


People also ask

How can I get beautify code in Eclipse?

Go to Source | Format Document or press Ctrl+Shift+F.

How do I use code formatter XML in Eclipse?

All you need is to export settings from Eclipse (go to Eclipse's Preferences → Java → Code Style → Formatter and export the settings to an XML file via the Export All button.), and then open IntelliJ IDEA Settings → Code Style → Java, click Manage, and import that XML file by simply clicking Import.

How do I turn off code formatting in Eclipse?

To change these settings, use Window -> Preferences -> Java -> Code Style -> Formatter. On the last tab of the formatter, you can define on/off tags which allow to you to prevent reformatting of some code.


2 Answers

in eclipse menu-->Windows-->preferences, search for the formatter, then edit then set the checkbox: insert space before opening brace

enter image description here


enter image description here

like image 79
ΦXocę 웃 Пepeúpa ツ Avatar answered Oct 09 '22 15:10

ΦXocę 웃 Пepeúpa ツ


Default code style will add space where you want it, and it can be autoformatted on every save:

Window->Preferences->Java->Editor->SaveActions: check "Format source code"

In case you want to change some of the default styles, you can do so if you navigate to formatter and edit active profile there:

Save Actions

like image 23
z m Avatar answered Oct 09 '22 16:10

z m