# Work with Groovy code in the editor

> **TL;DR**
> Required plugin: Groovy (bundled)

When you work with Groovy code in the [editor](using-code-editor.html), IntelliJ IDEA offers you various code completion, [live templates](settings-live-templates.html), refactoring, inspection, and Groovy intention actions that help you write code faster and easier.

## Code completion

When you access [Basic Completion](auto-completing-code.html) by pressing `Ctrl+Space` (Windows), `⌃ Space` (macOS), `⌃ Space` (IntelliJ IDEA Classic (macOS)), `⌃ Space` (macOS System Shortcuts), `Ctrl+Space` (XWin), `Ctrl+Space` (GNOME), `Ctrl+Space` (KDE), `Alt+/` (Emacs), `Ctrl+Space` (Sublime Text), `⌃ Space` (Sublime Text (macOS)), `Ctrl+Space` (NetBeans), `Ctrl+Space` (Visual Studio), `⌃ Space` (Visual Studio (macOS)), `Ctrl+Space` (Eclipse), `⌃ Space` (Eclipse (macOS)), you get basic suggestions for variables, types, methods, expressions, for a parameter name you get type suggestions and so on. When you call Basic Completion twice, it shows you more results.

The [Smart Completion](advanced-code-completion.html#smart_type_matching_completion) feature is aware of the expected type and data flow, and offers the options relevant to the context. To call Smart Completion, press `Ctrl+Shift+Space` (Windows), `⌃ ⇧ Space` (macOS), `⌃ ⇧ Space` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ Space` (macOS System Shortcuts), `Ctrl+Shift+Space` (XWin), `Ctrl+Shift+Space` (GNOME), `Ctrl+Shift+Space` (KDE), `Ctrl+Shift+Space` (Emacs), `Ctrl+Shift+Space` (Sublime Text), `Ctrl+Shift+Space` (Sublime Text (macOS)), `Ctrl+Shift+Space` (NetBeans), `Ctrl+Alt+Space` (Visual Studio), `⌃ ⌥ Space` (Visual Studio (macOS)), `Alt+Shift+Space` (Eclipse), `⌥ ⇧ Space` (Eclipse (macOS)). When you call Smart Completion twice, it shows you more results, including chains.

![Code completion](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_code_completion_import.animated.gif)

> **Tip:**
> To overwrite the identifier at the caret, instead of just inserting the suggestion, press `Tab` (Windows), `⇥` (macOS), `⇥` (IntelliJ IDEA Classic (macOS)), `⇥` (macOS System Shortcuts), `Tab` (XWin), `Tab` (GNOME), `Tab` (KDE), `Tab` (Emacs), `Tab` (Sublime Text), `⇥` (Sublime Text (macOS)), `Tab` (NetBeans), `Tab` (Visual Studio), `⇥` (Visual Studio (macOS)), `Tab` (Eclipse), `⇥` (Eclipse (macOS)). This is helpful if you're editing part of an identifier, such as a filename.

To let IntelliJ IDEA complete a statement for you, press `Ctrl+Shift+Enter` (Windows), `⌘ ⇧ ⏎` (macOS), `⌘ ⇧ ⏎` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ ⏎` (macOS System Shortcuts), `Ctrl+Shift+Enter` (XWin), `Ctrl+Shift+Enter` (GNOME), `Ctrl+Shift+Enter` (KDE), `Ctrl+Shift+Enter` (Emacs), `Ctrl+Shift+Enter` (Sublime Text), `Ctrl+Shift+Enter` (Sublime Text (macOS)), `Ctrl+Shift+Enter` (NetBeans), `Ctrl+Shift+Enter` (Visual Studio), `⌘ ⇧ ⏎` (Visual Studio (macOS)), `Ctrl+Shift+Enter` (Eclipse), `⌘ ⇧ ⏎` (Eclipse (macOS)).

[Statement Completion](advanced-code-completion.html#statements_completion) will automatically add the missing parentheses, brackets, braces and the necessary formatting.

The [Postfix Completion](postfix-code-completion.html) feature lets you transform an already typed expression to another one, based on the postfix you type after a dot.

For more information, refer to [Auto-Completing Code](auto-completing-code.html).

## Refactoring basics

IntelliJ IDEA offers a comprehensive set of automated code refactorings that lead to significant productivity gains when used correctly. Firstly, don't bother selecting anything before you apply a refactoring. IntelliJ IDEA is smart enough to figure out what statement you're going to refactor, and only asks for confirmation if several choices are possible.

> **Tip:**
> To undo the last refactoring, switch the focus to the [Project tool window](project-tool-window.html) and press `Ctrl+Z` (Windows), `⌘ Z` (macOS), `⌘ Z` (IntelliJ IDEA Classic (macOS)), `⌘ Z` (macOS System Shortcuts), `Ctrl+Z` (XWin), `Ctrl+Z` (GNOME), `Ctrl+Z` (KDE), `Ctrl+Shift+Minus` (Emacs), `Ctrl+Z` (Sublime Text), `⌘ Z` (Sublime Text (macOS)), `Ctrl+Z` (NetBeans), `Ctrl+Z` (Visual Studio), `⌘ Z` (Visual Studio (macOS)), `Ctrl+Z` (Eclipse), `⌘ Z` (Eclipse (macOS)).

| Action | Shortcut |
| --- | --- |
| Rename |  `Shift+F6` (Windows), `⇧ F6` (macOS), `⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ R` (macOS System Shortcuts), `Shift+F6` (XWin), `Shift+F6` (GNOME), `Shift+F6` (KDE), `Shift+F6` (Emacs), `Shift+F6` (Sublime Text), `⇧ F6` (Sublime Text (macOS)), `Ctrl+R` (NetBeans), `Ctrl+R, R` (Visual Studio), `⌘ R, R` (Visual Studio (macOS)), `Alt+Shift+R` (Eclipse), `⇧ F6` (Eclipse (macOS))  |
| Extract variable or type |  `Ctrl+Alt+V` (Windows), `⌘ ⌥ V` (macOS), `⌘ ⌥ V` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ V` (macOS System Shortcuts), `Ctrl+Alt+V` (XWin), `Ctrl+Alt+V` (GNOME), `Alt+Shift+V` (KDE), `Ctrl+Alt+V` (Emacs), `Ctrl+Alt+V` (Sublime Text), `Ctrl+Alt+V` (Sublime Text (macOS)), `Alt+Shift+V` (NetBeans), `Ctrl+R, V` (Visual Studio), `⌘ R, V` (Visual Studio (macOS)), `Alt+Shift+L` (Eclipse), `⌘ ⌥ L` (Eclipse (macOS))  |
| Extract field |  `Ctrl+Alt+F` (Windows), `⌘ ⌥ F` (macOS), `⌘ ⌥ F` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ F` (macOS System Shortcuts), `Ctrl+Alt+F` (XWin), `Ctrl+Alt+F` (GNOME), `Ctrl+Alt+F` (KDE), `Ctrl+Alt+F` (Emacs), `Ctrl+Alt+F` (Sublime Text), `Ctrl+Alt+F` (Sublime Text (macOS)), `Alt+Shift+E` (NetBeans), `Ctrl+R, F` (Visual Studio), `⌘ R, F` (Visual Studio (macOS)), `Ctrl+Alt+F` (Eclipse), `⌘ ⌥ F` (Eclipse (macOS))  |
| Extract a constant |  `Ctrl+Alt+C` (Windows), `⌘ ⌥ C` (macOS), `⌘ ⌥ C` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ C` (macOS System Shortcuts), `Ctrl+Alt+C` (XWin), `Ctrl+Alt+C` (GNOME), `Ctrl+Alt+C` (KDE), `Ctrl+Alt+C` (Emacs), `Ctrl+Alt+C` (Sublime Text), `⌘ ⌥ C` (Sublime Text (macOS)), `Alt+Shift+C` (NetBeans), `Ctrl+Alt+C` (Visual Studio), `⌘ ⌥ C` (Visual Studio (macOS)), `Ctrl+Alt+C` (Eclipse), `Ctrl+Alt+C` (Eclipse (macOS))  |
| Extract a method |  `Ctrl+Alt+M` (Windows), `⌘ ⌥ M` (macOS), `⌘ ⌥ M` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ M` (macOS System Shortcuts), `Ctrl+Alt+M` (XWin), `Ctrl+Alt+M` (GNOME), `Ctrl+Alt+M` (KDE), `Ctrl+Alt+M` (Emacs), `Ctrl+Alt+M` (Sublime Text), `⌘ ⌥ M` (Sublime Text (macOS)), `Alt+Shift+M` (NetBeans), `Ctrl+R, M` (Visual Studio), `⌘ R, M` (Visual Studio (macOS)), `Alt+Shift+M` (Eclipse), `⌘ ⌥ M` (Eclipse (macOS))  |
| Extract a parameter |  `Ctrl+Alt+P` (Windows), `⌘ ⌥ P` (macOS), `⌘ ⌥ P` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ P` (macOS System Shortcuts), `Ctrl+Alt+P` (XWin), `Ctrl+Alt+P` (GNOME), `Ctrl+Alt+P` (KDE), `Ctrl+Alt+P` (Emacs), `Ctrl+Alt+P` (Sublime Text), `⌘ ⌥ P` (Sublime Text (macOS)), `Ctrl+Alt+P` (NetBeans), `Ctrl+R, P` (Visual Studio), `⌘ R, P` (Visual Studio (macOS)), `Ctrl+Alt+P` (Eclipse), `⌘ ⌥ P` (Eclipse (macOS))  |
| Inline |  `Ctrl+Alt+N` (Windows), `⌘ ⌥ N` (macOS), `⌘ ⌥ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ N` (macOS System Shortcuts), `Ctrl+Alt+N` (XWin), `Ctrl+Alt+N` (GNOME), `Ctrl+Alt+N` (KDE), `Ctrl+Alt+N` (Emacs), `Ctrl+Alt+N` (Sublime Text), `⌘ ⌥ N` (Sublime Text (macOS)), `Ctrl+Alt+N` (NetBeans), `Ctrl+R, I` (Visual Studio), `⌘ R, I` (Visual Studio (macOS)), `Alt+Shift+I` (Eclipse), `⌘ ⌥ I` (Eclipse (macOS))  |
| Copy |  `F5` (Windows), `F5` (macOS), `F5` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ Y` (macOS System Shortcuts), `F5` (XWin), `F5` (GNOME), `F5` (KDE), `F5` (Emacs), `F5` (Sublime Text), `F5` (Sublime Text (macOS)), `F5` (NetBeans), `F5` (Visual Studio), `F5` (Visual Studio (macOS)), `F5` (Eclipse), `F5` (Eclipse (macOS))  |
| Move |  `F6` (Windows), `F6` (macOS), `F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ I` (macOS System Shortcuts), `F6` (XWin), `F6` (GNOME), `F6` (KDE), `F6` (Emacs), `F6` (Sublime Text), `F6` (Sublime Text (macOS)), `Ctrl+M` (NetBeans), `Ctrl+R, O` (Visual Studio), `⌘ R, O` (Visual Studio (macOS)), `Alt+Shift+V` (Eclipse), `⌘ ⌥ V` (Eclipse (macOS))  |
| Refactor this |  `Ctrl+Alt+Shift+T` (Windows), `⌃ T` (macOS), `⌘ ⌥ ⇧ T` (IntelliJ IDEA Classic (macOS)), `⌃ S` (macOS System Shortcuts), `Ctrl+Alt+Shift+T` (XWin), `Ctrl+Alt+Shift+T` (GNOME), `Ctrl+Alt+Shift+T` (KDE), `Ctrl+Alt+Shift+T` (Emacs), `Ctrl+Alt+Shift+T` (Sublime Text), `⌃ T` (Sublime Text (macOS)), `Ctrl+Alt+Shift+T` (NetBeans), `Ctrl+Shift+R` (Visual Studio), `⌘ ⇧ R` (Visual Studio (macOS)), `Ctrl+Alt+Shift+T` (Eclipse), `⌃ T` (Eclipse (macOS))  |

> **Tip:**
> A real time-saver is the ability to extract part of a string expression with the help of the Extract refactorings. Just select a string fragment and apply a refactoring to replace all of the selected fragment usages with the introduced constant or variable.

For more information, refer to [Code refactoring](refactoring-source-code.html) .

## Groovy inspections

Inspections are built-in static code analysis tools that help you find probable bugs, locate dead code, detect performance issues, and improve the overall code structure.

To check and configure the available Groovy inspections, go to  the Editor | Inspections settings page `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) .

![Groovy inspections settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_inspections.png)

Most inspections not only tell you where a problem is, but also provide quick fixes to deal with it right away. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) to choose a quick-fix.

> **Tip:**
> The editor lets you quickly navigate between the highlighted problems via keyboard shortcuts. Press `F2` (Windows), `F2` (macOS), `F2` (IntelliJ IDEA Classic (macOS)), `⌃ Comma` (macOS System Shortcuts), `F2` (XWin), `F2` (GNOME), `F2` (KDE), `F2` (Emacs), `F2` (Sublime Text), `F2` (Sublime Text (macOS)), `F2` (NetBeans), `Alt+Page Down` (Visual Studio), `⌥ Page ↓` (Visual Studio (macOS)), `F2` (Eclipse), `⌘ .` (Eclipse (macOS)) to go to the next problem, and `Shift+F2` (Windows), `⇧ F2` (macOS), `⇧ F2` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ Comma` (macOS System Shortcuts), `Shift+F2` (XWin), `Shift+F2` (GNOME), `Shift+F2` (KDE), `Shift+F2` (Emacs), `Shift+F2` (Sublime Text), `Shift+F2` (Sublime Text (macOS)), `Shift+F2` (NetBeans), `Alt+Page Up` (Visual Studio), `⌥ Page ↑` (Visual Studio (macOS)), `Shift+F1` (Eclipse), `⌘ ⇧ .` (Eclipse (macOS)) to go to the previous one.

Inspections that are too complex to be run on-the-fly are available when you perform code analysis for the entire project. You can do this in one of the following two ways: by selecting `Code | Running Code Cleanup with profile '{0}'…` from the main menu, or by selecting `Code| Analyze Code | Run Inspection by Name…` to run an inspection by its name.

Note that while inspections provide quick-fixes for code that has potential problems, intentions help you apply automatic changes to code that is correct. To get a list of intentions applicable to the code at the caret, press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)).

For more information, refer to [Code inspections](code-inspection.html).

## Groovy live templates

IntelliJ IDEA provides you with various [live templates](using-live-templates.html) that you can use while working with Groovy code in the editor.

Before you start working with the templates, ensure that you have the [Groovy Live Templates](https://plugins.jetbrains.com/plugin/31544-groovy-live-templates) plugin [installed and enabled](managing-plugins.html).

You can access the settings to see the list of available templates.

Procedure: Access the live templates settings

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Editor | Live Templates`.

2. In the list of options, click Groovy node and check the list of provided live templates.

You can check an abbreviation, description, and a code sample for the template.

![Groovy Live Templates Settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_live_templates.png)

## Groovy intentions

To read a short description of any Groovy intention action, check its code example, and disable the ones you do not need, access the Groovy intentions settings.

Procedure:

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Editor | Inspections`.

2. In the list of options, click the Groovy node, locate the intention you need and make the adjustments.

![Groovy Intentions settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_intention_settings.png)

3. Alternatively, while in the editor, when you press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) to select an intention action from the context menu, press the arrow key next to it to select an option to edit its settings or disable the intention.

![Groovy edit intentions settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_intention_edit_settings.png)

Procedure: Strings in Groovy

With the Show intentions `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) action you can select different intentions for strings such as changing single line into a multiline, add concatenation, convert a literal string into a GString, and so on.

* Convert to multiline: converts a single long line into a multiline. You can break down the line without adding any concatenation. It is helpful for copying and pasting code.

![Convert a strings to a multiline](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_convert_to_multiline.animated.gif)

* Convert into Singleline literal: converts a multiline back into a single long line. In this case, escape sequences `/n` are added. You can continue and select the Break string on /n action to split the line adding the concatenation.

![Convert a                 multiline to a single line](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_convert_to_single_and_break.png)

