fix for 1203536 - corrected calculation of cyclomatic complexity metric
This commit is contained in:
parent
adc04337ea
commit
829cb74749
|
|
@ -20,7 +20,6 @@ package com.puppycrawl.tools.checkstyle.checks.metrics;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
||||
|
||||
/**
|
||||
* Checks cyclomatic complexity against a specified limit. The complexity is
|
||||
|
|
@ -57,10 +56,7 @@ public class CyclomaticComplexityCheck
|
|||
TokenTypes.LITERAL_DO,
|
||||
TokenTypes.LITERAL_FOR,
|
||||
TokenTypes.LITERAL_IF,
|
||||
TokenTypes.LITERAL_ELSE,
|
||||
TokenTypes.LITERAL_SWITCH,
|
||||
TokenTypes.LITERAL_CASE,
|
||||
TokenTypes.LITERAL_TRY,
|
||||
TokenTypes.LITERAL_CATCH,
|
||||
TokenTypes.QUESTION,
|
||||
TokenTypes.LAND,
|
||||
|
|
@ -71,9 +67,7 @@ public class CyclomaticComplexityCheck
|
|||
/** {@inheritDoc} */
|
||||
protected final void visitTokenHook(DetailAST aAST)
|
||||
{
|
||||
if (!CheckUtils.isElseIf(aAST)) {
|
||||
incrementCurrentValue(1);
|
||||
}
|
||||
incrementCurrentValue(1);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
|||
|
|
@ -17,15 +17,15 @@ public class CyclomaticComplexityCheckTest
|
|||
"4:5: Cyclomatic Complexity is 2 (max allowed is 0).",
|
||||
"7:17: Cyclomatic Complexity is 2 (max allowed is 0).",
|
||||
"17:5: Cyclomatic Complexity is 6 (max allowed is 0).",
|
||||
"27:5: Cyclomatic Complexity is 4 (max allowed is 0).",
|
||||
"34:5: Cyclomatic Complexity is 6 (max allowed is 0).",
|
||||
"48:5: Cyclomatic Complexity is 4 (max allowed is 0).",
|
||||
"58:5: Cyclomatic Complexity is 4 (max allowed is 0).",
|
||||
"67:5: Cyclomatic Complexity is 4 (max allowed is 0).",
|
||||
"27:5: Cyclomatic Complexity is 3 (max allowed is 0).",
|
||||
"34:5: Cyclomatic Complexity is 5 (max allowed is 0).",
|
||||
"48:5: Cyclomatic Complexity is 3 (max allowed is 0).",
|
||||
"58:5: Cyclomatic Complexity is 3 (max allowed is 0).",
|
||||
"67:5: Cyclomatic Complexity is 3 (max allowed is 0).",
|
||||
"76:5: Cyclomatic Complexity is 1 (max allowed is 0).",
|
||||
"79:13: Cyclomatic Complexity is 2 (max allowed is 0).",
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("ComplexityCheckTestInput.java"), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
<li>Indentation check now works better with enums and
|
||||
for-each statements (bugs 1193850 and 1193855)</li>
|
||||
|
||||
<li>Corrected calculation of Cyclomatic complexity metric
|
||||
(bug 1203536, module CyclomaticComplexity)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>Dependencies:</p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue