8

次の例で期待するインデントを追加するために、Eclipse フォーマッターとコードのクリーンアップを構成 (または拡張) できます。

public static void main(String[] args) {
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
        "this is string one",
        "this is string two",
        "this is string three"
    );

    System.out.println(
        new MessageFormat("{0} {1} {2} {3}").format(
            new String[]{
                "this is string zero",
                "this is string one",
                "this is string two",
                "this is string three"
            }
        )
    );
}

見つけられるすべての設定をいじってみました。「行を結合しない」オプションを使用すると、コードが完全に解体されることはありませんが、それでもインデントがすべて削除され、コードは次のようになります。

    String[] numbers = new String[] {
    "one",
    "two",
    "three",
    "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
    "this is string one",
    "this is string two",
    "this is string three"
    );

    System.out.println(
    new MessageFormat("{0} {1} {2} {3}").format(
    new String[] {
    "this is string zero",
    "this is string one",
    "this is string two",
    "this is string three"
    }
    )
    );

次のようなブロックの周りの書式設定をオフにする機能を発見しました。

    // @formatter:off
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };
    // @formatter:on

私のコードがそれらで散らばってしまうことを除いて、これはまともな回避策であり、コードのクリーンアップの「正しいインデント」部分はディレクティブを無視し、とにかくインデントを台無しにします。

編集:「行の折り返し」->「折り返し行のデフォルトのインデント」と「配列の初期化のデフォルトのインデント」の設定を見つけ、「0」ではなく「1」に設定しました。それは配列初期化子にとってはより良いことですが、私が望むように左括弧に一致するように右括弧をインデントしません:

public static void main(String[] args) {
    String[] numbers = new String[] {
        "one",
        "two",
        "three",
        "four",
    };

    new MessageFormat("{0} {1} {2} {3}").format(
        "this is string one",
        "this is string two",
        "this is string three"
        );

    System.out.println(
        new MessageFormat("{0} {1} {2} {3}").format(
            new String[] {
                "this is string zero",
                "this is string one",
                "this is string two",
                "this is string three"
            }
            )
        );
}
4

1 に答える 1

1

行折り返しタブを確認しましたか。式/配列初期化子と関数呼び出し/修飾されたオブジェクト割り当て引数で「すべての要素、新しい行のすべての要素をラップする」を選択すると、同様のものが得られると思います

于 2012-02-08T01:55:10.587 に答える