void (@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { final PsiElement position = parameters.getPosition(); final PsiType[] leftTypes = InstanceOfLeftPartTypeGetter.getLeftTypes(position); final Set<PsiClassType> expectedClassTypes = new LinkedHashSet<>(); final Set<PsiClass> parameterizedTypes = new HashSet<>(); for (final PsiType type : leftTypes) { if (type instanceof PsiClassType classType) { if (!classType.isRaw()) { ContainerUtil.addIfNotNull(parameterizedTypes, classType.resolve()); } expectedClassTypes.add(classType.rawType()); } } JavaInheritorsGetter .processInheritors(parameters, expectedClassTypes, result.getPrefixMatcher(), type -> { final PsiClass psiClass = PsiUtil.resolveClassInType(type); if (psiClass == null || psiClass instanceof PsiTypeParameter) return; if (expectedClassTypes.contains(type)) return; result.addElement(createInstanceofLookupElement(psiClass, parameterizedTypes)); }); }