Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse code formatter: do not wrap lines on method call

I'm trying the Eclipse Auto Formatter, but I cannot find a proper options to format according to my liking.

When I have a line like this:

MyLongNameClass myLongNameObject = otherObject.callAVeryLongMethodWithParameters(param1, param2, param3)

Eclipse auto formatter wraps it this way:

MyLongNameClass myLongNameObject = otherObject
    .callAVeryLongMethodWithParameters(param1, param2, param3)

I'd rather like to have this result:

MyLongNameClass myLongNameObject = 
    otherObject.callAVeryLongMethodWithParameters(
        param1, param2, param3)

Keeping the object and the method accessor on the same line, and avoiding starting a new line with '.'. Is this possible? Is there an option for this?

like image 615
smirne Avatar asked Aug 02 '26 11:08

smirne


1 Answers

I'm not sure if you can really do what you wanted, but this might get you close:

In eclipse Mars:

Go to Window -> Preferences -> Java -> Code Style -> Formatter

Create your own profile based on one of the built-ins using the New... button. By default this will take you into the editing window. If you already have a formatter set up that you want to change, select it and use the Edit... button.

In the profile editing window do the following:

  • Select the Line Wrapping tab
  • In the left scroll-box, go to Function Calls -> Qualified invocations.
  • In the Settings for qualified invocations area select Do not wrap.
  • In the left scroll-box, go to Function Calls -> Arguments
  • Select Wrap first element, others where necessary in the argument settings then select Indent by one.

You can test these settings by adjusting the line width in the preview window.

I know this is a late submission, but I hope it helps someone else who searches for this same feature.

like image 146
desilvai Avatar answered Aug 04 '26 01:08

desilvai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!