* Convert to String and Convert to GString: convert a GString into a regular String and vice versa.

![GString to String Conversion](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gstring_to_string.animated.gif)

Procedure: Declare explicit type in Groovy

Among standard declarations, such as creating a field for parameter, or introducing a local variable to a result of expression, IntelliJ IDEA lets you declare an explicit type for the selected variable. Adding explicit declarations, makes code in large projects more readable and sustainable.

* In the editor, press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) on the selected variable and from the list of intentions, select Declare explicit type. To remove it, use the Remove explicit type action.

![Set and remove explicit type](https://resources.jetbrains.com.cn/help/img/idea/2026.2/set_or_remove_explicit_type.animated.gif)

Procedure: Add explicit types to parameters

You can add explicit types for all the parameters in a method declaration for Groovy methods where the types of the parameters are not explicitly defined.

1. In the editor, place the caret at the parameters you need and press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)).

2. From the context menu, select the Add explicit types to parameters.

![add explicit types to parameters](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_add_expl_param.animated.gif)

Procedure: Convert to @CompileStatic

Since Groovy code is compiled dynamically by default, IntelliJ IDEA lets you use the `@CompileStatic` annotation to switch to static compilation whenever this annotation is used.

1. In the editor you can automatically add the @CompileStatic annotation. From the context menu, select `Refactor | Convert to @CompileStatic`.

