检查 Java 文件是否有 == 错误,不限于字符串
许多标准源代码检查工具(PMD、FindBugs、Checkstyles)都实现了“字符串相等”规则,其中使用 ==
(或 !=
)可以检测到比较字符串并将其报告为错误。
我希望编写(或配置!)一个类似的规则,该规则适用于我的 API 中的一组其他对象类型。
//Want to detect things like:
Instance a = ...;
Instance b = ...;
if ( a == b ) //Error here, not using a.equals(b)
看看 PMD 和FindBugs 没有明显(或简单)的方法来做到这一点,有人遇到过这样的事情吗?
干杯, 罗
Many of the standard source code checking tools (PMD, FindBugs, Checkstyles) all implement a "String Equality" rule, where the usage of ==
(or !=
) when comparing strings can be detected and reported as an error.
I'm looking to write (or configure!) a similar rule that works on a set of other object types in my API.
//Want to detect things like:
Instance a = ...;
Instance b = ...;
if ( a == b ) //Error here, not using a.equals(b)
Looking at PMD & FindBugs there is no obvious (or easy) way to do this, has anyone come across something like this ?
Cheers,
Ro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PMD 中的 CompareObjectsWithEquals 不适合您吗?
Doesn't CompareObjectsWithEquals in PMD work for you?