Handle boolean expressions on different statements

This commit is contained in:
Gwilym Kuiper
2020-02-18 16:59:12 +00:00
parent a4db0ea069
commit 0231350dea
2 changed files with 22 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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>