PsiClass (@NotNull PsiElement place, PsiClass memberClass) { PsiClass lastClass = null; Boolean isAtLeast17 = null; for (PsiElement placeParent = place; placeParent != null; placeParent = placeParent.getContext()) { if (placeParent instanceof PsiClass && !(placeParent instanceof PsiAnonymousClass)) { final boolean isTypeParameter = placeParent instanceof PsiTypeParameter; if (isTypeParameter && isAtLeast17 == null) { isAtLeast17 = JavaVersionService.getInstance().isAtLeast(placeParent, JavaSdkVersion.JDK_1_7); } if (!isTypeParameter || isAtLeast17) { PsiClass aClass = (PsiClass)placeParent; if (memberClass != null && aClass.isInheritor(memberClass, true)) return aClass; lastClass = aClass; } } } return lastClass; }