IntelliJ IDEA 2021.1 Help

Create custom inspections

To create a custom inspection, you have to configure a search and replace templates. The IDE will search for code that matches the template and will highlight it in the editor.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Editor | Inspections.

    You can also press Ctrl+Alt+Shift+H and select Configure Inspections.

  2. Select the profile in which you want to create a new inspection.

  3. On the toolbar, click the Add Structural Search Replace Inspection and select Add Search Template if you want your inspection only to highlight code, or Add Replace Template if you want your inspection to highlight code strings and suggest fixes.

    Adding a new Structural Search and Replace inspection

  4. Configure the templates.

    You can use a sample template and configure it according to your needs. To do so, click the Tool button and select Existing Templates and then select the suitable one.

    For more information on how to configure search and replace templates, refer to Search Templates.

    The Structural Replace dialog
  5. When finished, click the Tool button and select Save Template as Inspection.

  6. In the dialog that opens, name the new inspection, specify a tooltip, description, and provide a suppress ID if necessary (@SuppressWarnings("suppress id") ). The default suppress ID for custom inspections is SSBasedInspection.

  7. Apply the changes and close the dialog.

After that, your custom inspection is going to appear in the list of inspections of the current profile under the Structural search category. There, you can change its severity and the scope in which this inspection will run.

Note that the Structural search category is not available until you create at least one custom inspection.

Custom inspection shown in the list of inspections

When your inspection is ready, you can run it.

Last modified: 15 June 2021