Intellij IDEA doesn't grey out some unused methods

后端 未结 3 702
别跟我提以往
别跟我提以往 2021-01-17 17:08

In intellij IDEA, if a method is unused, the method is shown in a gray color. But in some cases, IDEA doesn\'t grey out the method, but when I check the references of those

3条回答
  •  生来不讨喜
    2021-01-17 17:31

    It might be a bug if you're using a method with a very common name.

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

    I had a very common named method, named "stop".

    • Looking for usages (using ALT + F7) didn't show anything.
    • Analyzing the whole project, clearly showed that this method did not have any use.

    Despite that, the method was still yellow.

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

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

    My advice is to just not name your methods as something that may be written in a TODO comment.

    See this image, where I am using a method named "stop" :

提交回复
热议问题