![Convert to @CompileStatic from context menu](https://resources.jetbrains.com.cn/help/img/idea/2026.2/Convert_at_CompileStatic.animated.gif)

IntelliJ IDEA makes the following adjustments to code:

* The `@CompileDynamic` annotation is added to methods that depend on dynamic language features and which could not be automatically converted.

* An explicit type coercion is added when it’s required.

* An explicit type is added to fields when they can be inferred from field initializers.

* An explicit return type is added to methods.

2. If you added the `@CompileStatic` annotation manually and want to fix the related red code, invoke the Convert to @CompileStatic intention action.

![intention action: convert @CompileStatic](https://resources.jetbrains.com.cn/help/img/idea/2026.2/intention_convert_at_CompileStatic.animated.gif)

Procedure: Change an anonymous class into a dynamic instantiation

You can convert an anonymous class into a closure for better readability.

1. In the editor, select a class you want to convert and press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)).

2. From the list of options, select Change to dynamic instantiation.

![Change to dynamic instantiation](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_change_to_dynamic.animated.gif)

## Recursive calls indicator

When you have recursive calls in your Groovy code, IntelliJ IDEA adds ![the Recursive call](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.gutter.recursiveMethod.svg) in the left gutter as a marker.

![Recursive calls](https://resources.jetbrains.com.cn/help/img/idea/2026.2/recursive_calls_indicator.animated.gif)

## Type annotations

Since IntelliJ IDEA supports the Groovy 3 type annotation [syntax](https://www.oracle.com/technical-resources/articles/java/ma14-architect-annotations.html), the annotations can be placed almost anywhere a type is specified.  It can help you reduce the number of errors within code.

Procedure: Add annotation

1. In the editor, place the caret at the type for which you want to create an annotation and specify its name.

2. Press `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (NetBeans), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS)) and select Create annotation 'name'.

![NonNull annotation](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_nonNull_annotation.animated.gif)

## Support for GINQ in Groovy 4

IntelliJ IDEA provides syntax highlighting, code completion, and inspections for [Groovy Integrated Queries (GINQ)](https://docs.groovy-lang.org/docs/next/html/documentation/#_ginq_a_k_a_groovy_integrated_query) in the Groovy 4 version.

Check the following code example:

![GINQ in Groovy](https://resources.jetbrains.com.cn/help/img/idea/2026.2/groovy_ginq.animated.gif)

## See also

### Reference

[Groovy](groovy.html)

### Procedures

[Run, debug, and test Groovy](getting-started-with-groovy.html)

