CreateMissingDeconstructionRecordClassBranchesFix (@NotNull PsiSwitchBlock switchBlock, @NotNull PsiClass selectorType, @NotNull Map<PsiType, Set<List<PsiType>>> missedBranches, @NotNull List<? extends PsiCaseLabelElement> elements) { if (missedBranches.isEmpty()) { return null; } if (!selectorType.isRecord()) { return null; } if (missedBranches.values().stream().flatMap(t -> t.stream()).flatMap(t -> t.stream()) .anyMatch(type -> { if (type == null) { return true; } PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(type); return (psiClass == null && !TypeConversionUtil.isPrimitiveAndNotNull(type)) || (psiClass != null && psiClass.hasTypeParameters()); })) { return null; } if (!SwitchUtils.isRuleFormatSwitch(switchBlock)) { return null; } List<String> allLabels = new ArrayList<>(); int lastDeconstructionPatternIndex = -1; int i = -1; for (PsiCaseLabelElement element : elements) { i++; //put after last pattern, because missed cases cannot be dominated if (element instanceof PsiPattern) { lastDeconstructionPatternIndex = i; } if (element == null) return null; allLabels.add(element.getText()); } List<String> missedLabels = getMissedLabels(switchBlock, missedBranches, false); if (missedLabels == null || missedLabels.isEmpty()) { return null; } allLabels.addAll(lastDeconstructionPatternIndex + 1, missedLabels); allLabels = allLabels.stream().distinct().toList(); List<String> shortenLabels = getMissedLabels(switchBlock, missedBranches, true); if (shortenLabels == null) { return null; } return new CreateMissingDeconstructionRecordClassBranchesFix(switchBlock, new HashSet<>(missedLabels), allLabels, shortenLabels); }