Find all unused variable

前端 未结 4 1332
鱼传尺愫
鱼传尺愫 2021-02-08 21:36

Normally it\'s easy to see unused variables in Netbeans, just a grey squiggly line.

But how would I find all of these unused variables in my project or of a single clas

相关标签:
4条回答
  • 2021-02-08 22:10

    In Eclipse, that gray squiggly line is a yellow squiggly line called a Warning. Then the warning is propagated up to the package level, and up to the project level (such that your project is almost always underlined in yellow with a warning icon). Anyway it really helps you see which source files have warnings in them.

    Then your task is to solve every warning in the entire project, and you will have caught the unhandled variables.

    I assume netbeans has the same feature somewhere.

    0 讨论(0)
  • 2021-02-08 22:22

    You could run something like FindBugs on it.

    FindBugs

    Looking at the bug list it has

    UuF: Unused field (UUF_UNUSED_FIELD) This field is never used. Consider removing it from the class.

    You could filter on just this, but it is a good idea to run this on all code all the time, it is amazing what it finds.

    0 讨论(0)
  • 2021-02-08 22:24

    PMD will find unused local variables for you (among many other things). There's a NetBeans plugin that I give installation instructions for here (Warning: Shameless Plug, that links to my blog).

    0 讨论(0)
  • 2021-02-08 22:27

    The compiler will warn about unused variables giving you your list.

    Unused method variables will be removed by the compiler but unused member variables remain, which depending on the state of your codebase may make this a cosmetic problem that can be handled as and when each file is modified rather than a conserted effort to remove all unused variables in one go.

    Saying that, I generally like my builds to run with no warnings, so that when I genuinely break something I notice the warning. Maybe this is the clean-up you are looking for ;-)

    0 讨论(0)
提交回复
热议问题