Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chained methods formatting in Eclipse

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);
like image 355
Hoeze Avatar asked Mar 28 '13 13:03

Hoeze


2 Answers

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

like image 170
Java42 Avatar answered Oct 04 '22 16:10

Java42


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.

like image 40
Bananeweizen Avatar answered Oct 04 '22 16:10

Bananeweizen