The Sensei IntelliJ plugin lets you create searches to match on code implementing a pattern you want to change, and then create code amendment quickfixes to automatically change the code.
This section will walk through the main parts of the GUI and how we can use them.
From here we can show the Recipe Editor tool window which will list all the ‘cookbooks’, or lists of recipes, that you have available.
This tool window also allows us to add and remove cookbooks, and change their location.
The checkboxes on this tool window can switch cookbooks on and off. And you can use the
Sensei Cookbook tab on the bottom of the screen to navigate back
here when needed. You don’t have to use the main Sensei menu.
Recipes in the project's
.sensei folder have been
You can manage them to see what recipes are available by clicking the Manage recipes button.
Each recipe has configuration with the name and description and warning level which all configure how they are rendered in the IDE when code matches the pattern in the search.
By clicking on a Recipe, you can edit it.
The Recipe Editor has four main components.
The list of recipes where we can add, delete, and duplicate recipes
The General Settings tab where we can configure the recipe
Recipe Settings tab where we create the search and matching conditions
QuickFix settings where we configure the Quick Fix changes to amend or generate code
General Settings is where we primarily configure the:
Name and Description, which are shown in the contextual popup when we hover the mouse over a violation in the code.
Level, which defines how the matching Recipe is rendered in the IDE
If you configure a recipe as ‘Error’ then the code will typically have a red underline and show as a syntax error, but a Warning will have a light highlighting. Sensei will use the highlighting properties of the IntelliJ 'Error'/'Warning'/'Info' levels by default.
There are other settings but these are for more advanced use and will be covered later in the documentation.
The ‘Recipe Settings’ contains the search configuration.
This is the search we perform in the code to match coding patterns.
In this example the search is for any annotation on a method which are a Junit 5 Test annotation.
And you can see the annotations in the code have been highlighted in the code itself.
If the annotation type was changed then the code would not match, so we can visually see if our searches would match for the code we are working with.
The QuickFix Settings are the QuickFixes which are shown in IntelliJ when you use Alt + Enter or ⌘ Cmd + ↵ Enter to fix the problem.
And you can see at the bottom of the screen a diff view that shows the results of applying a QuickFix.
The recipe shown in the screenshot adds a
Logger into the class and
the diff view shows the before and after state in the code.
In the code, usually at the point you want to start a search.
Pressing Alt + Enter or ⌘ Cmd + ↵ Enter shows the context menu to create a recipe.
Often we ‘start from scratch’ with an empty recipe.
A recipe can also be created by clicking the
+ button in the Recipe Editor.
When recipes have been activated, they will be marked in the editor.
The following code shows some ‘errors’ and some ‘warnings’ have been found in the code.
There are many ways to apply a QuickFix.
In the Problems Tab.
Right click on the reported problem and choose “Show Quick Fixes”
Then choose the quick fix from the list.
The most common way to fix code is with Alt + Enter or ⌘ Cmd + ↵ Enter where we will see any Intellij suggestions and Sensei quickfixes.
And if you choose the action then the code will be amended.