Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.
Notice: I'm taking a break from blogging to focus on Atari Gamer . com, check it out!

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
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!


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