How to check “The value of the local variable/field is not used” in Checkstyle?

落花浮王杯 提交于 2019-12-08 00:42:44

问题


How to check The value of the local variable is not used and The value of the field is not used using Checkstyle? In Eclipse there is a warning about that. But there's no in Checkstyle (i use sun_checks.xml, slightly modified).

I tried to write my own check, but being a newbie, only found how to calculate variable declarations (using TokenTypes.VARIABLE_DEF), but i am not sure how to find namely usage of these variables and fields...


回答1:


Checkstyle can't do that, I'm afraid, but PMD (rule) and FindBugs (rule) can.

Checkstyle and PMD operate only on the Java source, and it is harder to deduce field and variable use only from the source. FindBugs operates on the compiled class files, so it has an easier job in this case. PMD can only detect unused private fields and variables, which can be found by looking at a single source file.

Writing an "unused private field/variable detector" for Checkstyle is possible, if tedious. I would recommend going with the PMD tool for this, which also features a light-weight Eclipse plugin.



来源:https://stackoverflow.com/questions/20116032/how-to-check-the-value-of-the-local-variable-field-is-not-used-in-checkstyle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!