void (PsiElement current, @NotNull Set<PsiElement> visited) { if (current == null) return; final String text = current instanceof PsiClass ? ((PsiClass)current).getName() : current.getText(); if (MatchUtils.compareWithNoDifferenceToPackage(text, "Object")) { if(objectTaken) return; objectTaken = true; } PsiElement element = current instanceof PsiReference ? ((PsiReference)current).resolve() : current; if (element instanceof PsiClass clazz) { if (visited.contains(element)) return; if (acceptInterfaces || !clazz.isInterface()) visited.add(element); if (firstElementTaken || acceptFirstElement) remaining.add(clazz); firstElementTaken = true; if (clazz instanceof PsiAnonymousClass) { build(((PsiAnonymousClass)clazz).getBaseClassReference(),visited); return; } if (acceptClasses) { processClasses(clazz.getExtendsList(), visited); if (!objectTaken) { build(PsiClassImplUtil.getSuperClass(clazz), visited); } } if (acceptInterfaces) { processClasses(clazz.getImplementsList(), visited); if (!acceptClasses) processClasses(clazz.getExtendsList(), visited); } } else { remaining.add(current); } }