Reputation: 55
I'm using eclipse luna (4.4). I have a java line that looks like this:
LongClassName obj = new LongClassName(new AnotherLongName(), new YetAnotherLongNAme());
This line is longer than my line width, so i would like to configure the formatter to fix this. Unfortunately, the formatter keeps changing it to:
LongClassName obj =
new LongClassName(new AnotherLongName(), new YetAnotherLongNAme());
Which is problematic because the second line is still longer than my line width.
I would like the formatter to wrap the argument list, like so:
LongClassName obj =
new LongClassName(new AnotherLongName(),
new YetAnotherLongNAme());
However, i can't figure out how to do that. I tried changing the policy fields in "Formatter -> Line Wrapping -> Function Calls", but it doesn't help. Enabling or disabling the "Prefer warpping outer expressions..." option doesn't change the result either.
I don't want to resort to on/off tags or to use "Never join already wrapped lines", I want the formatter to do it automatically.
Edit:
I'd rather not force the formatter to wrap all function calls, only those that exceed the line width. E.g. this:
Foo f = new Foo(4, 7);
should stay as it is, and not be wrapped.
Upvotes: 0
Views: 988
Reputation: 2744
Formatter -> Line Wrapping -> Function Calls
set: Line wrapping policy:
to Wrap all elements, except first element if not necessary (5 of 5)
check: Force split, even if line shorter than maximum line width
set: Indentation policy
to Indent on column
this way you do not need to change Maximum line width
if you want also right side of assignment (new LongClasssName... in your case) to wrap you should also do the followings:
Formatter -> Line Wrapping -> Expressions -> Assignements
set: Line wrapping policy:
to Wrap first element, others when necessary
check: Force split, even if line shorter than maximum line width
set: Indentation policy
to Indent by one
p.s: you should apply only this changes to Eclipse [built-in]
settings
Upvotes: 1