有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

在这个^{}

它向您展示了如何在IntelliJ中启用自动换行

但是你能进一步定制它吗

例如,如果自动将换行值设置为120,则:

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

它将成为:

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

有没有办法让它变得更聪明,并将其格式化为:

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

或者至少像:

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

如果不将参数类型与参数名称分开,那就太好了


共 (1) 个答案

  1. # 1 楼答案

    回到File > Settings > Editor > Code Style > Java > Wrapping and Braces

    并将Method declaration parameters设置为Wrap always

    这样做,方法

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

    格式如下

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