Problem about IfStatementTree: How to let the rule check method by method

Hello guys
I am writing the rule to determine if there are more than 3 if-else in one method.
But I have a problem here.

Here is my rule code.

and here is the result in SonarQube

As the result shows, there are only 2 if-else in the “jump” method, but it is still reported as an issue.
But it shouldn’t be reported as an issue.
Please tell me what I should modify my rule to reach my goal.

my SonarQube version: 8.9.2.46101
the language I use: Java

Thanks a lot!

Hi @Liver,

I don’t know if you managed to solve your problem but it looks to me like the reuse of the same instance of IfStatementVisitor between method visits. As a consequence, you keep increasing ifcounter without ever clearing it.
And thus once ifcounter is greater or equal to 3, it will systematically report on the next if statement it encounters regardless of the method it is visiting.

Hope this helps.

Dorian

Thanks a lot!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.