简体   繁体   English

您可以自定义IntelliJ如何自动格式化方法声明和方法调用的换行吗?

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

In this answer 在这个answer

It shows you how to enable auto line wrapping in IntelliJ. 它显示了如何在IntelliJ中启用自动换行。

But can you customize it further? 但是您可以进一步自定义它吗?

For example, if you auto format this with a line wrap value of 120: 例如,如果您使用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 返回File > Settings > Editor > Code Style > Java > Wrapping and Braces

and set Method declaration parameters to Wrap always 并将“ Method declaration parameters设置为“ 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) {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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