The Wrapping clained method calls a single line in Eclipse for Java

I was not able to figure out how to wrap each method call in Eclipse . For example, I have this:

 someObject.A().B().C(); 

But I really want this:

 someObject.A() .B() .C(); 

Nothing in the Line Wrapping section in Eclipse seems to give me this result.

+68
eclipse wrapping line
Jun 08 2018-11-11T00:
source share
7 answers

In addition to Deepak Azad's answer, you may need the following:

Windows : Window β†’ Settings β†’ Java β†’ Code Style
β†’ Formatter β†’ Edit β†’ Linear Packaging (tab)

Mac OS : ADT -> Preferences -> Java -> Code Style
β†’ Formatter β†’ Edit β†’ Linear Packaging (tab)

Then in the list on the left, select:

Function Calls β†’ Qualified Calls

Now, under this list, set the Line Wrap Policy :

Wrap all items except the first item if not necessary

Verify

Separation force, even if the line is less than the maximum line width

Finally, set the indentation policy to (thanks @Turbo ):

Indent by Column

It should give you the exact behavior you requested.




BONUS: Android Studio / IntelliJ Idea:

Mac OS : Android Studio β†’ Settings ( Cmd +, ) β†’ Editor β†’ Code Style β†’ Java β†’ Wrap and Bindings tab β†’ Call Chains

select

Always wrap

and check

Multiline Alignment

+127
May 04 '12 at 9:21 am
source share

Window> Preferences> Java> Code Style> Formater> Editing> Linear Packaging> Function Calls, set the "Line Wrap Policy" to "Wrap all items, each item in a new line."

+6
Jun 08 2018-11-11T00:
source share

Window-> Preferences-> Java-> Code Style-> Formater-> Edit-> Line wrapping-> Never join already wrapped strings

+5
Jun 08 '11 at 8:01
source share

If you want to format these segments yourself, you can prevent the reformatting of these eclipse segments by using:

 // @formatter:off ... // @formatter:on 

Perhaps you need to enable this in your settings: http://archive.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/eclipse-news-part2.html#JavaFormatter

See also: How to disable Eclipse code formatting for specific sections of Java code?

+2
Jan 31 '12 at 10:01
source share

For those who have eclipse code formatting options checked in the original control (for consistent code formatting throughout the command), there is a checkbox in the .settings folder.

The property that this formatting behavior will give you is in the file .settings/org.eclipse.jdt.core.prefs .

Property:

 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80 
0
Mar 15 '17 at 16:28
source share

in: Window-> Preferences-> Java-> Code Style-> Formater-> Edit-> Line wrapping-> Function call-> Qualified invocation

select the indentation policy as indentation in the column

0
Jun 12 '17 at 15:42 on
source share

Customize eclipse formatting format in both java and javascript. increase the maximum line that matches your screen. Windows> Preferences

Edit

-one
Feb 10 '17 at 15:40
source share



All Articles