Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Eclipse Formatter Wrap Where Necessary, Every Element on a New Line?

I'm tying to figure out how I can customize the Eclipse code formatter to break lines more to my liking. I'm trying to set the style for parameter lists, either in method declarations or calls. Looking for a mix of Wrap where necessary and Wrap all elements, every element on a new line. I want to Wrap where necessary, every element on a new line, which doesn't seem to exist. My logic is that no break is necessary for short lines, my eye can scan the parameter list horizontally:

public void myMethod(int p1, int p2, int p3) {

But for lists that do need to be broken, I would like every element on a new line, so I can scan vertically:

public void myMethodWithALotOfParams(
    ReallyLongClassName param1,
    AnotherLongName aLongParamName,
    int p3) {

I can't seem to make this happen. I can wrap everything, including short lists. I can wrap only long lines, and continue stacking parameters on each line until I reach the margin. I can't trigger wrapping on long lines, then put each parameter on its own line.

This style can be seen in several places in Code Complete (2nd Ed).

UPDATE >>

I don't think there is anything built in to Eclipse to handle this, but I'm not afraid to write code. :) Eclipse is open source, so I tried to find the code that handles formatting, in hopes of building in the preferred behavior. Didn't have much luck on the first try, lots of abstraction, not much parsing and formatting. Hints?

like image 377
Sean Colvin Avatar asked Aug 23 '11 19:08

Sean Colvin


1 Answers

look at this link

Window -> Preferences -> Java -> Code Style -> Formatter -> New (Profile) -> Edit -> Line Wrapping -> Never join already wrapped lines

Or change other parameters if you want to change line wrapping parameters.

like image 106
Bobs Avatar answered Sep 30 '22 02:09

Bobs