次の例で期待するインデントを追加するために、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"
}
)
);
}