我已经对声纳 cpd 如何检测重复块进行了很多分析。但是我无法准确触发检测块或代码行所需的过程。是否有最小行数。
例如,如果我按如下方式编写,即使我重复超过 20 次,它也不会检测到任何代码重复。
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
System.out.println("this is good");
后来我尝试给予块重复
try
{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try
{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
try{
connection = null;
}
catch(Exception e){
e.printStackTrace();
}
这里它被视为两个块,即使它有很多块。
请让我知道声纳 3.4.1 进行重复检测的确切过程
在这个 http://docs.sonarsource.org/3.1/apidocs/src-html/org/sonar/plugins/cpd/SonarEngine.html
我发现块大小恒定为 10。但我能够在我的观察中将其联系起来。
块是平衡大括号之间的代码行。块大小恒定意味着块中必须有 10 行代码进行匹配。所以要复制试试这个。
public void foo(){
//... 10 lines of code
}
private void bar(){
//.... the same 10 lines of code
}