2012-02-08 11 views
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」に設定しました。これは、配列初期化子のためのより良いですが、それでも開口部に一致するようにインデント決算parethesisは、私がそれを望むようにかっこません。

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" 
      } 
      ) 
     ); 
} 
+0

はい、各構成要素のインデントを変更します。それぞれに3-4のオプションがあります。あなたが何かを平坦化しているなら、かなり壊れた設定があります。デフォルトでは、私はあなたが望むフォーマットを得ると思います。 –

答えて

1

あなたが行の折り返し]タブを確認しました。式/配列イニシャライザと関数呼び出し/ Qalifiedオブジェクトの割り当て引数については、「すべての要素をラップする、新しい行のすべての要素をラップする」を選択すると、同様のものが得られます。

+4

私はちょうどインデントを修正するが、私のための行を分割することはありません。私はまだ1つの行配列とメソッド呼び出しを行うことができるようにしたい:新しいint [] {1,2,3}; call.method( "one"、 "two");配列の初期化子の場合、たとえ私が私のために行を分割していても、新しい行に閉じ括弧を入れず、括弧で囲むようにインデントを作成しません。最後の配列の後に配置します素子。 –

関連する問題