Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

If you use IntelliJ's inspection features to highlight unused methods and you work with web services you will probably find yourself in this bind. The @WebMethod annotated methods in your service endpoint interface (SEI) class will be flagged as never used. This is because typically you would't be writing test cases for this class as it shouldn't contain any business logic and should delegate to other classes (if you have logic in your SEI, you should be re-writing it!)

The result is a bunch of never used indicators...

It's actually fairly simple to just go and disable inspection for unused methods globally - in Preferences go to Editor > Inspections > Java > Declaration redundancy > Unused declaration and untick Methods, however that's not what I'm trying to do here.

There is another obvious answer to how to disable this inspection on a specific method, use the @SuppressWarnings annotation on the method like this...

That, ultimately, is what I want to do, but hey I'm lazy and I don't want to have to type this out every time. So there just so happens to be a feature in IntelliJ to add this annotation for you. By clicking on the method name and pressing Alt-Enter (or clicking on that light bulb popup) to bring up the contextual menu you will get this...

On the Safe delete menu item, press the right arrow on the keyboard (or click that little triangle on the far right) and it will bring up another menu.

Well, now that's more like it! This new menu gives a whole slew of options for suppressing that inspection. Pick whichever one you need and get on with it! In my case I like to control this suppression on a method-by-method basis so I picked the last option and IntelliJ produced this, as expected...

Enjoy your warning free SEI!


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.