Ternary operators increase nesting complexity

This commit is contained in:
Gwilym Kuiper
2020-02-18 15:56:08 +00:00
parent 5ea69530d7
commit 4b26d22c73
2 changed files with 30 additions and 0 deletions

View File

@ -122,4 +122,15 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter {
return data;
}
@Override
public Object visit(ASTTernaryExpression node, Object data) {
State state = (State) data;
state.increaseNestingLevel();
super.visit(node, data);
state.decreaseNestingLevel();
return data;
}
}

View File

@ -271,4 +271,23 @@
]]>
</code>
</test-code>
<test-code>
<description>Ternary operators cause nesting</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'c__Foo#foo(Integer)' has value 3.</message>
</expected-messages>
<code>
<![CDATA[
class Foo {
Integer foo(Integer n) {
return n < 0 ? // +1
-1 : n > 0 ? // +2
1 : 0;
}
}
]]>
</code>
</test-code>
</test-data>