Collection<List<Rule>> (@NotNull PsiSwitchBlock switchBlock) { PsiCodeBlock switchBody = switchBlock.getBody(); if (switchBody == null) { return Collections.emptyList(); } Int2ObjectMap<List<Rule>> rulesByHash = new Int2ObjectOpenHashMap<>(); List<String> commentTexts = new ArrayList<>(); for (PsiElement element = switchBody.getFirstChild(); element != null; element = element.getNextSibling()) { TryWithIdenticalCatchesInspection.collectCommentTexts(element, commentTexts); if (element instanceof PsiSwitchLabeledRuleStatement ruleStatement) { PsiStatement body = ruleStatement.getBody(); if (body != null) { //noinspection AssignmentToForLoopParameter element = collectCommentsUntilNewLine(commentTexts, element); Rule rule = new Rule(ruleStatement, body, ArrayUtilRt.toStringArray(commentTexts)); commentTexts.clear(); rulesByHash.computeIfAbsent(rule.hash(), __ -> new ArrayList<>()).add(rule); } } } return new ArrayList<>(rulesByHash.values()); }