PsiMethod (@NotNull PsiMethod method, @Nullable PsiType specificType) { PsiClass qualifierClass = method.getContainingClass(); if (qualifierClass == null) return method; if (specificType == null || specificType instanceof PsiArrayType) return method; StreamEx<PsiType> types; if (specificType instanceof PsiIntersectionType) { types = StreamEx.of(((PsiIntersectionType)specificType).getConjuncts()); } else { types = StreamEx.of(specificType); } List<PsiMethod> methods = types.map(PsiUtil::resolveClassInClassTypeOnly) .nonNull() .without(qualifierClass) .distinct() .filter(specificClass -> InheritanceUtil.isInheritorOrSelf(specificClass, qualifierClass, true)) .map(specificClass -> MethodSignatureUtil.findMethodBySuperMethod(specificClass, method, true)) .nonNull() .distinct() .toList(); if (methods.isEmpty()) return method; PsiMethod best = methods.get(0); for (PsiMethod realMethod : methods) { if (best.equals(realMethod)) continue; if (MethodSignatureUtil.isSuperMethod(best, realMethod)) { best = realMethod; } else if (!MethodSignatureUtil.isSuperMethod(realMethod, best)) { // Several real candidates: give up return method; } } return best; }