List<String> (@NotNull PsiSwitchBlock block, @NotNull Map<PsiType, Set<List<PsiType>>> branchesByType, boolean shorten) { List<String> result = new ArrayList<>(); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(block.getProject()); for (Map.Entry<PsiType, Set<List<PsiType>>> branches : branchesByType.entrySet()) { PsiType recordType = branches.getKey(); if (recordType == null) { return null; } String recordTypeString = recordType.getCanonicalText(); List<String> variableNames = new ArrayList<>(); PsiClass recordClass = PsiUtil.resolveClassInClassTypeOnly(TypeConversionUtil.erasure(recordType)); if (recordClass == null || !recordClass.isRecord()) return null; for (PsiRecordComponent recordComponent : recordClass.getRecordComponents()) { String nextName = codeStyleManager.suggestUniqueVariableName(recordComponent.getName(), block, false); variableNames.add(nextName); } for (List<PsiType> branch : branches.getValue()) { StringJoiner joiner = new StringJoiner(", ", "(", ")"); if (branch.size() != variableNames.size()) return null; for (int i = 0; i < branch.size(); i++) { PsiType psiType = branch.get(i); String typeText = shorten ? psiType.getPresentableText() : psiType.getCanonicalText(); joiner.add(typeText + " " + variableNames.get(i)); } result.add(recordTypeString + joiner); } } //every item is equal, but it is needed to produce a stable result Collections.sort(result); return result; }