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...
suppress_1.png


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...
 Java
@SuppressWarnings("unused")


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...
suppress_2.png




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.
suppress_3.png


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...
suppress_4.png


Enjoy your warning free SEI!

-i

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

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.
 
comments powered by Disqus
Other posts you may like...