void (@NotNull List<? extends PsiCaseLabelElement> elements, boolean inclusiveUnconditionalAndDefault, @NotNull Consumer<? super HighlightInfo.Builder> errorSink) { //T is an intersection type T1& ... &Tn, and P covers Ti, for one of the type Ti (1≤i≤n) List<PsiType> selectorTypes = getAllTypes(mySelectorType); if (inclusiveUnconditionalAndDefault) { PsiCaseLabelElement elementCoversType = selectorTypes.stream() .map(type -> findUnconditionalPatternForType(elements, type)) .filter(t -> t != null) .findAny() .orElse(null); PsiElement defaultElement = SwitchUtils.findDefaultElement(myBlock); if (defaultElement != null && elementCoversType != null) { HighlightInfo.Builder defaultInfo = createError(defaultElement.getFirstChild(), JavaErrorBundle.message("switch.unconditional.pattern.and.default.exist")); registerDeleteFixForDefaultElement(defaultInfo, defaultElement, defaultElement.getFirstChild()); errorSink.accept(defaultInfo); HighlightInfo.Builder patternInfo = createError(elementCoversType, JavaErrorBundle.message( "switch.unconditional.pattern.and.default.exist")); IntentionAction action = getFixFactory().createDeleteSwitchLabelFix(elementCoversType); patternInfo.registerFix(action, null, null, null, null); errorSink.accept(patternInfo); return; } if (defaultElement != null || elementCoversType != null) return; } //enums are final; checking intersections are not needed PsiClass selectorClass = PsiUtil.resolveClassInClassTypeOnly(TypeConversionUtil.erasure(mySelectorType)); if (selectorClass != null && getSwitchSelectorKind() == SelectorKind.ENUM) { List<PsiEnumConstant> enumElements = new SmartList<>(); elements.stream() .map(SwitchBlockHighlightingModel::getEnumConstant) .filter(Objects::nonNull) .forEach(enumElements::add); checkEnumCompleteness(selectorClass, enumElements, !elements.isEmpty(), errorSink); return; } List<PsiType> sealedTypes = getAbstractSealedTypes(selectorTypes); if (!sealedTypes.isEmpty()) { errorSink.accept(checkSealed(elements, selectorClass)); return; } //records are final; checking intersections are not needed if (selectorClass != null && selectorClass.isRecord()) { if (!checkRecordCaseSetNotEmpty(elements)) { errorSink.accept(createCompletenessInfoForSwitch(!elements.isEmpty())); } else { errorSink.accept(checkRecordExhaustiveness(elements, mySelectorType)); } } else { errorSink.accept(createCompletenessInfoForSwitch(!elements.isEmpty())); } }