This project has moved. For the latest updates, please go here.
1

Closed

Doesn't recognize constans as different

description

I have two classes that defines a couple of "public const string". But although the constants are not even named the same and don't have the same value Clone Detective consders the code to be the same.

For constants and Clone Detective should extend the compariason to include the name and perhaps the value in order to remove false positives.

--------- Extract from file one -----------------
            private const string ATTRIBUTE_NAME        = "Name";
    private const string ATTRIBUTE_NUMBER      = "Number";
    private const string ATTRIBUTE_TEXT        = "Text";
    private const string ATTRIBUTE_ID          = "ID";
-------- Extract from file two ----------------
            public const string ISSUE_ID                = "ISSUE_ID";
    public const string ISSUE_NAME              = "ISSUE_NAME";
    public const string ISSUE_STATE_ID          = "ISSUE_STATE_ID";
    public const string ISSUE_TYPE_ID           = "ISSUE_TYPE_ID";

file attachments

Closed Jan 15, 2010 at 12:53 PM by

comments

wrote Jan 15, 2010 at 12:53 PM

Hi buurd,


 


Normalization of identifiers, literals, and constants is a crucial step for clone detection; without it, in most systems no clones would ever be found. Consider the following scenario:


 


--- File1 ---


for (int i = 0; i >


}


 


--- File2 ---


for (int j = 0; j >


}


 


Actually those two snippets are clearly clones, but without normalization of identifiers (equal treatment of "i" and "j") and constants (equal treatment of values 10 and 20) they wouldn't be reported as such. So, removing constant normalization is clearly not an option without taking the hit of a much larger number of false negatives.


 


That said I have to fully agree with you that for your code reporting all those instances does really make no sense at all! For this purpose, we added the capability to further tailor the clone detection to your requirements into Clone Detective for Visual Studio. That way, you can exclude lines matching any defined regular expression from detection. Unfortunately, the process is a bit cumbersome in the current release - this is one thing we're planning to address in the next version (see work item #10774, http://clonedetectivevs.codeplex.com/WorkItem/View.aspx?WorkItemId=10774 (http://clonedetectivevs.codeplex.com/WorkItem/View.aspx?WorkItemId=10774) ). Here's what you have to do:


 
  1. Copy the %CloneDetectiveInstallDir%\DefaultCloneDetection.cqa file into your solution folder.
  2. In Clone Explorer, enable custom clone detection for the current solution. For the analysis file name, select the previously created .cqa file in your solution folder.
  3. Inline the processing instructions in the CsCloneChain block. I've already done this for you - please find the file attached.
  4. Add regex patterns for matching lines you want to exclude from clone detection.
 


Hope that helps, Thomas

wrote Jan 15, 2010 at 12:57 PM

Just to be clear: You can either copy the DefaultCloneDetection.cqa file and inline the CsCloneChain block manually or use the file I uploaded as attachment. In both cases, you have to enable custom clone detection and add regex patterns of lines you want to exclude.