Collection<PsiClass> (@NotNull PsiClass psiClass) { return CachedValuesManager.getCachedValue(psiClass, () -> { PsiReferenceList permitsList = psiClass.getPermitsList(); Collection<PsiClass> results; if (permitsList == null) { results = SyntaxTraverser.psiTraverser(psiClass.getContainingFile()) .filter(PsiClass.class) //local classes and anonymous classes must not extend sealed .filter(cls -> !(cls instanceof PsiAnonymousClass || PsiUtil.isLocalClass(cls))) .filter(cls -> cls.isInheritor(psiClass, false)) .toList(); } else { results = Stream.of(permitsList.getReferencedTypes()) .map(type -> type.resolve()).filter(Objects::nonNull) .collect(Collectors.toCollection(LinkedHashSet::new)); } return CachedValueProvider.Result.create(results, PsiModificationTracker.MODIFICATION_COUNT); }); }