boolean (@NotNull PsiMethod m1, @NotNull PsiMethod m2) { final Queue<PsiMethod> supers1Q = new ArrayDeque<>(); supers1Q.add(m1); final Queue<PsiMethod> supers2Q = new ArrayDeque<>(); supers2Q.add(m2); Set<PsiMethod> supers1 = new HashSet<>(); Set<PsiMethod> supers2 = new HashSet<>(); while (true) { PsiMethod me1; if ((me1 = supers1Q.poll()) != null) { if (supers2.contains(me1)) return true; supers1.add(me1); PsiSuperMethodImplUtil.processDirectSuperMethodsSmart(me1, psiMethod -> { supers1Q.add(psiMethod); return true; }); } PsiMethod me2; if ((me2 = supers2Q.poll()) != null) { if (supers1.contains(me2)) return true; supers2.add(me2); PsiSuperMethodImplUtil.processDirectSuperMethodsSmart(me2, psiMethod -> { supers2Q.add(psiMethod); return true; }); } if (me1 == null && me2 == null) break; } return false; /* HashSet<PsiMethod> s1 = new HashSet<PsiMethod>(Arrays.asList(m1.findDeepestSuperMethods())); s1.add(m1); HashSet<PsiMethod> s2 = new HashSet<PsiMethod>(Arrays.asList(m2.findDeepestSuperMethods())); s2.add(m2); s1.retainAll(s2); return !s1.isEmpty(); */ }