IntelliJ IDEA 11.1 Web Help

10.5+

This section discusses the Introduce Parameter refactoring in Groovy. This refactoring allows to perform the following actions:

In this section:

Examples

Before After
class Cat {
  Cat cat = new Cat()
  def makePestOfItself(){
    print ("miaou!!!!!!!!")
  }
  def makeTroubles(){
    if (makePest){
      makePestOfItself()
    }
  }
}
class Cat {
  Cat cat = new Cat()
  def makePestOfItself(String warning){
    print (warning)
  }
  def makeTroubles(){
    if (makePest){
      makePestOfItself("miaou!!!!!!!!")
    }
  }
}
class Bar {
  def foo = {
    print 'H<caret here>ello, world!'
  }
}

new Bar().foo()
new Bar().foo.call()
class Bar {
  def foo = { String s ->
    print s
  }
}

new Bar().foo('Hello, world!')
new Bar().foo.call('Hello, world!')
Introducing a parameter in Groovy
  1. In the editor, place the cursor within the expression to be replaced by a parameter.
  2. Do one of the following:
    • Press Ctrl+Alt+PCommand Alt P.
    • Choose Refactor | Introduce Parameter in the main menu.
    • Select Refactor | Introduce Parameter from the context menu.
  3. In the Introduce Parameter dialog:
    1. Specify the parameter name in the Name field.
    2. Choose parameter type, and specify whether you want to declare the new parameter final, and create the overloading method.
    3. Click Refactor.

See Also

Concepts:

Reference:

Web Resources: