简体   繁体   中英

Can you customize how IntelliJ does auto format line wrapping on method declarations and method calls?

In this answer

It shows you how to enable auto line wrapping in IntelliJ.

But can you customize it further?

For example, if you auto format this with a line wrap value of 120:

public void someMethodWithLotsOfArguments(int thisIsValue1, int thisIsValue2, int thisIsValue3, int thisIsValue4asdfasdfasdfasdfasdf, Double thisIsValue, int thisIsValue6, int thisIsValue7) {

It will become:

  public void someMethodWithLotsOfArguments(int thisIsValue1, int thisIsValue2, int thisIsValue3, int 
      thisIsValue4asdfasdfasdfasdfasdf, Double thisIsValue, int thisIsValue6, int thisIsValue7) {

Is there a way to get it to be smarter about this and format it like:

public void someMethodWithLotsOfArguments(int thisIsValue1, 
    int thisIsValue2, 
    int thisIsValue3, 
    int thisIsValue4asdfasdfasdfasdfasdf, 
    int thisIsValue5, 
    int thisIsValue6,
    int thisIsValue7) {

Or at the very least like:

  public void someMethodWithLotsOfArguments(int thisIsValue1, int thisIsValue2, int thisIsValue3, 
      int thisIsValue4asdfasdfasdfasdfasdf, Double thisIsValue, int thisIsValue6, int thisIsValue7) {

Something that doesn't break up the parameter type from the parameter name would be great.

Go back in File > Settings > Editor > Code Style > Java > Wrapping and Braces

and set Method declaration parameters to Wrap always

Doing so, method

public void someMethodWithLotsOfArguments(int thisIsValue1, int thisIsValue2, int thisIsValue3, int thisIsValue4asdfasdfasdfasdfasdf, Double thisIsValue, int thisIsValue6, int thisIsValue7) {
}

Will be formated as following

public void someMethodWithLotsOfArguments(int thisIsValue1,
        int thisIsValue2,
        int thisIsValue3,
        int thisIsValue4asdfasdfasdfasdfasdf,
        Double thisIsValue,
        int thisIsValue6,
        int thisIsValue7) {
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM