Set<PsiElement> (@NotNull PsiSwitchBlock switchBlock) { SwitchBlockHighlightingModel switchModel = createInstance(PsiUtil.getLanguageLevel(switchBlock), switchBlock, switchBlock.getContainingFile()); if (switchModel == null) return Collections.emptySet(); List<PsiCaseLabelElement> labelElements = ContainerUtil.filterIsInstance(SwitchUtils.getSwitchBranches(switchBlock), PsiCaseLabelElement.class); if (labelElements.isEmpty()) return Collections.emptySet(); MultiMap<Object, PsiElement> duplicateCandidates = new MultiMap<>(); labelElements.forEach(branch -> switchModel.fillElementsToCheckDuplicates(duplicateCandidates, branch)); Set<PsiElement> result = new SmartHashSet<>(); for (Map.Entry<Object, Collection<PsiElement>> entry : duplicateCandidates.entrySet()) { if (entry.getValue().size() <= 1) continue; result.addAll(entry.getValue()); } // Find only one unconditional pattern, but not all, because if there are // multiple unconditional patterns, they will all be found as duplicates PsiCaseLabelElement unconditionalPattern = PatternsInSwitchBlockHighlightingModel.findUnconditionalPatternForType(labelElements, switchModel.mySelectorType); PsiElement defaultElement = SwitchUtils.findDefaultElement(switchBlock); if (unconditionalPattern != null && defaultElement != null) { result.add(unconditionalPattern); result.add(defaultElement); } PatternsInSwitchBlockHighlightingModel patternInSwitchModel = ObjectUtils.tryCast(switchModel, PatternsInSwitchBlockHighlightingModel.class); if (patternInSwitchModel == null) return result; List<PsiCaseLabelElement> dominanceCheckingCandidates = new SmartList<>(); labelElements.forEach(label -> PatternsInSwitchBlockHighlightingModel.fillElementsToCheckDominance(dominanceCheckingCandidates, label)); if (dominanceCheckingCandidates.isEmpty()) return result; return StreamEx.ofKeys(patternInSwitchModel.findDominatedLabels(dominanceCheckingCandidates), value -> value instanceof PsiPattern) .into(result); }