use of org.sonar.uast.helpers.SwitchLike in project sonar-go by SonarSource.
the class AllBranchesAreIdenticalCheck method handleSwitch.
private void handleSwitch(UastNode node) {
SwitchLike switchLike = SwitchLike.from(node);
if (switchLike == null) {
return;
}
List<UastNode> caseNodes = switchLike.caseNodes();
if (caseNodes.size() < 2) {
return;
}
UastNode firstCase = CaseLike.from(caseNodes.get(0)).body();
if (caseNodes.stream().noneMatch(UastNode.Kind.DEFAULT_CASE)) {
return;
}
boolean allEquivalent = caseNodes.stream().skip(1).map(caseNode -> CaseLike.from(caseNode).body()).allMatch(body -> syntacticallyEquivalent(firstCase, body));
if (allEquivalent) {
reportIssue(switchLike.switchKeyword(), MESSAGE);
}
}
use of org.sonar.uast.helpers.SwitchLike 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);
}
}
}
Aggregations