(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

8 comments
Comment actions Permalink

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

0
Comment actions Permalink

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.

0
Comment actions Permalink

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. 


0
Comment actions Permalink

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.

0
Comment actions Permalink

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.

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.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

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.

0
Comment actions Permalink

Hello Tom,

Turning off this specific inspection will turn off editor highlighting for
unused public members. Unused private members will still be highlighted.

Can I just turn it off for public methods? 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.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.