mindas
mindas

Reputation: 26713

Telling IntelliJ IDEA which methods not to identify as unused

IntelliJ IDEA has a handy feature to detect unused methods and show them in grey, hinting a potential warning for dead code.

Some methods, however, are not executed directly but via reflection. A good example would be @RequestMapping-annotated methods which are executed by Spring. IntelliJ has decent Spring integration hence it detects this annotation and does not mark such a method as unused.

I have a tiny AJAX framework where I use my own annotation to point which method to execute based on certain HTTP request properties (very similar to what @RequestMapping is doing). Understandably, IntelliJ has no idea what does my annotation stand for and and marks such a method as unused, adding unnecessary noise.

I was thinking of:

Can anyone suggest any ideas how to solve this problem?

Upvotes: 69

Views: 23531

Answers (4)

In case anyone is finding trouble with this at the moment, here is how you can configure it in IntelliJ IDEA's current version: Route viewn

File > Settings > Editor > Inspections > Unused declaration > Entry Points > Annotations... > Mark as entry point if annotated by

Really useful for @Beans!

Upvotes: 1

Zarathustra
Zarathustra

Reputation: 2943

@Peter Lawrey s solution did not help in my version of Intellij (14.1.1).

I used the hard way around:Settings-Editor->Inspections->Unused declarion Now there is an Options point, scroll down to Configure annotations... and you can add your annotation there.

Upvotes: 7

Peter Lawrey
Peter Lawrey

Reputation: 533520

You can tell IntelliJ to not to warn about used for any method/field annotated with the annotation the "unused" method has.

It should be a quick fix all you have to do is hit <Alt>+<Enter> and select Suppress for methods annotated by ...

You don't need to add anything to you code and you only have to do this once per annotation.

enter image description here

Upvotes: 99

Vance Maverick
Vance Maverick

Reputation: 822

@SuppressWarnings("unused") should work.

Upvotes: 50

Related Questions