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...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...