クイック・アシスト

クイック・アシストは、ローカル・コードの変換を実行します。 クイック・アシストは Java エディターの選択項目または単一カーソルによって起動され、クイック・フィックスと同じショートカット (Ctrl+1) を使用します。ただし、クイック・アシストは通常、エラーが存在する場合には表示されません。 同じ行にエラーが存在していても表示する場合は、もう一度 Ctrl+1 を押します。

クイック・アシストの選択は、直接ショートカットに割り当てることができます。デフォルトで、以下のショートカットがあります。

追加のショートカットの割り当て、またはデフォルトのショートカットの変更は、 「キー」設定ページを開く「一般」>「キー」設定ページ (「ソース」カテゴリー内) で行います。

クイック・アシストのインディケーター (電球) は、 Java エディター設定ページを開く 「Java」>「エディター」設定ページでオンにできます。

名前 コード例 呼び出しロケーション
'if'ステートメントを逆転 if (x) a(); else b(); > if (!x) b(); else a(); else ブロック付きの if ステートメント
ブール式を逆転 a && !b > !a || b ブール式
ローカル変数を逆転 boolean a = false;
if (a) {}
> boolean notA = true;
if (!notA) {}
ブール変数
等号を逆転します。 a.equals(b) > b.equals(a) 'equals' の呼び出し
条件式を逆転 x ? b : c > !x ? c : b 条件式
否定のプルアップ b && c > !(!b || !c) ブール式
否定のプッシュダウン !(b && c) > !b || !c 否定のブール式
余分の括弧の削除 if ((a == b) && (c != d)  {} > if (a == b && c != d)  {} 選択された式
小括弧内に式を入れます。 return a > 10 ? 1 : 2; > return (a > 10) ? 1 : 2; 選択された式
小括弧内に式を入れます。 if (a == b && c != d)  {} > if ((a == b) && (c != d))  {} 選択された式
ネストされた if 文の結合 if (a) { if (b) {} } > if (a && b) {} ネストされた if 文
ネストされた if 文の交換 if (a) { if (b) {} } > if (b) { if (a) {} } ネストされた if 文
(論理積) を使用した式をもつ if 文の分割 if (a && b) {} > if (a) { if (b) {} } if 文の中の論理積を使用した式
選択した 'if' ステートメントを || と結合します。 if (a) x();  if (b) x(); > if (a || b) x(); 選択された 'if' ステートメント
'if' シーケンスを if-else-if に結合 if (a) x();  if (b) y(); > if (a) x();  else if (b) y(); 選択された 'if' ステートメント
論理和された式の if 文の分割 if (a || b) x(); > if (a) x();  if (b) x(); if 文の中の論理和された式
If-else の代入を条件式に if (a) x= 1; else x= 2; > x= a ? 1 : 2; if 文
If-else の return を条件式に if (a) return 1;
else return 2;
> return a ? 1 : 2; if 文
条件式の代入を If-else に x= a ? 1 : 2; > if (a) x= 1; else x= 2; 条件式
条件式の return を If-else に return  a ? 1 : 2; > if (a) return 1; else return 2; 条件式
Switch を If-else に switch (kind) {
case 1: return -1;
case 2: return -2;
}
> if (kind == 1) {
  return -1;
} else if (kind == 2) {
  return -2;
}
switch 文
列挙型で欠落している case ステートメントの追加 switch (e){
}
> switch (e){
case E1: break;
case E2: break;
}
switch 文
オペランドの交換 a + b > b + a 2 項演算
キャストと代入 if (obj instanceof Vector) {
}
> if (obj instanceof Vector) {
 Vector vec= (Vector)obj;

}
'if' または 'while' 文内のインスタンス式
別の catch ブロックを使用します。 try {
} catch (FileNotFoundException | InterruptedIOException e) {
}
> try {
} catch (FileNotFoundException e) {
} catch (InterruptedIOException e) {
}
multi-catch ブロック (1.7 以降)
例外を、別の catch ブロックに移動します try {
} catch (FileNotFoundException | InterruptedIOException | IllegalArgumentException e) {
}
> try {
} catch (FileNotFoundException e) {
} catch (InterruptedIOException | IllegalArgumentException e) {
}
multi-catch 節の例外 (1.7 以降)
catch ブロックを結合します。 try {
} catch (FileNotFoundException e) {
} catch (InterruptedIOException e) {
}
> try {
} catch (FileNotFoundException | InterruptedIOException e) {
}
catch ブロック (1.7 以降)
finally ブロックを追加します。 try {
} catch (Exception e) {
}
> try {
} catch (Exception e) {
} finally {}
try/catch 文
else ブロックを追加します。 if (a) b(); > if (a) b(); else { } if 文
ブロックでステートメントを置換 if (a) b(); > if (a) { b(); } if 文
ブロックのアンラップ { a() } > a() ブロック、if/while/for 文
ストリングの選出 "abcdefgh" > "abc" + "de" + "fgh" 文字列リテラルの一部を選択
ストリング連結を StringBuilder (J2SE 5.0) または StringBuffer に変換 "Hello " + name > StringBuilder builder= new StringBuilder();
builder.append("Hello ");
builder.append(name);
文字列リテラルを選択
ストリング連結を MessageFormat に変換 "Hello " + name > MessageFormat.format("Hello {0}", name); 文字列リテラルを選択
変数の分割 int i= 0; > int i; i= 0; 初期化がある変数
結合変数 int i; i= 0; > int i= 0 初期化がない変数
変数への代入 foo() > X x= foo(); 式ステートメント
ローカルに抽出 foo(getColor()); > Color color= getColor();
foo(color);
式
フィールドへのパラメーターの代入 public A(int color) {} > Color fColor;
public A(int color) {
    fColor= color;
}
パラメーター
配列イニシャライザーから配列の作成 int[] i=  { 1, 2, 3 } > int[] i= new int[] { 1, 2, 3 } 配列イニシャライザー
「拡張 for ループ」への変換 (J2SE 5.0) for (Iterator i= c.iterator();i.hasNext();) {
}
> for (x : c) {
}
for ループ
索引付き「for」ループへの変換 (J2SE 5.0) for (x : c) {
}
> for (int i = 0; i < c.size(); i++) {
    x = c[i];
}
拡張 for ループ
イテレーター・ベースの「for」ループへの変換 (J2SE 5.0) for (x : c) {
}
> for (Iterator i= c.iterator();i.hasNext();) {
}
拡張 for ループ
スーパークラスのメソッドの作成


メソッド宣言
ファイル内の名前変更


識別子
ワークスペース内の名前変更


識別子
ローカル変数に抽出します。 a= b*8; > int x= b*8;
a= x;
式
定数に抽出します。 a= 8; > final static int CONST= 8;
a= CONST;
式
メソッドの抽出 int x= p * 5; > int x= getFoo(p); 式およびステートメント
ローカル変数のインライン化 int a= 8, b= a; > int b= 8; ローカル変数
ローカル変数をフィールドに変換 void foo() { int a= 8; } > int a= 8; void foo() {} ローカル変数
匿名をネスト・クラスに変換 new Runnable() { }; > class RunnableImplementation implements Runnable { } 匿名クラス
getter および setter に置換 (フィールドのカプセル化) p.x; > p.getX(); フィールド
推定される型引数を挿入します。 List<String> list = new ArrayList<>(); > List<String> list = new ArrayList<String>(); 汎用インスタンス作成式 (1.7 以降)

以下のクイック・アシストが、プロパティー・ファイル・エディターで使用できます。

関連概念

Java エディター
クイック・フィックスおよびクイック・アシスト

関連参照

クイック・フィックス
JDT アクション