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.

This entry was posted in New Features and tagged , . Bookmark the permalink.

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

  15. Szilard says:

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

    Alexey,
    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. Alexey Kudravtsev says:

    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. Clinton Foster says:

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">