Search in sources :

Example 1 with IfLike

use of org.sonar.uast.helpers.IfLike in project sonar-go by SonarSource.

the class NoIdenticalConditionsCheck method handleIf.

private void handleIf(UastNode node) {
    IfLike ifLike = IfLike.from(node);
    if (ifLike == null) {
        return;
    }
    UastNode condition = ifLike.condition();
    IfLike elseIf = ifLike.elseIf();
    while (elseIf != null) {
        checkConditions(elseIf.condition(), condition);
        elseIf = elseIf.elseIf();
    }
}
Also used : IfLike(org.sonar.uast.helpers.IfLike) UastNode(org.sonar.uast.UastNode)

Example 2 with IfLike

use of org.sonar.uast.helpers.IfLike 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

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