Search in sources :

Example 1 with ElseLike

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);
    }
}
Also used : ElseLike(org.sonar.uast.helpers.ElseLike) IfLike(org.sonar.uast.helpers.IfLike)

Aggregations

ElseLike (org.sonar.uast.helpers.ElseLike)1 IfLike (org.sonar.uast.helpers.IfLike)1