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

后端 未结 7 1460
南方客
南方客 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 06:05

    Complementing Deepak Azad's answer, what you exactly need is the following:

    Windows: Window → Preferences → Java → Code Style
    → Formatter → Edit → Line wrapping (tab)

    Mac OS: ADT → Preferences → Java → Code Style
    → Formatter → Edit → Line wrapping (tab)

    Then, in the list at the left, select:

    Function Calls → Qualified invocations

    Now below this list, set Line wrapping policy to:

    Wrap all elements, except first element if not necessary

    Check:

    Force split, even if line shorter than maximum line width

    Finally, set Indentation policy to (thanks @Turbo):

    Indent on column

    It should give you the exact behavior you asked for.


    BONUS: Android Studio / IntelliJ Idea:

    Mac OS: Android Studio → Preferences (Cmd +,) → Editor → Code Style → Java → Wrapping And Braces tab → Chained method calls

    select

    Wrap always

    and check

    Align when multiline

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