Global unused declaration inspection

Thanks to improvements in the internal indexes behind the Intellij IDEA code insight engine, Maia will be able to instantly highlight some java classes, methods and fields which are unused across the entire project.

To use the feature, enable the Unused declarations inspection.

unused members

Of course, all sorts of JEE @Inject annotations, test code entry points
and other implicit dependencies configured in the Unused declarations inspection
are deeply respected.

Comments below can no longer be edited.

21 Responses to Global unused declaration inspection

  1. Avatar

    Eugene Kirpichov says:

    April 27, 2009

    Whoa, this is crazy cool! Can’t wait for the first EAP.

  2. Avatar

    JBaruch says:

    April 27, 2009

    Long waited, indeed. Great stuff!

  3. Avatar

    Eugene Kirpichov says:

    April 28, 2009

    By the way, shouldn’t this entry be also tagged “maia”?

  4. Avatar

    plt says:

    July 8, 2009

    It is really cool! Helps me to found bug occured due wrong resolving.
    Thanks a lot!

  5. Avatar

    James says:

    July 10, 2009

    Very exciting news! I can’t wait to run it against our diseased codebase 🙂

  6. Avatar

    Jan says:

    October 7, 2009

    Is there a way to disable this inspection for public methods? I still like the inspection to warn me about unused private/protected/package_private methods, but not for public methods.

    The problem with this feature is that it doesn’t work well if you are developing an API of some sort, on which other projects (outside the scope of the currently opened IDEA project) depend.

    Don’t get me wrong, I like this feature, but I would also like to configure it differently for public and non-public methods.

  7. Avatar

    Ran Biron says:

    October 15, 2009

    What about recursive global unused declarations? possibly with “remove entire declaration tree” action?

  8. Avatar

    Osvaldas Grigas says:

    November 17, 2009

    I second Jan. There are many public methods in our project that are invoked through reflection, e.g. through Spring XML configuration. So now I see warnings everywhere, which is frustrating because I know these methods are used. I could turn Unused declarations inspection off, but then I would also lose notifications of unused private methods, and that would be a shame.

  9. Avatar

    Andreas says:

    November 23, 2009

    +1 to Jan. There should be an option to disable public declarations, but to keep it for other scopes.

  10. Avatar

    Lucas says:

    December 9, 2009

    I agree with you, Jan. There should be an option to disable this feature for public methods.

  11. Avatar

    Tomasz says:

    December 14, 2009

    Agreed with Jan – this feature made one of the most important inspection useless. Public methods should be excludable from the inspection!

    Hope Jetbrains issue a fix soon.

  12. Avatar

    n says:

    January 13, 2010

    Partly agree with Jan – but with a caveat:

    The optimal solution would be if this was configurable so that a project could specify whether:

    – all public declarations will be excluded from inspection (suitable for some libraries etc, or for projects with lots of reflection or injection etc)

    – declarations that are tagged as unused could be marked as “ignore usage – it really is in use I say!” – suitable for projects that have some reflection/injection/other reasons

    – the project has a set of “entry points”, e.g. a set of interfaces/classes that define the “really public” part of your library, and remaining public declarations are checked for usage. This is due to the missing modularization support in Java, with Java7 this feature would be even more useful (but require modification/extension).

    The last option would be extremely useful for me in my project!

  13. Avatar

    Chris says:

    January 29, 2010

    +1 to Jan. A great feature rendered virtually useless. And there doesn’t appear to be a fix in the 9.0.2 release..

  14. Avatar

    Alexey Kudravtsev says:

    January 29, 2010

    To disable the inspection for public methods, turn off the “Settings|Inspections|Declaration redundancy|Unused declaration” global inspection.

  15. Avatar

    Szilard says:

    August 4, 2012

    +1 to Jan
    I have recently upgraded from 8 to 11.
    Money out the window.
    This is extremely annoying.

    If you disable this feature, it will disable it everywhere, e.g. unused private declarations too.
    It used to be a great feature – until rendered completely useless … 🙁
    From the developers of a commercial product I would expect to pay more attention to the users’ problems.

  16. Avatar

    Alexey Kudravtsev says:

    August 6, 2012

    Hello @Sziland, once again:
    if you want to highlight unused public methods, please enable the “Settings|Inspections|Declaration redundancy|Unused declaration” global inspection.
    if you want to highlight unused private methods, please enable the “Settings|Inspections|Declaration redundancy|Unused symbol” local inspection.

    So, if you want to highlight unused private members, but do not highlight unused public members, turn off “Unused declaration” and turn on “Unused symbol”.

  17. Avatar

    Clinton Foster says:

    June 23, 2014

    I’m struggling with this same issue. Alexey, perhaps this dialog has changed since you posted your reply? I can’t figure out how to retain the “unused declaration” warning for methods declared as “private”, but turn them off for default, package and public methods. This should certainly be the default. Second best would be to make it configurable. I have to believe this is possible since otherwise it would render one of the most useful inspections useless (as pointed out by others).

    It has been a few years since I’ve used Intellij, so it could very well be that I just don’t understand how the configuration dialogs work.

  18. Avatar

    Lucas says:

    July 7, 2015

    It had been 6 years since Jan comment, and the annoying is still there… 🙁

    • Avatar

      Ivan Sopov says:

      October 8, 2015

      There was a solution with “Unused symbol”, but now it is gone.

  19. Avatar

    Tati says:

    November 27, 2015

    A problem that was created in 2009. Fixed sometime in 2010. Rebroken after that. And up until now, it still isn’t fixed. smh. Is anybody there available to give a solution to this issue? I have tested with my new IDE… and it’s broken.

  20. Avatar

    Basheer Almomani says:

    October 7, 2018

    can we have “initialize it in the constructor” add to quick fix options alongside with the current fixes in the list like “add parameter constructor”

Discover more