Wrapping chained method calls on a separate line in Eclipse for Java

后端 未结 7 1458
南方客
南方客 2020-12-02 05:10

I haven\'t been successful in figuring out how to wrap each method call in Eclipse. For example, I have this:

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

相关标签:
7条回答
  • 2020-12-02 05:48

    If you are willing to do the formatting of those segments yourself, you can prevent eclipse from reformatting those segments by using:

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

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

    See also: How to turn off the Eclipse code formatter for certain sections of Java code?

    0 讨论(0)
  • 2020-12-02 05:49

    For those who have eclipse code formatting settings checked into source control (for consistent code formatting across the whole team), the .settings folder is checked in.

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

    The property is:

    org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
    
    0 讨论(0)
  • 2020-12-02 05:52

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

    select Indentation policy as indent on column

    0 讨论(0)
  • 2020-12-02 05:56

    Customize your eclipse formatter in both java and javascript. increase the max line with that fits your screen.

    0 讨论(0)
  • 2020-12-02 06:00

    Window → Preferences → Java → Code Style → Formater → Edit → Line wrapping → Never join already wrapped lines

    0 讨论(0)
  • 2020-12-02 06:03

    Window > Preferences > Java > Code Style > Formater > Edit > Line wrapping > Function Calls, set the 'Line wrapping policy' as 'Wrap all elements, every element on a new line'.

    0 讨论(0)
提交回复
热议问题