簡體   English   中英

您可以自定義IntelliJ如何自動格式化方法聲明和方法調用的換行嗎?

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

在這個answer

它顯示了如何在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) {

不會破壞參數名稱中的參數類型的東西會很棒。

返回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) {
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM