Handle boolean expressions on different statements
This commit is contained in:
@ -170,4 +170,19 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter {
|
||||
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTBlockStatement node, Object data) {
|
||||
State state = (State) data;
|
||||
|
||||
for (ApexNode<?> child : node.children()) {
|
||||
child.jjtAccept(this, data);
|
||||
|
||||
// This needs to happen because the current 'run' of boolean operations is terminated
|
||||
// once we finish a statement.
|
||||
state.booleanOperation(null);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -293,13 +293,14 @@
|
||||
|
||||
<test-code>
|
||||
<description>Boolean operators</description>
|
||||
<expected-problems>5</expected-problems>
|
||||
<expected-problems>6</expected-problems>
|
||||
<expected-messages>
|
||||
<message>'c__Foo#a(Integer)' has value 1.</message>
|
||||
<message>'c__Foo#b(Integer)' has value 1.</message>
|
||||
<message>'c__Foo#c(Integer)' has value 1.</message>
|
||||
<message>'c__Foo#d(Boolean,Boolean,Boolean,Boolean,Boolean,Boolean)' has value 3.</message>
|
||||
<message>'c__Foo#e(Boolean,Boolean,Boolean)' has value 2.</message>
|
||||
<message>'c__Foo#f()' has value 2.</message>
|
||||
</expected-messages>
|
||||
<code>
|
||||
<![CDATA[
|
||||
@ -328,6 +329,11 @@
|
||||
&& // +1
|
||||
!(b && c); // +1
|
||||
}
|
||||
|
||||
Boolean f() {
|
||||
Boolean a = true && false; // +1
|
||||
return a && true; // +1
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
|
Reference in New Issue
Block a user