Search in sources :

Example 1 with CaseLike

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

the class NoIdenticalConditionsCheck method handleSwitch.

private void handleSwitch(UastNode node) {
    SwitchLike switchLike = SwitchLike.from(node);
    if (switchLike == null) {
        return;
    }
    List<UastNode> caseNodes = switchLike.caseNodes();
    List<UastNode> allConditions = new ArrayList<>();
    for (UastNode caseNode : caseNodes) {
        CaseLike caseLike = CaseLike.from(caseNode);
        List<UastNode> conditions = caseLike.conditions();
        for (UastNode condition : conditions) {
            for (UastNode prevCondition : allConditions) {
                checkConditions(condition, prevCondition);
            }
            allConditions.add(condition);
        }
    }
}
Also used : SwitchLike(org.sonar.uast.helpers.SwitchLike) ArrayList(java.util.ArrayList) UastNode(org.sonar.uast.UastNode) CaseLike(org.sonar.uast.helpers.CaseLike)

Aggregations

ArrayList (java.util.ArrayList)1 UastNode (org.sonar.uast.UastNode)1 CaseLike (org.sonar.uast.helpers.CaseLike)1 SwitchLike (org.sonar.uast.helpers.SwitchLike)1