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.
- Place the caret at a parameter you want to convert, and press Alt+EnterAlt+Enter:
- On the context menu, choose
- Repeat the procedure until all the required named arguments are represented as map entries. Note that
all the subsequent conversions are done silently.
- In a Groovy method, place the caret at a map to be converted, and press Alt+EnterAlt+Enter:
- On the context menu, choose , 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 .
- If necessary, choose to change return type of the method.
- 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.
- Type contents of a list or a map in the editor:
- Place the caret somewhere inside the square brackets, and press Ctrl+Alt+VCtrl+Alt+V.
The expression in brackets is converted to a list or map respectively.