ThreeState (PsiClass class1, PsiClass class2, boolean avoidExpensiveProcessing, SearchScope scope) { final Query<PsiClass> search = ClassInheritorsSearch.search(class1, scope, true); var processor = new Processor<PsiClass>() { ThreeState result = ThreeState.NO; final AtomicInteger count = new AtomicInteger(0); @Override public boolean process(PsiClass inheritor) { if (inheritor.equals(class2) || inheritor.isInheritor(class2, true)) { result = ThreeState.YES; return false; } if (avoidExpensiveProcessing && count.incrementAndGet() > 20) { result = ThreeState.UNSURE; return false; } return true; } }; search.forEach(processor); return processor.result; }