Global unused declaration inspection

April 27th, 2009 by Alexey Kudravtsev

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.

Tags: , ,

14 Responses to “Global unused declaration inspection”

  1. Eugene Kirpichov Says:

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

  2. JBaruch Says:

    Long waited, indeed. Great stuff!

  3. Eugene Kirpichov Says:

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

  4. plt Says:

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

  5. James Says:

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

  6. Jan Says:

    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. Ran Biron Says:

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

  8. Osvaldas Grigas Says:

    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. Andreas Says:

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

  10. Lucas Says:

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

  11. Tomasz Says:

    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. n Says:

    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. Chris Says:

    +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. Alexey Kudravtsev Says:

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

Leave a Reply