Custom Inspection for missing annotation

Answered

We have some classes that require a specific custom annotation, based on their class name. I wanted to add a custom inspections that triggers a warning, whenever this annotation is missing from such a class. Is this possible with the Structural search approach? I couldn't find any examples that search for missinb attributes, only for existing ones and then doing some validation on them. Or would this require the approach with a custom plugin?

1 comment
Comment actions Permalink

Hi, you could use Structural search for this.
There is a Count filter that can specify the number of occurrences: https://www.jetbrains.com/help/idea/search-templates.html#count_filter

You could also click the wrench icon in this dialog, check the Existing Templates -> Not annotation methods to know how to use it.

An example for your use cases

1

Please sign in to leave a comment.