Code intentions help you simplify your code. They are activated using Alt+Enter.
Here is a complete list of the Groovy intentions available:
| Name | Description | Before Code | After Code |
|---|---|---|---|
| Change To C Style Comment | This intention converts one of more "end-of-line" comments to block comments. | //comment line 1 //comment line 2 x = 0x30 |
/*comment line 1 comment line 2 */ x = 0x30 |
| Change To End Of Line Comment | This intention converts a block comment to one or more "end-of-line" comments. | /*comment line 1 comment line 2 */ x = 0x30 |
//comment line 1 //comment line 2 x = 0x30 |
| Conditional To Elvis | This intention changes appropriate conditional operator to it's Elvis represenation. | public class X {
void f(a, b) {
return a!=null?a:b
}
|
public class X {
void f(a, b) {
return a?:b
}
|
| Convert Closure Arg To It | This converts an implicit call to a closure into an explicit call. | def myClosure = {i -> print i}
|
def myClosure = {print it}
|
| Convert G String To String | This intention converts selected GString literal into an equivalent String literal. | x = "48" |
x = '48' |
| Convert Integer To Decimal | This intention converts selected integer literal (written in either hexadecimal or octal notation) into decimal notation. |
x = 0x30 |
x = 48 |
| Convert Integer To Hex | This intention converts selected integer literal (written in either decimal or octal notation) into hexadecimal notation. |
x = 48; |
x = 0x30; |
| Convert Integer To Octal | This intention converts selected integer literal (written in either decimal or hexadecimal notation) back into octal notation. |
x = 48; |
x = 060; |
| Convert Parameter To Map Entry | This intention converts all occurrences of selected method or closure parameters to appropriate entries of parameter map. | def foo(arg1, arg2, arg3) {
use(arg1 + arg2 + arg3)
}
foo("Hello ", "world", "!")
|
def foo(args) {
use(args.arg1 + args.arg2 + args.arg3)
}
foo(args1: "Hello, ", arg2: "world", arg3: "!")
|
| Convert String To GString | This intention converts selected String literal into an equivalent GString literal. | x = '48' |
x = "48" |
| Demorgans Law | This intention replaces either a || b with !(!a && !b) or a && b with !(!a || !b) inside boolean expression. | public class X {
void f(a, b) {
if (!a || !b) return;
}
|
public class X {
void f(a, b) {
if (!(a && b)) return;
}
|
| Expand Boolean | This intention replaces uses of boolean values with equivalent if-then-else statements, if possible. |
public class X {
boolean f(boolean a) {
return a;
}
}
|
public class X {
boolean f(boolean a) {
if(a){
return true;
}
else{
return false;
}
}
}
|
| Flip Comparison | This intention reverses the order of evaluation of a comparison. | public class X {
void f(a, b) {
if (a < b) return;
}
|
public class X {
void f(a, b) {
if (b > a) return;
}
|
| Flip Conditional | This intention flips branches of the conditional operator. | public class X {
void f(a, b) {
return a>b?a:b
}
|
public class X {
void f(a, b) {
return a<=b?b:a
}
|
| Flip Conjunction | This intention reverses the order of evaluation of an '&&' or '||' expression. | public class X {
void f(a, b) {
if (a && b) return;
}
|
public class X {
void f(a, b) {
if (b &&a) return;
}
|
| For To Each | This intention replaces selected for..in statement with .each iterator and associated closure. | for(x in [1, 2, 3])
{
print(x)
}
|
[1, 2, 3].each{ x-> print(x) }
|
| Indexed Expression Conversion | This intention converts access to an indexed value using "[]" to an equivalent call to a ".getAt()" or ".setAt()" method. | x = y.getAt(z) |
x = y[z] |
| Indexing Method Conversion | This intention converts access to an indexed value using ".getAt()" or ".setAt()" methods to the equivalent [] form. | x = y.getAt(z) |
x = y[z] |
| Java Style Properties Invocation | This intention changes Java-style properties invocation to Groovy-style. | foo.setMyProperty(value) |
foo.myProperty = value |
| Make Closure Call Explicit | This converts an implicit call to a closure into an explicit call. | def Closure myClosure myClosure(arg1, arg2) |
def Closure myClosure myClosure.call(arg1, arg2) |
| Make Closure Call Implicit | This converts an explicit call to a closure into an implicit call. | def Closure myClosure myClosure.call(arg1, arg2) |
def Closure myClosure myClosure(arg1, arg2) |
| Merge Else If | This intention merges the else branch of an if-else statement, if the else contains nothing but a nested if-else statement. |
public class X {
int f(int a) {
if (a == 0) {
return 0;
}
else {
if (a == 1) {
return 2;
}
else {
return 18;
}
}
}
}
|
public class X {
int f(int a) {
if (a == 0) {
return 0;
}
else if (a == 1) {
return 2;
}
else {
return 18;
}
}
}
|
| Merge If And | This intention merges if-else statement inside then-branch of another if-else into one. | public class X {
void f(a, b) {
if (a)
if(b)
return;
}
|
public class X {
void f(a, b) {
if (a &&b)
return;
}
|
| Negate Comparison | This intention negates a comparison to it's opposite. | public class X {
void f(a, b) {
if (a < b) return;
}
|
public class X {
void f(a, b) {
if (!(b >= a)) return;
}
|
| Remove Parentheses From Method Call | This intention convert a top level method call with parentheses to the equivalent call without parentheses. | println("Hello World")
|
println "Hello World" |
| Split Else If | This intention splits an else-if branch into an equivalent nested if statement. | public class X {
int f(int a) {
if (a == 0) {
return 0;
}
else if (a == 1) {
return 2;
}
else {
return 18;
}
}
}
|
public class X {
int f(int a) {
if (a == 0) {
return 0;
}
else {
if (a == 1) {
return 2;
}
else {
return 18;
}
}
}
}
|
Labels:
None