Unused declaration shown in right tripe but not in analysis results
Answered
Hi,
I use default inspection settings with 2016.1.1. when I run Analyze | Inspect Code on current Java file, there is one warning - class is not used. However on right stripe I see warnings for class methods. When I add the class to entry points and run analysis again, the result shows all the not used methods. It make sense not to show not used methods when the class itself is not used. I think this should work for right stripe too but it is reversed, no mark for class itself, but marks for all not used methods. Is this intentional?
Kind regards, Jan
Please sign in to leave a comment.
Unused classes are detected by Analyze | Inspect Code only, unused methods are detected on-the-fly, this behavior is by design.
Thank you for your support. I was not correct with above statement, in my opinion there is a bug in on-the-fly declaration not used. It shows that class is not used and at the same time also that the (public) methods are not used. In my opinion, when class is not used it should not show warning for public methods too. Also I don't fully understand the concept of entry points. When I add class as entry point, the warning about class not used disappears but there is still warning about not used public methods. Again IMHO when class is marked as entry point, IntelliJ it should not warn about unused public methods.
Kind regards, Jan
See the related issues:
https://youtrack.jetbrains.com/issue/IDEA-121289
https://youtrack.jetbrains.com/issue/IDEA-116609
Thanks, voted, Jan
Hi again,
I was browsing sources to better understand it as this is quite unpleasant for me. I have lot of classes that are used by reflection and the right stripe is full of warnings with no easy way to turn them off. At the same time I don't want to miss unused non-public method or field. Here are my conclusions:
* one can probably write a plugin that will add checkbox and implementation for Unused declaration Java inspection on Entry point tab just like Android, TestNG and other stuff are added, only Main, Applet and Servlet are "baked in"
* unfortunately, as you pointed out, the unused declaration on the fly ignores the selection of entry points above and also entry points added by user to EntryPointManager. In fact there is no extension point at all, probably because of speed considerations
* it is easy to fix the on the fly inspection not to show unused public methods when class is not used, just few lines, details in https://youtrack.jetbrains.com/issue/IDEA-121289
* I have read the How to contribute code. However the very first question is whether you want this feature to be changed? Is there someone who can answer this for me? I did not found forum dedicated to community or does that work through Git channels?
Kind regards, Jan