7

I'd like to configure the Eclipse java formatter to format chained method calls like that:

lblName
        .setX(last.getX() + last.getWidth())
        .setY(0)
        .setHeight(this.height)
        .setWidth(80);

My problem is, that I don't know how to make it only format it like this, if the first method call already is placed in the second line. This call should be untouched:

lblName.setX(last.getX() + last.getWidth()).setY(0).setHeight(this.height).setWidth(80);
Arian
  • 3,183
  • 5
  • 30
  • 58
Hoeze
  • 636
  • 5
  • 20
  • 2
    [Wrapping chained method calls on a separate line in Eclipse for Java](http://stackoverflow.com/a/10446098/1083128) might be helpful – Mia Dec 02 '13 at 06:38
  • Solution is here: http://stackoverflow.com/questions/6275785/wrapping-chained-method-calls-on-a-separate-line-in-eclipse-for-java – mystilleef Mar 26 '15 at 20:56

2 Answers2

17

You say:

...if the first method call already is placed...call should be untouched...

If you don't want the formatter to wrap already wrapped lines, have a look at this panel:

enter image description here

Java42
  • 7,628
  • 1
  • 32
  • 50
  • Thanks. Just to add - the path is Windows (menu) -> Preferences -> Java/Code Style/Formatter (as above) -> Select Java Conventions (dropdown) -> Edit (button) -> Line wrapping (tab). If you want to change them you'll need to change the Profile name from the default to edit, then save. – Stuart Brock Jun 14 '18 at 11:56
1

That's not possible. You can either have a line break after each method call, after a certain character limit per line, or not at all.

That said, your request is also not well thought. Writing two times the same code with differences only in line breaks (e.g. by two different people in the same team) should lead to getting the same formatted code for committing to a common repository.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • 2
    the solution posted above works perfectly OK. There is nothing wrong with it. We have a bunch of Apache Camel code done in this way and this is a perfect solution. – Rodrigo Asensio Jan 16 '15 at 16:11