IntelliJ IDEA 13.1.0 Web Help

In this section you can find some examples of working with lists and maps in IntelliJ IDEA:

To convert a parameter of a function to a map entry

If a function has a lengthy list of named arguments, you can reduce it by representing parameters as map entries. For this purpose, IntelliJ IDEA suggests the Convert parameter to map entry intention action.

  1. Place the caret at a parameter you want to convert, and press Alt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+Enter, Shift+Alt+J or Ctrl+Shift+MAlt EnterAlt EnterCommand 1:

    groovyConvertParam1.png

  2. On the context menu, choose Convert parameter to map entry, and specify conversion parameters:

    groovyConvertParam2.png

  3. Repeat the procedure until all the required named arguments are represented as map entries. Note that all the subsequent conversions are done silently.

    groovyConvertParam3.png

To convert Groovy map to a class instance
  1. In a Groovy method, place the caret at a map to be converted, and press Alt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+EnterAlt+Enter, Shift+Alt+J or Ctrl+Shift+MAlt EnterAlt EnterCommand 1:

    groovyConvertMapToClass

  2. On the context menu, choose Convert to class, and specify new class name and the package where the new class will be created. If such package doesn't yet exist, you can create one immediately,by clicking icon_newFolder.
  3. If necessary, choose to change return type of the method.
  4. Click OK to apply changes and perform conversion.

    As a result, a class is created, with the fields corresponding to the keys of the original map.

To produce a list or a map
  1. Type contents of a list or a map in the editor:
    [55, 127,-9,-100,568]
                

    or

    [fname:"John",lname:"Smith",age:31]
              
  2. Place the caret somewhere inside the square brackets, and press Ctrl+Alt+VCtrl+Alt+VShift+Alt+VCtrl+Alt+VCtrl+Alt+VCtrl+Alt+V or Ctrl+Shift+VCtrl+Alt+VShift+Alt+VShift+Alt+L or Ctrl+Alt+VAlt Command VAlt Command VAlt Command L. The expression in brackets is converted to a list or map respectively.

    GroovyIntroduceVariable.png

To inline a list or a map
  1. Place the caret on the list or map declaration, and press Ctrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NShift+Alt+IAlt Command NAlt Command NAlt Command I. IntelliJ IDEA highlights the encountered usages:

    GroovyInline1.png

  2. Confirm inlining:

    GroovyInline2.png

See Also

Procedures:

External Links:

Web Resources: