简体   繁体   English

声纳 CPD 检测块重复

[英]Sonar CPD detecting blocks duplications

I have done so much analysis on how sonar cpd detects duplicate blocks.But I am not able to trigger out exactly what the process it takes to detect blocks or lines of code.Do that have any minimum number of lines.我已经对声纳 cpd 如何检测重复块做了很多分析。但我无法准确触发检测块或代码行所需的过程。是否有任何最少行数。

For example if I am writing as below it is not detecting any code duplications even I repeat more that 20 times.例如,如果我写如下,即使我重复超过 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");

Later on I tried giving blocks duplications后来我尝试给块重复

     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();
    }

Here it is considering as two block even though it has many blocks.即使它有很多块,这里也将其视为两个块。

Please let me know the exact process followed in this duplication detection by sonar 3.4.1请让我知道声纳 3.4.1 在此重复检测中遵循的确切过程

In this http://docs.sonarsource.org/3.1/apidocs/src-html/org/sonar/plugins/cpd/SonarEngine.html在这个http://docs.sonarsource.org/3.1/apidocs/src-html/org/sonar/plugins/cpd/SonarEngine.html

I found a constant block size as 10. But I am able to relate this in my observation.我发现一个恒定的块大小为 10。但我能够在我的观察中将其联系起来。

A block is the lines of code between balanced braces.块是平衡大括号之间的代码行。 The constant block size means that in the block there must be 10 Lines of code to match.恒定块大小意味着在块中必须有 10 行代码来匹配。 So to have a duplication try this.所以要复制试试这个。

public void foo(){
//... 10 lines of code
}

private void bar(){
//.... the same 10 lines of code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM