FindBugs 自定义检测器来检查变量命名

FindBugs custom detector to check variable naming

我正在开发一个自定义的 findbugs 插件,它可以在 java 个类中发现变量命名错误。

例如 Button 变量必须以 btn* 开头,如果不是,请报告。

Button btnSave; // It's ok
Button close; //Report it, not starts with btn

我已经在这个项目上工作了好几天。我可以检测方法命名错误、方法 return 值错误等。但我无法检测 - 这个简单的变量命名错误。 我尝试了很多代码片段,findbugs 文档是对这种情况没有帮助。

此外,我无法调试我的自定义插件项目,每次更改都会占用我的时间。

谢谢。

FindBugs 是一个在 bytecode 上运行的代码分析器。变量名是源代码的属性。

您最好使用不同的静态分析器,例如在源代码上运行的 PMD。

另见 What are the differences between PMD and FindBugs?