Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I modify Eclipse code formatting?

When I reformat code with Eclipse, it turns method headers like this:

public void myMethod(String param) {

into method headers like this:

public void myMethod(
                     String param) {

When I was brought on here I'd never used Eclipse before, and I imported project settings provided by someone else. I have seen that on small new projects I've worked on Eclipse does not do this, so it must be in the settings I've imported. But I've gone through every panel I can find, as well as every hidden file I can find in the workspace, and I can't figure out what is causing this.

How do I turn it off? I don't want a newline before parameters in my method signatures, and I can't imagine why anyone would!

like image 628
skiphoppy Avatar asked Oct 21 '09 15:10

skiphoppy


People also ask

How do I format all in Eclipse?

Show activity on this post. In older versions of Eclipse (Indigo) it works from Package Explorer (not Navigator). Right click the package you wish to format then choose Source -> Format. It will format all classes in that package and its sub-packages.

How do I change the format code in Eclipse?

Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.


4 Answers

Have a look at Window>Preferences>Java>Code Style>Formatter.

There you can configure almost everything. Your case is found at

Line Wrapping>Method Declarations>Parameters.

like image 97
tangens Avatar answered Oct 17 '22 15:10

tangens


In my version of Eclipse, I found the option under Window->Preferences->Java->Code Style->Formatter, then clicked the Edit.. button.

In the new window, go to the Line Wrapping tab and find Method Declarations. You want to change the Line wrapping policy. The Force split check box seems to do the same.

like image 27
Colin Gislason Avatar answered Oct 17 '22 14:10

Colin Gislason


Go into preferences: Java -> Code Style -> Formatter

Restore Defaults or edit what's there.

Additionally, Code Style -> Code Templates will allow you to define generate code formatting.

Note that this is for Eclipse Workspace as a whole, the same Preferences can be accessed under the project preferences if you want to get more fine grained at a per project level.

like image 42
MarkPowell Avatar answered Oct 17 '22 16:10

MarkPowell


In eclipse you can define your code formatting use Code Style ,

for MAC System :--> Eclipse --> Preference -- > java--> code Style

for Window System :--> Window->Preferences->Java->Code Style->Formatter

like image 20
Imran khan Avatar answered Oct 17 '22 14:10

Imran khan