List of Quick Assists

Quick assists perform local code transformations. They are invoked on a selection or a single cursor in the Java editor and use the same shortcut is used as for quick fixes (Ctrl +1), but quick assist are usually hidden when an error is around.

A selection of quick assist can be assigned to a direct shortcut. By default these are:

Assign more shortcuts or change the default shortcuts on the keys preference page.

A quick assist light bulb can be turned on on the Java Editor preference page.

Name Code example Invocation location
Inverse if statement if (x) a(); else b(); > if (!x) b(); else a(); on 'if' statements with 'else' block
Inverse boolean expression a && !b > !a || b on a boolean expression
Remove extra parentheses if ((a == b) && (c != d)  {} > if (a == b && c != d)  {} on selected expressions
Add paranoidal parentheses if (a == b && c != d)  {} > if ((a == b) && (c != d) on selected expressions
Join nested if statements if (a) { if (b) {} } > if (a && b) {} on a nested if statement
Swap nested if statements if (a) { if (b) {} } > if (b) { if (a) {} } on a nested if statement
Split if statement with and'ed expression if (a && b) {} > if (a) { if (b) {} } on an and'ed expression in a 'if'
Split if statement with or'd expression if (a || b) x(); > if (a) x();  if (b) x(); on an or'd expression in a 'if'
Inverse conditional expression x ? b : c > !x ? c : b on a conditional expression
Pull negation up b && c > !(!b || !c) On a boolean expression
Push negation down !(b && c) > !b || !c On a negated boolean expression
If-else assignment to conditional expression if (a) x= 1; else x= 2; > x= a ? 1 : 2; on an 'if' statement
If-else return to conditional expression if (a) return 1;
else return 2;
> return a ? 1 : 2; on an 'if' statement
Conditional expression assignment to If-else x= a ? 1 : 2; > if (a) x= 1; else x= 2; on a conditional expression
Conditional expression return to If-else return  a ? 1 : 2; > if (a) return 1; else return 2; on a conditional expression
Switch to If-else switch (kind) {
case 1: return -1;
case 2: return -2;
}
> if (kind == 1) {
  return -1;
} else if (kind == 2) {
  return -2;
}
on a switch statement
Exchange operands a + b > b + a on an infix operation
Cast and assign if (obj instanceof Vector) {
}
> if (obj instanceof Vector) {
 Vector vec= (Vector)obj;

}
on a instanceof expression in an 'if' or 'while' statement
Pick out string "abcdefgh" > "abc" + "de" + "fgh" select a part of a string literal
Split variable int i= 0; > int i; i= 0; On a variable with initialization
Join variable int i; i= 0; > int i= 0 On a variable without initialization
Assign to variable foo() > X x= foo(); On an expression statement
Extract to local foo(getColor()); > Color color= getColor();
foo(color);
On an expression
Assign parameter to field public A(int color) {} > Color fColor;
public A(int color) {
    fColor= color;
}
On a parameter
Add finally block try {
} catch (Expression e) {
}
> try {
} catch (Expression e) {
} finally {}
On a try/catch statement
Add else block if (a) b(); > if (a) b(); else { } On a if statement
Replace statement with block f (a) b(); > if (a) { b(); } On a if statement
Invert equals a.equals(b) > b.equals(a) On a invocation of 'equals'
Array initializer to Array creation int[] i=  { 1, 2, 3 } > int[] i= new int[] { 1, 2, 3 } On an array initializer
Convert to 'enhanced for loop' (J2SE 5.0) for (Iterator i= c.iterator();i.hasNext();) {
}
> for (x : c) {
}
On a for loop
Create method in super class


On a method declaration
Unwrap blocks { a() } > a() On blocks, if/while/for statements
Rename in file


On identifiers

Related concepts

Java editor
Quick Fix

Related reference

JDT actions