Child pages
  • Intentions

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

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.

No Format
//comment line 1
//comment line 2 
x = 0x30
No Format
/*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.

No Format
/*comment line 1
comment line 2 */
x = 0x30
No Format
//comment line 1
//comment line 2
x = 0x30

Conditional To Elvis

This intention changes appropriate conditional operator to it's Elvis represenation.

No Format
public class X {
  void f(a,  b) {
    return a!=null?a:b
}
No Format
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.

No Format
def myClosure = {i -> print i}
No Format
def myClosure = {print it}

Convert G String To String

This intention converts selected GString literal into an equivalent String literal.

No Format
x = "48"
No Format
x = '48'

Convert Integer To Decimal

This intention converts selected integer literal (written in either hexadecimal or octal notation)
into decimal notation.

No Format
x = 0x30
No Format
x = 48

Convert Integer To Hex

This intention converts selected integer literal (written in either decimal or octal notation)
into hexadecimal notation.

No Format
x = 48;
No Format
x = 0x30;

Convert Integer To Octal

This intention converts selected integer literal (written in either decimal or hexadecimal notation)
back into octal notation.

No Format
x = 48;
No Format
x = 060;

Convert Parameter To Map Entry

This intention converts all occurrences of selected method or closure parameters to appropriate entries of parameter map.

No Format
def foo(arg1, arg2, arg3) {
  use(arg1 + arg2 + arg3)
}

foo("Hello ", "world", "!")
No Format
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.

No Format
x = '48'
No Format
x = "48"

Demorgans Law

This intention replaces either a || b with !(!a && !b) or a && b with !(!a || !b) inside boolean expression.

No Format
 public class X {
  void f(a,  b) {
    if (!a || !b) return;
} 
No Format
 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.

No Format
public class X {
  boolean f(boolean a) {
    return a;
  }
}
No Format
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.

No Format
public class X {
  void f(a,  b) {
    if (a < b) return;
}
No Format
public class X {
  void f(a,  b) {
    if (b > a) return;
}

Flip Conditional

This intention flips branches of the conditional operator.

No Format
public class X {
  void f(a,  b) {
    return a>b?a:b
}
No Format
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.

No Format
public class X {
  void f(a,  b) {
    if (a && b) return;
}
No Format
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.

No Format
for(x in [1, 2, 3])
{
   print(x)
}
No Format
[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.

No Format
x = y.getAt(z) 
No Format
x = y[z]

Indexing Method Conversion

This intention converts access to an indexed value using ".getAt()" or ".setAt()" methods to the equivalent [] form.

No Format
x = y.getAt(z) 
No Format
x = y[z]

Java Style Properties Invocation

This intention changes Java-style properties invocation to Groovy-style.

No Format
foo.setMyProperty(value)
No Format
foo.myProperty = value

Make Closure Call Explicit

This converts an implicit call to a closure into an explicit call.

No Format
def Closure myClosure
myClosure(arg1, arg2)
No Format
def Closure myClosure
myClosure.call(arg1, arg2)

Make Closure Call Implicit

This converts an explicit call to a closure into an implicit call.

No Format
def Closure myClosure
myClosure.call(arg1, arg2)
No Format
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.

No Format
public class X {
  int f(int a) {
    if (a == 0) {
      return 0;
    }
    else {
      if (a == 1) {
        return 2;
      }
      else {
        return 18;
      }
    }
  }
}
No Format
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.

No Format
public class X {
  void f(a,  b) {
    if (a)
       if(b)
         return;
}
No Format
public class X {
  void f(a,  b) {
    if (a &&b)
         return;
}

Negate Comparison

This intention negates a comparison to it's opposite.

No Format
public class X {
  void f(a,  b) {
    if (a < b) return;
}
No Format
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.

No Format
println("Hello World")
No Format
println "Hello World"

Split Else If

This intention splits an else-if branch into an equivalent nested if statement.

No Format
public class X {
  int f(int a) {
    if (a == 0) {
      return 0;
    }
    else if (a == 1) {
      return 2;
    }
    else {
      return 18;
    }
  }
}
No Format
public class X {
  int f(int a) {
    if (a == 0) {
      return 0;
    }
    else {
      if (a == 1) {
        return 2;
      }
      else {
        return 18;
      }
    }
  }
}