List<PatternTypeTestDescription> (@NotNull List<? extends PatternDescription> elements, @NotNull PsiElement context) { List<PatternTypeTestDescription> reducedToTypeTest = new ArrayList<>(); List<PatternDeconstructionDescription> deconstructionDescriptions = new ArrayList<>(); for (PatternDescription element : elements) { if (element instanceof PatternTypeTestDescription typeTestDescription) { reducedToTypeTest.add(typeTestDescription); } if(element instanceof PatternDeconstructionDescription deconstructionDescription) { deconstructionDescriptions.add(deconstructionDescription); } } Map<PsiType, List<PatternDeconstructionDescription>> groupedByType = deconstructionDescriptions.stream().collect(Collectors.groupingBy(t -> t.type())); for (Map.Entry<PsiType, List<PatternDeconstructionDescription>> entry : groupedByType.entrySet()) { if (checkRecordPatternExhaustivenessForDescription(entry.getValue(), entry.getKey(), context).isExhaustive()) { reducedToTypeTest.add(new PatternTypeTestDescription(entry.getKey())); } } return reducedToTypeTest; }