*
The moose likes IDEs, Version Control and other tools and the fly likes Eclipse format settings: avoid joining manual set line-breaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Eclipse format settings: avoid joining manual set line-breaks" Watch "Eclipse format settings: avoid joining manual set line-breaks" New topic
Author

Eclipse format settings: avoid joining manual set line-breaks

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
hi,

is there a way inside eclipse to tell the auto-reformat to preserve linebreaks which are done on purpose (like IntelliJ)?

e.g. I often do linebreaks to make code better readable:



Annoying eclipse is now always reformatting the whole stuff to one line Is there a format setting to avoid this?

thanks


aldana software engineering blog & .more
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5811
    
    7

Yes you can do that. In the preference dialog, go to Java | Code Style | Formatter. (At this point I usually create my own Formatter based on the built-in one). Click the Edit button. The change things to your hearts content. You will probably want to make changes on both the New Lines and Line Wrapping tabs. And I suggest that after changing the formatting to what you want that you have the Formatter - then it will be easy to load your formatting preferences into an workspace, or to share with coworkers to ensure consist formatting in your project.


JBoss In Action
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
I already tried to play around with these settings, but it still does not preserve manual set linebreaks (inside function calls, method declarations etc.).

Eclipse only allows that it wraps itself automatically or that it removes the wrappings completely. Maybe you know the exact setting?

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5811
    
    7

Under Line Wrapping, select Method Declarations | Parameters, and choose "wrap all elements, except first element if not necessary" and "indent on column"


[Thumbnail for params.png]

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
thanks for the screenshot!

the thing is that i don't want always to wrap the parameters. if a function has only 2 parameters, i don't need any automatic wrap lines. it should be more on the developer, who decides which looks better readable. as far as i can see the settings eclipse goes brute force and does not leave the developer the freedom to decide.

to me this is not so bad because i am using IntelliJ but some colleagues are using eclipse and the inconsistent automatic-formatting makes unneccessary changes to version control system.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Eclipse format settings: avoid joining manual set line-breaks
 
Similar Threads
autoboxing and synchronized
for - scope (including own initializer)
Anyone know regular expressions?
Output from outer/inner class code?
Exit Sub code in Java