[英]PMD CPD exclude methods like equals and hashcode?
I cannot find an option how to tell PMD-CPD to skip specific methods. 我找不到如何告诉PMD-CPD跳过特定方法的选项。 We use generated
equals()
and hashCode()
methods, so the methods look often very similar and CPD reports a lot of them as duplicate code. 我们使用生成的
equals()
和hashCode()
方法,因此这些方法看起来非常相似,并且CPD将很多方法报告为重复代码。
I can use some //NOPMD
comments in the code, but what is in my eyes not a way how to manage my code. 我可以在代码中使用一些
//NOPMD
注释,但在我看来,如何管理我的代码并不是什么方法。 Since I incorporate a tool into code what has nothing to do with the code. 因为我在代码中加入了一个与代码无关的工具。 CPD helps to avoid coding errors/styles and should not force me to modify my code.
CPD有助于避免编码错误/样式,不应强迫我修改我的代码。
So would be really helpful if someone have some ideas how to solve it. 如果有人有一些想法如何解决它,那将会非常有用。
best wishes 最好的祝愿
PMD CPD has no such option, so short of filing a feature request, it is not possible. PMD CPD没有这样的选择,因此没有提交功能请求,这是不可能的。
However, you could use annotations for suppression as described in the CPD docs : 但是,您可以使用注释进行抑制,如CPD文档中所述 :
//enable suppression
@SuppressWarnings("CPD-START")
public Object someMethod(int x) throws Exception {
// any code here will be ignored for the duplication detection
}
//disable suppression
@SuppressWarnings("CPD-END")
public void nextMethod() {
}
Personally, I don't like this syntax very much, because it makes you annotate completely unrelated methods. 就个人而言,我不太喜欢这种语法,因为它会让你注释完全不相关的方法。
nextMethod()
has nothing to do with someMethod()
, but still gets the CPD-END
annotation. nextMethod()
与someMethod()
无关,但仍然获取CPD-END
注释。 But it may stil be better than putting a whole lot of //NOPMD
comments. 但它可能比放置大量
//NOPMD
评论更好。 It also excludes the method only for CPD, but not for other PMD detectors, as //NOPMD
would. 它也排除了仅用于CPD的方法,但不包括其他PMD检测器,如
//NOPMD
。
Your initial wish of not putting information for analyis tools into the code is understandable. 您最初希望不将分析工具的信息放入代码中是可以理解的。 However, when I think about it, the annotations and comments do say something about the code, so having the code's meta information in the source is not such a bad thing.
但是,当我考虑它时,注释和注释会对代码做一些说明,因此在源代码中使用代码的元信息并不是一件坏事。 If you still don't like it, consider using SonarQube or some other tool with a database behind it.
如果您仍然不喜欢它,请考虑使用SonarQube或其他工具及其背后的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.