Intellij IDEA does not highlight some unused methods

In intellij IDEA, if the method is not used, the method is grayed out. But in some cases, IDEA does not highlight this method, but when I check the references to these methods with alt + F7, IDEA says that the method is not used.

Is this an IDEA bug, or is there any reason that IDEA will not serostatize these specific methods? If this is an error, is there a workaround for IDEA to detect that this method is not used?

+8
source share
3 answers

Most likely, this is not a mistake, this is a limitation for performance reasons. Methods that can last a long time when searches are scanned are skipped.

The workaround is to start checking the unused declaration explicitly in all your projects through Analysis | Code Verification or Analysis | Run check by name. It will take some time. You can also set up a TeamCity server to do this automatically for you every night.

+6
source

It used to work like a charm, but once I mistakenly pressed alt + Enter for an unused method and decided to cancel checking the unused code. Since then, I stopped receiving inactive methods and code, so since there is a way to cancel it, there must be a way to get it back to work.

After 5 minutes of searching, I found a solution:

Settings -> Editor -> Checks -> Java -> Redundancy Declaration -> Unused Declaration

Make sure you check "Unused declaration"

And I just checked by creating a new useless method that works like a charm.

+1
source

This may be a mistake if you use a method with a very common name.

If you tried the @Peter Gromov method above and your method is still yellow, this might be a mistake.

I had a very common method called "stop".

  • A search for use (using ALT + F7) showed nothing.
  • Analyzing the entire project, he clearly showed that this method had no use.

Despite this, the method still remained yellow.

I was surprised to learn that if I try to refactor a method name, I will get a pop-up warning that this will change in other places.

It turns out that refactoring warned about changing the method name in the TODO comments. Somehow, Lint recognized TODO comments using this method.

My advice is simply not to call your methods something that can be written in a TODO comment.

Look at this image where I use a method called stop: enter image description here

0
source

All Articles