VS2013 RC で [Analyze] > [Analyze Solution for Code Clones] を選択し、次の 2 つの方法が認識されることを期待しています。
private static char GetBarcodeChecksumWithLegacyCode(string barcodeWithoutCzechSum)
{
Contract.Requires(!string.IsNullOrWhiteSpace(barcodeWithoutCzechSum));
if (barcodeWithoutCzechSum.Length > 6)
{
int a = 0;
int b = 0;
int j = barcodeWithoutCzechSum.Length - 1;
int i = j;
while (i >= 0)
{
a = a + barcodeWithoutCzechSum[i] - 48;
i = i - 2;
}
j = barcodeWithoutCzechSum.Length - 2;
i = j;
while (i >= 0)
{
b = b + barcodeWithoutCzechSum[i] - 48;
i = i - 2;
}
a = 3 * a + b;
b = a % 10;
if (b != 0) b = 10 - b;
var ch = (char)(48 + b);
return ch;
}
return ' ';
}
public static string GetBarcodeChecksum(string barcode)
{
int oddTotal;
int oddTotalTripled;
int evenTotal;
// Which positions are odd or even depend on the length of the barcode,
// or more specifically, whether its length is odd or even, so:
if (isStringOfEvenLen(barcode))
{
oddTotal = sumInsideOrdinals(barcode);
oddTotalTripled = oddTotal * 3;
evenTotal = sumOutsideOrdinals(barcode);
}
else
{
oddTotal = sumOutsideOrdinals(barcode);
oddTotalTripled = oddTotal * 3;
evenTotal = sumInsideOrdinals(barcode);
}
int finalTotal = oddTotalTripled + evenTotal;
int modVal = finalTotal % 10;
int czechSum = 10 - modVal;
if (czechSum == 10)
{
return "0";
}
return czechSum.ToString();
}
...機能的に同等です。1 つ目は不可解で、2 つ目 (私にとっては、おそらく私が書いたものだから) は明白です。ただし、ツールはそれらを「コード クローン」とは見なしません。
私のメソッドが他のメソッド、つまり isStringOfEvenLen()、sumInsideOrdinals()、および sumOutsideOrdinals() を呼び出しているためでしょうか?