use of org.sonar.uast.helpers.ElseLike in project sonar-go by SonarSource.
the class AllBranchesAreIdenticalCheck method handleIf.
private void handleIf(UastNode node) {
IfLike ifLike = IfLike.from(node);
if (ifLike == null || visitedIfs.contains(node)) {
return;
}
ElseLike elseLike = ifLike.elseLike();
boolean allSame = true;
IfLike elseIf = ifLike.elseIf();
while (elseIf != null) {
visitedIfs.add(elseIf.node());
if (!syntacticallyEquivalent(ifLike.thenNode(), elseIf.thenNode())) {
allSame = false;
}
elseLike = elseIf.elseLike();
elseIf = elseIf.elseIf();
}
if (elseLike == null) {
// if without else is exception of the rule, see RSPEC
return;
}
allSame = allSame && syntacticallyEquivalent(ifLike.thenNode(), elseLike.elseNode());
if (allSame) {
reportIssue(ifLike.ifKeyword(), MESSAGE);
}
}