CompletenessResult (@NotNull PsiSwitchBlock switchBlock) { SwitchBlockHighlightingModel switchModel = SwitchBlockHighlightingModel.createInstance( PsiUtil.getLanguageLevel(switchBlock), switchBlock, switchBlock.getContainingFile()); if (switchModel == null) return UNEVALUATED; PsiCodeBlock switchBody = switchModel.myBlock.getBody(); if (switchBody == null) return UNEVALUATED; List<PsiCaseLabelElement> labelElements = StreamEx.of(SwitchUtils.getSwitchBranches(switchBlock)).select(PsiCaseLabelElement.class) .filter(element -> !(element instanceof PsiDefaultCaseLabelElement)).toList(); if (labelElements.isEmpty()) return UNEVALUATED; boolean needToCheckCompleteness = switchModel.needToCheckCompleteness(labelElements); boolean isEnumSelector = switchModel.getSwitchSelectorKind() == SelectorKind.ENUM; AtomicBoolean reported = new AtomicBoolean(); if (switchModel instanceof PatternsInSwitchBlockHighlightingModel patternsInSwitchModel) { if (findUnconditionalPatternForType(labelElements, switchModel.mySelectorType) != null) return COMPLETE_WITH_UNCONDITIONAL; if (!needToCheckCompleteness && !isEnumSelector) return INCOMPLETE; patternsInSwitchModel.checkCompleteness(labelElements, false, builder -> { if (builder != null) reported.set(true); }); } else { if (!needToCheckCompleteness && !isEnumSelector) return INCOMPLETE; PsiClass selectorClass = PsiUtil.resolveClassInClassTypeOnly(switchModel.mySelector.getType()); if (selectorClass == null || !selectorClass.isEnum()) return UNEVALUATED; List<PsiSwitchLabelStatementBase> labels = PsiTreeUtil.getChildrenOfTypeAsList(switchBlock.getBody(), PsiSwitchLabelStatementBase.class); List<PsiEnumConstant> enumConstants = StreamEx.of(labels).flatCollection(SwitchUtils::findEnumConstants).toList(); switchModel.checkEnumCompleteness(selectorClass, enumConstants, !labels.isEmpty(), builder -> { if (builder != null) reported.set(true); }); } // if a switch block is needed to check completeness and switch is incomplete we let highlighting to inform about it as it's a compilation error if (needToCheckCompleteness) return reported.get() ? UNEVALUATED : COMPLETE_WITHOUT_UNCONDITIONAL; return reported.get() ? INCOMPLETE : COMPLETE_WITHOUT_UNCONDITIONAL; }