(Public) Method 'xxx' is never used ...
I am a bit surprised that a "public" (or even protected) method of a class that is not called from the class itself (or the current project) is actually highlighted as being never used. Well, my point is although this is (superficially) a correct or intended inspection, I also think that public interface (public methods) of a class is something that is intended for public use if/when you release your code. From this standpoint, it's not all that fair to flag unused (in this scope: projects open in IntelliJ) public methods should /not/ be given a wavy underline by inspector by default. Regards, Kedar
Please sign in to leave a comment.
If you treat the whole project as self-contained, then marking obsolete
public methods as obsolete is a fine way to detect bugs or cleanup the code.
If you are developing a library or use nasty generics to access the methods,
disable this intention.
Tom
Hi Kedar,
indented way to get rid of the warnings is to create a scope for your API classes and disable the inspection for that scope.
Fair enough.
On Sun, 01 May 2011 05:21:01 MSD, Kedar Mhaswade
<kedar.mhaswade@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>I am a bit surprised that a "public" (or even protected) method of a class that is not called from the class itself (or the current project) is actually highlighted as being never used. Well, my point is although this is (superficially) a correct or intended inspection, I also think that public interface (public methods) of a class is something that is intended for public use if/when you release your code. From this standpoint, it's not all that fair to flag unused (in this scope: projects open in IntelliJ) public methods should /not/ be given a wavy underline by inspector by default. Regards, Kedar
I will not complain if there are other packages in the same compile
unit use the public methods. It is just warning, that could indicate
a typo, you thought you were overriding when you weren't for example.
It can also be useful information about where you can prune some fat.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Politicians complain that Kindles and iBooks are killing jobs by
destroying the paper book industry. I see it that they have create a way
to produce books for less than a third the cost without destroying forests
and emitting greenhouse gases in the process. They have created wealth.
They are encouraging literacy and cutting the costs of education.
Not fair enough by me.....please let me just turn them off.
In many cases this is just a silly and pointless inspection that detracts from real issues. I would prefer to simply turn it off completely and from scouring the net, I am not the only one.
I don't want to create API scopes, I don't want to mark them with annotations.... I just want to switch them off.
It's my code, I bought and paid for my IDE and I absolutely hate being forced into someone else's fuzzy, ill thought-out ideas of good practice.
Hello Tom,
Of course you can turn it off. Settings | Inspections | Declaration redundancy
| Unused declararation.
And we really don't think that "having no dead code in your project" is a
fuzzy and ill thought-out practice.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Can I just turn it off for public methods, public enum fields etc? That's the issue at heart to be honest.
You see, I agree with you that having no dead code is a good idea and a good inspection to have. It's the practice of warning me about unused *public*, and to an arguably much lesser extent, protected and default code that it cannot possibly know is used or not, that isn't great. Especially when there is (seemingly) no way to isolate the inspection according to the code's access level.
Thanks for the quick response.
Hello Tom,
Turning off this specific inspection will turn off editor highlighting for
unused public members. Unused private members will still be highlighted.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
I am just running into this - and I have to agree with Tom here. Having to create a bunch of scopes to achieve what should otherwise be an easy option is a major PITA. A method/enum declared as "public" should be treated as such.
If enabling an option like this would have the effect of disabling the syntax highlighting, etc. then please fix this so it doesn't do that. I believe IntelliJ IDEA does the right thing here for Java.
Having to sift through a bunch of warnings of no consequence just to find the ones that are of actual value diminishes the overall value of warnings as such, and thus that of the IDE.
Hello Paul,
In the inspection's settings (Java | Declaration redundancy | Unused declaration) you can define the members to report including public fields and methods.
My bad - my google search for a CLion issue landed me here, so I thought I was on a CLion support page. IntelliJ works just fine.
Paul Tomas,
Thank you for confirming it works!:)